-
Notifications
You must be signed in to change notification settings - Fork 11
/
JSTesting.ns
92 lines (85 loc) · 3.19 KB
/
JSTesting.ns
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
Newspeak3
'Root'
class JSTesting usingPlatform: platform testFramework: minitest = (
|
private js = platform js.
private TestContext = minitest TestContext.
|) (
public class JSTests = TestContext (
) (
public testJSMath = (
| Math n |
Math:: js global at: 'Math'.
n:: Math random.
assert: n isKindOfFloat.
assert: n >= 0.0 asFloat.
assert: n < 1.0 asFloat.
n:: Math at: 'E'.
assert: n isKindOfFloat.
assert: n > 2.718 asFloat.
assert: n < 2.719 asFloat.
)
public testJSObject = (
| JSObject object |
JSObject:: js global at: 'Object'.
object:: JSObject new.
should: [object methodDoesNotExist] signal: Exception.
assert: (object at: 'property' put: 42) equals: 42.
assert: (object at: 'property') equals: 42.
assert: (object removeKey: 'property') equals: true.
)
public testJSString = (
(* String argument *)
assert: (js global parseInt: '42') equals: 42.
(* String return value *)
assert: ((js global at: 'Math') toString) equals: '[object Math]'.
)
public testJSUndefined = (
assert: js undefined isUndefined.
deny: js global isUndefined.
assert: (js global at: 'DoesNotExist') isUndefined.
deny: (js global at: 'Object') isUndefined.
assert: js undefined printString equals: 'undefined'.
)
public testJSInteger = (
assert: (js global parseInt: '0') equals: 0.
assert: (js global parseInt: '1') equals: 1.
assert: (js global parseInt: '-1') equals: -1.
assert: (js global parseInt: '0x7F') equals: 16r7F.
assert: (js global parseInt: '0xEF') equals: 16rEF.
assert: (js global parseInt: '0xFF') equals: 16rFF.
assert: (js global parseInt: '0x7FFF') equals: 16r7FFF.
assert: (js global parseInt: '0xEFFF') equals: 16rEFFF.
assert: (js global parseInt: '0xFFFF') equals: 16rFFFF.
assert: (js global parseInt: '0x7FFFFFFF') equals: 16r7FFFFFFF.
assert: (js global parseInt: '0xEFFFFFFF') equals: 16rEFFFFFFF.
assert: (js global parseInt: '0xFFFFFFFF') equals: 16rFFFFFFFF.
assert: (js global parseInt: '0x7FFFFFFFFFFF') equals: 16r7FFFFFFFFFFF.
assert: (js global parseInt: '0xEFFFFFFFFFFF') equals: 16rEFFFFFFFFFFF.
assert: (js global parseInt: '0xFFFFFFFFFFFF') equals: 16rFFFFFFFFFFFF.
assert: (js global parseInt: '-0x7F') equals: -16r7F.
assert: (js global parseInt: '-0xEF') equals: -16rEF.
assert: (js global parseInt: '-0xFF') equals: -16rFF.
assert: (js global parseInt: '-0x7FFF') equals: -16r7FFF.
assert: (js global parseInt: '-0xEFFF') equals: -16rEFFF.
assert: (js global parseInt: '-0xFFFF') equals: -16rFFFF.
assert: (js global parseInt: '-0x7FFFFFFF') equals: -16r7FFFFFFF.
assert: (js global parseInt: '-0xEFFFFFFF') equals: -16rEFFFFFFF.
assert: (js global parseInt: '-0xFFFFFFFF') equals: -16rFFFFFFFF.
assert: (js global parseInt: '-0x7FFFFFFFFFFF') equals: -16r7FFFFFFFFFFF.
assert: (js global parseInt: '-0xEFFFFFFFFFFF') equals: -16rEFFFFFFFFFFF.
assert: (js global parseInt: '-0xFFFFFFFFFFFF') equals: -16rFFFFFFFFFFFF.
)
public testJSEval = (
assert: (js global eval: 'null') equals: nil.
assert: (js global eval: 'false') equals: false.
assert: (js global eval: 'true') equals: true.
assert: (js global eval: '42') equals: 42.
assert: (js global eval: '42.5') equals: 42.5 asFloat.
assert: (js global eval: '"string"') equals: 'string'.
)
) : (
TEST_CONTEXT = ()
)
) : (
)