--- a/RegressionTests__JavaScriptTests.st Tue Apr 24 07:47:59 2018 +0200
+++ b/RegressionTests__JavaScriptTests.st Tue Apr 24 16:32:38 2018 +0200
@@ -47,34 +47,36 @@
doTestEachFromSpec:spec
spec do:[:triple |
- |str checkSelectorOrNil valExpected val expectError|
-
- str := triple first.
- checkSelectorOrNil := triple second.
- expectError := false.
- valExpected := triple third.
- valExpected isArray ifTrue:[
- valExpected size > 0 ifTrue:[
- valExpected first == #eval ifTrue:[
- valExpected := Parser evaluate:valExpected second
- ] ifFalse:[
- valExpected first == #error ifTrue:[
- expectError := true
- ].
- ].
- ].
- ].
- expectError ifTrue:[
- self
- should:[ (JavaScriptParser parseExpression:str) evaluate ]
- raise:Error
- ] ifFalse:[
- val := (JavaScriptParser parseExpression:str) evaluate.
- checkSelectorOrNil notNil ifTrue:[
- self assert:(val perform:checkSelectorOrNil).
- ].
- self assert:(val = valExpected).
- ].
+ |str checkSelectorOrNil valExpected val expectError|
+
+ str := triple first.
+ checkSelectorOrNil := triple second.
+ expectError := false.
+ valExpected := triple third.
+ valExpected isArray ifTrue:[
+ valExpected size > 0 ifTrue:[
+ valExpected first == #eval ifTrue:[
+ valExpected := Parser evaluate:valExpected second
+ ] ifFalse:[
+ valExpected first == #error ifTrue:[
+ expectError := true
+ ].
+ ].
+ ].
+ ].
+ expectError ifTrue:[
+ self
+ should:[ (JavaScriptParser parseExpression:str) evaluate ]
+ raise:Error
+ ] ifFalse:[
+ val := (JavaScriptParser parseExpression:str) evaluate.
+ checkSelectorOrNil notNil ifTrue:[
+ self assert:(val perform:checkSelectorOrNil).
+ ].
+ valExpected == #void ifFalse:[
+ self assert:(val = valExpected).
+ ]
+ ].
]
!
@@ -1332,6 +1334,29 @@
"
!
+testFunction01
+ "
+ Tests parsing a simple function
+ "
+
+ self
+ execute:'test(arg) {
+ var arg;
+ var f;
+
+ arg = 0;
+ return arg + 1;
+ }'
+ for:nil
+ arguments:#(-1)
+ expect:1
+
+ "
+ self run:#testFunction01
+ self new testFunction01
+ "
+!
+
testIf01
self
execute:'max(a, b) {
@@ -1476,6 +1501,54 @@
"
!
+testLambdaFunction01
+ "
+ Tests parsing a lambda function
+ "
+
+ self
+ execute:'test(arg) {
+ var arg;
+ var f;
+
+ arg = 0;
+ f = (arg) => { return arg + 1; };
+ return f(10);
+ }'
+ for:nil
+ arguments:#(-1)
+ expect:11
+
+ "
+ self run:#testLambdaFunction01
+ self new testLambdaFunction01
+ "
+!
+
+testLambdaFunction02
+ "
+ Tests parsing a lambda function
+ "
+
+ self
+ execute:'test(arg) {
+ var arg;
+ var f;
+
+ arg = 0;
+ f = (arg1, arg2) => { return arg1 + arg2; };
+ return f(10, 20);
+ }'
+ for:nil
+ arguments:#(-1)
+ expect:30
+
+ "
+ self run:#testLambdaFunction02
+ self new testLambdaFunction02
+ "
+!
+
testLiteralReturn01
self
execute:'function f() { return (0); }'
@@ -4056,257 +4129,6 @@
"Created: / 01-02-2011 / 15:35:36 / cg"
!
-testScanner01
- self
- execute:'f() { }'
- for:nil
- arguments:#()
- expect:nil
-
- "
- self run:#testScanner01
- self new testScanner01
- "
-!
-
-testScanner02
- self
- execute:'f(a) { }'
- for:nil
- arguments:#(1)
- expect:nil
-
- "
- self run:#testScanner02
- self new testScanner02
- "
-!
-
-testScanner03
- self
- execute:'f(a, b) { }'
- for:nil
- arguments:#(1 2)
- expect:nil
-
- "
- self run:#testScanner03
- self new testScanner03
- "
-!
-
-testScanner04
- self
- execute:'f(a, b) { return (null); }'
- for:nil
- arguments:#(1 2)
- expect:nil
-
- "
- self run:#testScanner04
- self new testScanner04
- "
-!
-
-testScanner05
- self
- execute:'f(a, b) { return (null); }'
- for:nil
- arguments:#(1)
- expectError:(Method wongNumberOfArgumentsSignal)
-
- "
- self run:#testScanner05
- self new testScanner05
- "
-
- "Modified: / 20-04-2005 / 11:53:20 / cg"
-!
-
-testScanner06
- self
- execute:'f() { /* a comment */ return (null); }'
- for:nil
- arguments:#()
- expect:nil
-
- "
- self run:#testScanner06
- self new testScanner06
- "
-!
-
-testScanner07
- self
- execute:'f() { // an EOL comment
- return (null); }'
- for:nil
- arguments:#()
- expect:nil
-
- "
- self run:#testScanner07
- self new testScanner07
- "
-!
-
-testScanner08
- self
- execute:'f() { // a comment in an /* an EOL comment
- return (null); }'
- for:nil
- arguments:#()
- expect:nil
-
- "
- self run:#testScanner08
- self new testScanner08
- "
-!
-
-testScanner09
- self
- execute:'f() { // a comment in an /* an EOL */ comment
- return (null); }'
- for:nil
- arguments:#()
- expect:nil
-
- "
- self run:#testScanner09
- self new testScanner09
- "
-!
-
-testScanner10
- self
- execute:'f() { /** a comment */
- return (null); }'
- for:nil
- arguments:#()
- expect:nil
-
- "
- self run:#testScanner10
- self new testScanner10
- "
-!
-
-testScanner11
- self
- execute:'f() { /**/
- return (null); }'
- for:nil
- arguments:#()
- expect:nil
-
- "
- self run:#testScanner11
- self new testScanner11
- "
-!
-
-testScanner12
- "/ cg: is the comment below legal ?
- ^ self. "/ assume not
-
- self
- execute:'f() { /*/
- return (null); }'
- for:nil
- arguments:#()
- expectError:#ParseError
-
- "
- self run:#testScanner12
- self new testScanner12
- "
-!
-
-testScanner13
- "/ cg: is the comment below legal ?
- ^ self. "/ assume not
-
- self
- execute:'f_1() { /*/
- return (null); }'
- for:nil
- arguments:#()
- expectError:#ParseError
-
- "
- self run:#testScanner13
- self new testScanner13
- "
-!
-
-testScanner20
- #(
-
- ' = ' $=
- '/* ignored */= ' $=
- '/* ignored */ = ' $=
- ' + ' $+
- ' - ' $-
- ' * ' $*
- ' / ' $/
- ' % ' $%
- ' & ' $&
- ' ^ ' $^
- ' | ' $|
- ' !! ' $!!
- ' < ' $<
- ' > ' $>
-
- ' << ' #'<<'
- ' >> ' #'>>'
- ' == ' #'=='
- ' <= ' #'<='
- ' >= ' #'>='
- ' !!= ' #'!!='
- ' || ' #'||'
- ' && ' #'&&'
- ' ++ ' #'++'
- ' -- ' #'--'
-
- ' += ' #'+='
- ' -= ' #'-='
- ' *= ' #'*='
- ' /= ' #'/='
- ' %= ' #'%='
- ' &= ' #'&='
- ' ^= ' #'^='
- ' |= ' #'|='
-
- ' >>> ' #'>>>'
- ' >>= ' #'>>='
- ' <<= ' #'<<='
- ' === ' #'==='
- ' !!== ' #'!!=='
-
- ' 1 ' #Integer
- ' 12345 ' #Integer
- ' 1.0 ' #Float
- ' 1e10 ' #Float
- ' 1E10 ' #Float
- ' 1E+10 ' #Float
- ' 1E-10 ' #Float
- ' 1.0d ' #Float
- ' 1. ' #Float
-"/ ' 1.' #Float
- ) pairWiseDo:[:src :expectedToken |
- |scannedToken|
-
- scannedToken := (JavaScriptScanner for:src) nextToken.
- self assert:(scannedToken == expectedToken)
- ].
-
- "
- self run:#testScanner20
- self new testScanner20
- "
-!
-
testString01
self
execute:'test(str) {
@@ -5635,6 +5457,70 @@
"Created: / 17-09-2014 / 14:59:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!
+xtestInnerFunctionWithInitializedLocals
+
+ self
+ execute:'
+execute() {
+ function foo() {}
+ function bar() {}
+
+ function test()
+ {
+
+ foo();
+ bar();
+ var a;
+ var b;
+ var c = Array.new(15);
+ var d = 20;
+
+ return [ a , b , c , d ];
+ }
+
+ test();
+}
+'
+ for:nil
+ arguments:#()
+ expect:{ nil . nil . (Array new:15) . 20 }
+
+ "
+ self run:#testInnerFunctionWithInitializedLocals
+ self new testInnerFunctionWithInitializedLocals
+ "
+!
+
+xtestNew04
+ self
+ execute:'test() {
+ var days;
+
+ days = new Array(7,2);
+ days[1,1] = "Monday";
+ days[2,1] = "Tuesday";
+ days[3,1] = "Wednesday";
+ days[4,1] = "Thursday";
+ days[5,1] = "Friday";
+ days[6,1] = "Saturday";
+ days[7,1] = "Sunday";
+
+ return days;
+ }'
+ for:nil
+ arguments:#()
+ expect:#('Monday' 'Tuesday' 'Wednesday' 'Thursday' 'Friday' 'Saturday' 'Sunday')
+
+ "
+ self run:#testNew04
+ self new testNew04
+ "
+
+ "Created: / 23-02-2007 / 12:24:50 / cg"
+! !
+
+!JavaScriptTests methodsFor:'tests-parser'!
+
test_01_parse_literals
|spec|
@@ -5813,6 +5699,22 @@
"
!
+test_12_parse_lambdaExpression1
+ |spec|
+
+ spec := #(
+ ('(foo) => { return foo; }' isInnerFunction #void )
+ ('(foo,bar) => { return foo+bar; }' isInnerFunction #void )
+ ).
+
+ self doTestEachFromSpec:spec.
+
+ "
+ self run:#test_12_parse_lambdaExpression1
+ self new test_12_parse_lambdaExpression1
+ "
+!
+
test_30_parse_methods1
|spec|
@@ -5852,68 +5754,260 @@
self assert: tree selectorPosition = (6 to: 8)
"Created: / 17-11-2014 / 13:31:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-!
-
-xtestInnerFunctionWithInitializedLocals
-
- self
- execute:'
-execute() {
- function foo() {}
- function bar() {}
-
- function test()
- {
-
- foo();
- bar();
- var a;
- var b;
- var c = Array.new(15);
- var d = 20;
-
- return [ a , b , c , d ];
- }
-
- test();
-}
-'
+! !
+
+!JavaScriptTests methodsFor:'tests-scanner'!
+
+testScanner01
+ self
+ execute:'f() { }'
+ for:nil
+ arguments:#()
+ expect:nil
+
+ "
+ self run:#testScanner01
+ self new testScanner01
+ "
+!
+
+testScanner02
+ self
+ execute:'f(a) { }'
+ for:nil
+ arguments:#(1)
+ expect:nil
+
+ "
+ self run:#testScanner02
+ self new testScanner02
+ "
+!
+
+testScanner03
+ self
+ execute:'f(a, b) { }'
+ for:nil
+ arguments:#(1 2)
+ expect:nil
+
+ "
+ self run:#testScanner03
+ self new testScanner03
+ "
+!
+
+testScanner04
+ self
+ execute:'f(a, b) { return (null); }'
+ for:nil
+ arguments:#(1 2)
+ expect:nil
+
+ "
+ self run:#testScanner04
+ self new testScanner04
+ "
+!
+
+testScanner05
+ self
+ execute:'f(a, b) { return (null); }'
+ for:nil
+ arguments:#(1)
+ expectError:(Method wongNumberOfArgumentsSignal)
+
+ "
+ self run:#testScanner05
+ self new testScanner05
+ "
+
+ "Modified: / 20-04-2005 / 11:53:20 / cg"
+!
+
+testScanner06
+ self
+ execute:'f() { /* a comment */ return (null); }'
+ for:nil
+ arguments:#()
+ expect:nil
+
+ "
+ self run:#testScanner06
+ self new testScanner06
+ "
+!
+
+testScanner07
+ self
+ execute:'f() { // an EOL comment
+ return (null); }'
+ for:nil
+ arguments:#()
+ expect:nil
+
+ "
+ self run:#testScanner07
+ self new testScanner07
+ "
+!
+
+testScanner08
+ self
+ execute:'f() { // a comment in an /* an EOL comment
+ return (null); }'
+ for:nil
+ arguments:#()
+ expect:nil
+
+ "
+ self run:#testScanner08
+ self new testScanner08
+ "
+!
+
+testScanner09
+ self
+ execute:'f() { // a comment in an /* an EOL */ comment
+ return (null); }'
for:nil
arguments:#()
- expect:{ nil . nil . (Array new:15) . 20 }
-
- "
- self run:#testInnerFunctionWithInitializedLocals
- self new testInnerFunctionWithInitializedLocals
- "
-!
-
-xtestNew04
- self
- execute:'test() {
- var days;
-
- days = new Array(7,2);
- days[1,1] = "Monday";
- days[2,1] = "Tuesday";
- days[3,1] = "Wednesday";
- days[4,1] = "Thursday";
- days[5,1] = "Friday";
- days[6,1] = "Saturday";
- days[7,1] = "Sunday";
-
- return days;
- }'
+ expect:nil
+
+ "
+ self run:#testScanner09
+ self new testScanner09
+ "
+!
+
+testScanner10
+ self
+ execute:'f() { /** a comment */
+ return (null); }'
+ for:nil
+ arguments:#()
+ expect:nil
+
+ "
+ self run:#testScanner10
+ self new testScanner10
+ "
+!
+
+testScanner11
+ self
+ execute:'f() { /**/
+ return (null); }'
+ for:nil
+ arguments:#()
+ expect:nil
+
+ "
+ self run:#testScanner11
+ self new testScanner11
+ "
+!
+
+testScanner12
+ "/ cg: is the comment below legal ?
+ ^ self. "/ assume not
+
+ self
+ execute:'f() { /*/
+ return (null); }'
+ for:nil
+ arguments:#()
+ expectError:#ParseError
+
+ "
+ self run:#testScanner12
+ self new testScanner12
+ "
+!
+
+testScanner13
+ "/ cg: is the comment below legal ?
+ ^ self. "/ assume not
+
+ self
+ execute:'f_1() { /*/
+ return (null); }'
for:nil
arguments:#()
- expect:#('Monday' 'Tuesday' 'Wednesday' 'Thursday' 'Friday' 'Saturday' 'Sunday')
-
- "
- self run:#testNew04
- self new testNew04
- "
-
- "Created: / 23-02-2007 / 12:24:50 / cg"
+ expectError:#ParseError
+
+ "
+ self run:#testScanner13
+ self new testScanner13
+ "
+!
+
+testScanner20
+ #(
+
+ ' = ' $=
+ '/* ignored */= ' $=
+ '/* ignored */ = ' $=
+ ' + ' $+
+ ' - ' $-
+ ' * ' $*
+ ' / ' $/
+ ' % ' $%
+ ' & ' $&
+ ' ^ ' $^
+ ' | ' $|
+ ' !! ' $!!
+ ' < ' $<
+ ' > ' $>
+
+ ' << ' #'<<'
+ ' >> ' #'>>'
+ ' == ' #'=='
+ ' <= ' #'<='
+ ' >= ' #'>='
+ ' !!= ' #'!!='
+ ' || ' #'||'
+ ' && ' #'&&'
+ ' ++ ' #'++'
+ ' -- ' #'--'
+
+ ' += ' #'+='
+ ' -= ' #'-='
+ ' *= ' #'*='
+ ' /= ' #'/='
+ ' %= ' #'%='
+ ' &= ' #'&='
+ ' ^= ' #'^='
+ ' |= ' #'|='
+
+ ' >>> ' #'>>>'
+ ' >>= ' #'>>='
+ ' <<= ' #'<<='
+ ' === ' #'==='
+ ' !!== ' #'!!=='
+ ' => ' #'=>'
+
+ ' 1 ' #Integer
+ ' 12345 ' #Integer
+ ' 1.0 ' #Float
+ ' 1e10 ' #Float
+ ' 1E10 ' #Float
+ ' 1E+10 ' #Float
+ ' 1E-10 ' #Float
+ ' 1.0d ' #Float
+ ' 1. ' #Float
+"/ ' 1.' #Float
+ ) pairWiseDo:[:src :expectedToken |
+ |scannedToken|
+
+ scannedToken := (JavaScriptScanner for:src) nextToken.
+ self assert:(scannedToken == expectedToken) message:'expected: ',expectedToken, ' got: ',scannedToken.
+ ].
+
+ "
+ self run:#testScanner20
+ self new testScanner20
+ "
! !
!JavaScriptTests class methodsFor:'documentation'!