261
|
1 |
"{ Package: 'exept:regression' }"
|
|
2 |
|
|
3 |
"{ NameSpace: RegressionTests }"
|
|
4 |
|
|
5 |
TestCase subclass:#JavaScriptTests
|
|
6 |
instanceVariableNames:''
|
|
7 |
classVariableNames:''
|
|
8 |
poolDictionaries:''
|
|
9 |
category:'Languages-JavaScript-Compiling & Parsing'
|
|
10 |
!
|
|
11 |
|
|
12 |
!JavaScriptTests class methodsFor:'documentation'!
|
|
13 |
|
|
14 |
documentation
|
|
15 |
"
|
|
16 |
documentation to be added.
|
|
17 |
|
|
18 |
[author:]
|
|
19 |
cg (cg@FUSI)
|
|
20 |
|
|
21 |
[instance variables:]
|
|
22 |
|
|
23 |
[class variables:]
|
|
24 |
|
|
25 |
[see also:]
|
|
26 |
|
|
27 |
"
|
|
28 |
!
|
|
29 |
|
|
30 |
history
|
|
31 |
"Created: / 12-04-2005 / 11:54:25 / cg"
|
|
32 |
! !
|
|
33 |
|
|
34 |
!JavaScriptTests methodsFor:'initialize / release'!
|
|
35 |
|
|
36 |
setUp
|
|
37 |
"common setup - invoked before testing."
|
|
38 |
|
|
39 |
super setUp
|
|
40 |
!
|
|
41 |
|
|
42 |
tearDown
|
|
43 |
"common cleanup - invoked after testing."
|
|
44 |
|
|
45 |
super tearDown
|
|
46 |
! !
|
|
47 |
|
|
48 |
!JavaScriptTests methodsFor:'tests'!
|
|
49 |
|
|
50 |
test_01_parse_literals
|
|
51 |
|spec|
|
|
52 |
|
|
53 |
spec := #(
|
|
54 |
('1' #isInteger 1)
|
|
55 |
('0' #isInteger 0)
|
|
56 |
('-1' #isInteger -1)
|
|
57 |
('12345678901234567890' #isInteger 12345678901234567890)
|
|
58 |
('0x0' #isInteger 0)
|
|
59 |
('0x1' #isInteger 1)
|
|
60 |
('0xFFFF' #isInteger 16rFFFF)
|
|
61 |
('0xffff' #isInteger 16rFFFF)
|
|
62 |
('0xFFFFFFFFFFFFFFFF' #isInteger 16rFFFFFFFFFFFFFFFF)
|
|
63 |
('0777' #isInteger 8r777)
|
|
64 |
|
|
65 |
('1.2345' #isFloat 1.2345)
|
|
66 |
('-1.2345' #isFloat -1.2345)
|
|
67 |
|
|
68 |
('nil' #isNil nil)
|
|
69 |
('null' #isNil nil)
|
|
70 |
('true' nil true)
|
|
71 |
('false' nil false)
|
|
72 |
|
|
73 |
('"hello"' #isString 'hello' )
|
|
74 |
('"\t"' #isString (#eval 'Character tab asString') )
|
|
75 |
('"\r"' #isString (#eval 'Character return asString') )
|
|
76 |
('"\n"' #isString (#eval 'Character nl asString') )
|
|
77 |
|
|
78 |
('[ 1 , 2 , 3]' #isArray #(1 2 3) )
|
|
79 |
('[1,2,3]' #isArray #(1 2 3) )
|
|
80 |
('[1,2,3]' #isArray #(1 2 3) )
|
|
81 |
('["a","b","c"]' #isArray #('a' 'b' 'c') )
|
|
82 |
('[]' #isArray #() )
|
|
83 |
('[null]' #isArray #( nil ) )
|
|
84 |
|
|
85 |
('[1,[2,[3]]]' #isArray #(1 (2 (3))) )
|
|
86 |
|
|
87 |
).
|
|
88 |
|
|
89 |
spec do:[:triple |
|
|
90 |
|str checkSelectorOrNil valExpected val|
|
|
91 |
|
|
92 |
str := triple first.
|
|
93 |
checkSelectorOrNil := triple second.
|
|
94 |
valExpected := triple third.
|
|
95 |
valExpected isArray ifTrue:[
|
|
96 |
(valExpected size > 0 and:[valExpected first == #eval]) ifTrue:[
|
|
97 |
valExpected := Parser evaluate:valExpected second
|
|
98 |
].
|
|
99 |
].
|
|
100 |
|
|
101 |
val := (JavaScriptParser parseExpression:str) evaluate.
|
|
102 |
checkSelectorOrNil notNil ifTrue:[
|
|
103 |
self assert:(val perform:checkSelectorOrNil).
|
|
104 |
].
|
|
105 |
self assert:(val = valExpected).
|
|
106 |
].
|
|
107 |
|
|
108 |
"
|
|
109 |
self run:#test_01_parse_literals
|
|
110 |
self new test_01_parse_literals
|
|
111 |
"
|
|
112 |
!
|
|
113 |
|
|
114 |
test_02_parse_literals2
|
|
115 |
|spec|
|
|
116 |
|
|
117 |
spec := #(
|
|
118 |
('"\x01"' #isString (#eval '(Character value:1) asString') )
|
|
119 |
).
|
|
120 |
|
|
121 |
spec do:[:triple |
|
|
122 |
|str checkSelectorOrNil valExpected val|
|
|
123 |
|
|
124 |
str := triple first.
|
|
125 |
checkSelectorOrNil := triple second.
|
|
126 |
valExpected := triple third.
|
|
127 |
valExpected isArray ifTrue:[
|
|
128 |
valExpected first == #eval ifTrue:[
|
|
129 |
valExpected := Parser evaluate:valExpected second
|
|
130 |
] ifFalse:[
|
|
131 |
self error.
|
|
132 |
].
|
|
133 |
].
|
|
134 |
|
|
135 |
val := (JavaScriptParser parseExpression:str) evaluate.
|
|
136 |
checkSelectorOrNil notNil ifTrue:[
|
|
137 |
self assert:(val perform:checkSelectorOrNil).
|
|
138 |
].
|
|
139 |
self assert:(val = valExpected).
|
|
140 |
].
|
|
141 |
|
|
142 |
"
|
|
143 |
self run:#test_02_parse_literals2
|
|
144 |
self new test_02_parse_literals2
|
|
145 |
"
|
|
146 |
! !
|
|
147 |
|
|
148 |
!JavaScriptTests class methodsFor:'documentation'!
|
|
149 |
|
|
150 |
version
|
|
151 |
^ '$Header$'
|
|
152 |
! !
|