This repository has been archived by the owner on Feb 1, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
/
test_js_jstypes.py
73 lines (52 loc) · 1.76 KB
/
test_js_jstypes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import validator.testcases.javascript.jstypes as jstypes
from js_helper import _do_test_raw
def test_jsarray_output():
"""Test that the output function for JSArray doesn't bork."""
ja = jstypes.JSArray()
ja.elements = [None, None]
ja.output() # Used to throw tracebacks.
ja.get_literal_value() # Also used to throw tracebacks.
def test_jsobject_output():
"""Test that the output function for JSObject doesn't bork."""
jso = jstypes.JSObject()
jso.data = {"first": None}
jso.output() # Used to throw tracebacks
def test_jsobject_recursion():
"""Test that circular references don't cause recursion errors."""
jso = jstypes.JSObject()
jso2 = jstypes.JSObject()
jso.data = {"first": jstypes.JSWrapper(jso2)}
jso2.data = {"second": jstypes.JSWrapper(jso)}
print jso.output()
assert "(recursion)" in jso.output()
def test_jsarray_recursion():
"""Test that circular references don't cause recursion errors."""
ja = jstypes.JSArray()
ja2 = jstypes.JSArray()
ja.elements = [jstypes.JSWrapper(ja2)]
ja2.elements = [jstypes.JSWrapper(ja)]
print ja.output()
assert "(recursion)" in ja.output()
print ja.get_literal_value()
assert "(recursion)" in ja.get_literal_value()
def test_jsliteral_regex():
"""
Test that there aren't tracebacks from JSLiterals that perform raw binary
operations.
"""
assert not _do_test_raw("""
var x = /foo/gi;
var y = x + " ";
var z = /bar/i + 0;
""").failed()
def test_jsarray_contsructor():
"""
Test for tracebacks that were caused by JSArray not calling it's parent's
constructor.
"""
assert not _do_test_raw("""
var x = [];
x.foo = "bar";
x["zap"] = "foo";
baz("zap" in x);
""").failed()