compiler/tests/PPCUniversalTest.st
changeset 537 fb212e14d1f4
parent 535 a8feb0f47574
child 538 16e8536f5cfb
equal deleted inserted replaced
536:548996aca274 537:fb212e14d1f4
     2 
     2 
     3 "{ NameSpace: Smalltalk }"
     3 "{ NameSpace: Smalltalk }"
     4 
     4 
     5 PPAbstractParserTest subclass:#PPCUniversalTest
     5 PPAbstractParserTest subclass:#PPCUniversalTest
     6 	instanceVariableNames:'parser result context node compiler id node2 id2 id1 node1 node3
     6 	instanceVariableNames:'parser result context node compiler id node2 id2 id1 node1 node3
     7 		options configuration'
     7 		options'
     8 	classVariableNames:''
     8 	classVariableNames:''
     9 	poolDictionaries:''
     9 	poolDictionaries:''
    10 	category:'PetitCompiler-Tests-Core-Universal'
    10 	category:'PetitCompiler-Tests-Core-Universal'
    11 !
    11 !
    12 
    12 
    39 ! !
    39 ! !
    40 
    40 
    41 !PPCUniversalTest methodsFor:'tests - compiling'!
    41 !PPCUniversalTest methodsFor:'tests - compiling'!
    42 
    42 
    43 testCompileAnd
    43 testCompileAnd
    44     parser := #digit asParser and compileWithConfiguration: configuration.
    44     parser := #digit asParser and compileUsingCompiler:compiler.
    45     
    45     
    46     self assert: parser parse: '1' to: $1 end: 0.
    46     self assert: parser parse: '1' to: $1 end: 0.
    47     self assert: parser fail: 'a'.
    47     self assert: parser fail: 'a'.
    48     self assert: parser fail: ''.
    48     self assert: parser fail: ''.
    49 
    49 
    59     self assert: parser parse: '
    59     self assert: parser parse: '
    60 ' to: Character cr.
    60 ' to: Character cr.
    61 !
    61 !
    62 
    62 
    63 testCompileAnyStar
    63 testCompileAnyStar
    64     parser := #any asParser star compileWithConfiguration: configuration.
    64     parser := #any asParser star compileUsingCompiler:compiler.
    65     
    65     
    66     
    66     
    67     self assert: parser parse: 'aaa' to: { $a. $a . $a }.
    67     self assert: parser parse: 'aaa' to: { $a. $a . $a }.
    68     self assert: context invocationCount = 1.
    68     self assert: context invocationCount = 1.
    69     self assert: parser parse: '' to: { }.	
    69     self assert: parser parse: '' to: { }.	
    70 !
    70 !
    71 
    71 
    72 testCompileBlock
    72 testCompileBlock
    73     parser := (#letter asParser) plus ==> [ :res | res collect: [:each | each asUppercase ]].
    73     parser := (#letter asParser) plus ==> [ :res | res collect: [:each | each asUppercase ]].
    74     parser := parser compileWithConfiguration: configuration.
    74     parser := parser compileUsingCompiler:compiler.
    75     
    75     
    76     self assert: parser parse: 'foo' to: { $F . $O . $O}.
    76     self assert: parser parse: 'foo' to: { $F . $O . $O}.
    77     self assert: parser parse: 'bar' to: { $B . $A . $R}.
    77     self assert: parser parse: 'bar' to: { $B . $A . $R}.
    78     self assert: parser fail: ''.
    78     self assert: parser fail: ''.
    79 !
    79 !
    80 
    80 
    81 testCompileCharacter
    81 testCompileCharacter
    82     parser := $a asParser compileWithConfiguration: configuration.
    82     parser := $a asParser compileUsingCompiler:compiler.
    83     
    83     
    84     self assert: parser parse: 'a'  to: $a.
    84     self assert: parser parse: 'a'  to: $a.
    85     self assert: parser fail: 'b'.
    85     self assert: parser fail: 'b'.
    86 
    86 
    87     parser := $# asParser compileWithConfiguration: configuration.
    87     parser := $# asParser compileUsingCompiler:compiler.
    88     self assert: parser parse: '#'.
    88     self assert: parser parse: '#'.
    89 !
    89 !
    90 
    90 
    91 testCompileChoice
    91 testCompileChoice
    92     parser := (#digit asParser / #letter asParser) compileWithConfiguration: configuration.
    92     parser := (#digit asParser / #letter asParser) compileUsingCompiler:compiler.
    93     
    93     
    94     self assert: parser parse: '1' to: $1.
    94     self assert: parser parse: '1' to: $1.
    95     self assert: parser parse: 'a' to: $a.
    95     self assert: parser parse: 'a' to: $a.
    96     self assert: parser fail: '_'.
    96     self assert: parser fail: '_'.
    97     
    97     
    98 !
    98 !
    99 
    99 
   100 testCompileChoice2
   100 testCompileChoice2
   101     parser := ('true' asParser / 'false' asParser) compileWithConfiguration: configuration.
   101     parser := ('true' asParser / 'false' asParser) compileUsingCompiler:compiler.
   102     
   102     
   103     self assert: parser parse: 'true' to: 'true'.
   103     self assert: parser parse: 'true' to: 'true'.
   104     self assert: parser parse: 'false' to: 'false'.
   104     self assert: parser parse: 'false' to: 'false'.
   105     self assert: parser fail: 'trulse'.
   105     self assert: parser fail: 'trulse'.
   106     
   106     
   107 !
   107 !
   108 
   108 
   109 testCompileLiteral
   109 testCompileLiteral
   110     parser := 'foo' asParser compileWithConfiguration: configuration.
   110     parser := 'foo' asParser compileUsingCompiler:compiler.
   111     
   111     
   112     self assert: parser parse: 'foo'  to: 'foo'.
   112     self assert: parser parse: 'foo'  to: 'foo'.
   113     self assert: parser parse: 'foobar'  to: 'foo' end: 3.
   113     self assert: parser parse: 'foobar'  to: 'foo' end: 3.
   114     self assert: parser fail: 'boo'.
   114     self assert: parser fail: 'boo'.
   115     
   115     
   116     parser := '#[' asParser compileWithConfiguration: configuration.
   116     parser := '#[' asParser compileUsingCompiler:compiler.
   117     self assert: parser parse: '#[1]' to: '#[' end: 2.
   117     self assert: parser parse: '#[1]' to: '#[' end: 2.
   118 !
   118 !
   119 
   119 
   120 testCompileLiteral2
   120 testCompileLiteral2
   121     | quote |
   121     | quote |
   122     quote := '''' asParser.
   122     quote := '''' asParser.
   123     parser := (quote, $a asParser ) compileWithConfiguration: configuration.	
   123     parser := (quote , $a asParser) compileUsingCompiler:compiler.	
   124     self assert: parser parse: '''a'  to: {'''' . $a}.	
   124     self assert: parser parse: '''a'  to: {'''' . $a}.	
   125 !
   125 !
   126 
   126 
   127 testCompileNegate
   127 testCompileNegate
   128     parser := #letter asParser negate star, #letter asParser.
   128     parser := #letter asParser negate star, #letter asParser.
   129     parser := parser compileWithConfiguration: configuration.
   129     parser := parser compileUsingCompiler:compiler.
   130     
   130     
   131     self assert: parser parse: '...a' to: { { $. . $. . $. } . $a }.
   131     self assert: parser parse: '...a' to: { { $. . $. . $. } . $a }.
   132     self assert: parser parse: 'aaa' to: { {} . $a } end: 1.
   132     self assert: parser parse: 'aaa' to: { {} . $a } end: 1.
   133     self assert: parser fail: '...'.
   133     self assert: parser fail: '...'.
   134 !
   134 !
   135 
   135 
   136 testCompileNil
   136 testCompileNil
   137     parser := nil asParser compileWithConfiguration: configuration.
   137     parser := nil asParser compileUsingCompiler:compiler.
   138     
   138     
   139     self assert: parser parse: 'a' to: nil end: 0.
   139     self assert: parser parse: 'a' to: nil end: 0.
   140     self assert: parser parse: '' to: nil end: 0.
   140     self assert: parser parse: '' to: nil end: 0.
   141     
   141     
   142     parser := nil asParser, 'foo' asParser.
   142     parser := nil asParser, 'foo' asParser.
   143     self assert: parser parse: 'foo' to: { nil . 'foo' }
   143     self assert: parser parse: 'foo' to: { nil . 'foo' }
   144 !
   144 !
   145 
   145 
   146 testCompileNot
   146 testCompileNot
   147     parser := #digit asParser not compileWithConfiguration: configuration.
   147     parser := #digit asParser not compileUsingCompiler:compiler.
   148     
   148     
   149     self assert: parser parse: 'a' to: nil end: 0.
   149     self assert: parser parse: 'a' to: nil end: 0.
   150     self assert: parser fail: '1'.
   150     self assert: parser fail: '1'.
   151     self assert: parser parse: '' to: nil end: 0.
   151     self assert: parser parse: '' to: nil end: 0.
   152 
   152 
   153     parser := 'foo' asParser, $: asParser not.
   153     parser := 'foo' asParser, $: asParser not.
   154     parser := parser compileWithConfiguration: configuration.	
   154     parser := parser compileUsingCompiler:compiler.	
   155     self assert: parser parse: 'foo' to: { 'foo'. nil } end: 3.
   155     self assert: parser parse: 'foo' to: { 'foo'. nil } end: 3.
   156     
   156     
   157     parser := 'foo' asParser, $: asParser not, 'bar' asParser.
   157     parser := 'foo' asParser, $: asParser not, 'bar' asParser.
   158     parser := parser compileWithConfiguration: configuration.	
   158     parser := parser compileUsingCompiler:compiler.	
   159     self assert: parser parse: 'foobar' to: { 'foo'. nil . 'bar' } end: 6.
   159     self assert: parser parse: 'foobar' to: { 'foo'. nil . 'bar' } end: 6.
   160 !
   160 !
   161 
   161 
   162 testCompileNot2
   162 testCompileNot2
   163     parser := ($a asParser, $b asParser) not compileWithConfiguration: configuration.
   163     parser := ($a asParser , $b asParser) not compileUsingCompiler:compiler.
   164         
   164         
   165     self assert: parser parse: '' to: nil end: 0.
   165     self assert: parser parse: '' to: nil end: 0.
   166     self assert: parser parse: 'a' to: nil end: 0.
   166     self assert: parser parse: 'a' to: nil end: 0.
   167     self assert: parser parse: 'aa' to: nil end: 0.
   167     self assert: parser parse: 'aa' to: nil end: 0.
   168     self assert: parser fail: 'ab'.
   168     self assert: parser fail: 'ab'.
   169 !
   169 !
   170 
   170 
   171 testCompileNot3
   171 testCompileNot3
   172     parser := ('foo' asParser not, 'fee' asParser) compileWithConfiguration: configuration.
   172     parser := ('foo' asParser not , 'fee' asParser) compileUsingCompiler:compiler.
   173         
   173         
   174     self assert: parser parse: 'fee' to: #(nil 'fee').
   174     self assert: parser parse: 'fee' to: #(nil 'fee').
   175     self assert: parser fail: 'foo'.
   175     self assert: parser fail: 'foo'.
   176 !
   176 !
   177 
   177 
   178 testCompileNotLiteral
   178 testCompileNotLiteral
   179     parser := 'foo' asParser not compileWithConfiguration: configuration.
   179     parser := 'foo' asParser not compileUsingCompiler:compiler.
   180     self assert: parser class methodDictionary size = 1.
   180     self assert: parser class methodDictionary size = 1.
   181 
   181 
   182     self assert: parser parse: 'bar' to: nil end: 0.
   182     self assert: parser parse: 'bar' to: nil end: 0.
   183         
   183         
   184     self assert: parser fail: 'foo'.
   184     self assert: parser fail: 'foo'.
   199     self assert: parser parse: 'foobar' to: { 'foo'. nil . #($b $a $r) } end: 6.
   199     self assert: parser parse: 'foobar' to: { 'foo'. nil . #($b $a $r) } end: 6.
   200     self assert: parser fail: 'foofoo'.
   200     self assert: parser fail: 'foofoo'.
   201 !
   201 !
   202 
   202 
   203 testCompileOptional
   203 testCompileOptional
   204     parser := #digit asParser optional compileWithConfiguration: configuration.
   204     parser := #digit asParser optional compileUsingCompiler:compiler.
   205     
   205     
   206     self assert: parser parse: '1' to: $1.
   206     self assert: parser parse: '1' to: $1.
   207     self assert: parser parse: 'a' to: nil end: 0.
   207     self assert: parser parse: 'a' to: nil end: 0.
   208     
   208     
   209     parser := (#digit asParser optional, #letter asParser) compile.
   209     parser := (#digit asParser optional, #letter asParser) compile.
   210     self assert: parser parse: '1a' to: { $1 . $a }.
   210     self assert: parser parse: '1a' to: { $1 . $a }.
   211     self assert: parser parse: 'a' to: { nil . $a }.
   211     self assert: parser parse: 'a' to: { nil . $a }.
   212 !
   212 !
   213 
   213 
   214 testCompilePlus
   214 testCompilePlus
   215     parser := #letter asParser plus compileWithConfiguration: configuration.
   215     parser := #letter asParser plus compileUsingCompiler:compiler.
   216     
   216     
   217     self assert: parser parse: 'lorem' to: {$l. $o. $r. $e. $m} .
   217     self assert: parser parse: 'lorem' to: {$l. $o. $r. $e. $m} .
   218     self assert: parser parse: 'a123' to: {$a} end: 1.
   218     self assert: parser parse: 'a123' to: {$a} end: 1.
   219     self assert: parser parse: 'ab123' to: {$a . $b} end: 2.
   219     self assert: parser parse: 'ab123' to: {$a . $b} end: 2.
   220 
   220 
   221     self assert: parser fail: ''.
   221     self assert: parser fail: ''.
   222     self assert: parser fail: '123'.
   222     self assert: parser fail: '123'.
   223 !
   223 !
   224 
   224 
   225 testCompilePredicate
   225 testCompilePredicate
   226     parser := #digit asParser compileWithConfiguration: configuration.
   226     parser := #digit asParser compileUsingCompiler:compiler.
   227     
   227     
   228     self assert: parser parse: '1' to: $1.
   228     self assert: parser parse: '1' to: $1.
   229     self assert: parser parse: '0' to: $0.
   229     self assert: parser parse: '0' to: $0.
   230     self assert: parser fail: 'a'.
   230     self assert: parser fail: 'a'.
   231 !
   231 !
   232 
   232 
   233 testCompilePredicate2
   233 testCompilePredicate2
   234     parser := #space asParser compileWithConfiguration: configuration.
   234     parser := #space asParser compileUsingCompiler:compiler.
   235     
   235     
   236     self assert: parser parse: ' ' to: Character space.
   236     self assert: parser parse: ' ' to: Character space.
   237     self assert: parser fail: 'a'.
   237     self assert: parser fail: 'a'.
   238 !
   238 !
   239 
   239 
   240 testCompileSequence
   240 testCompileSequence
   241     parser := (#digit asParser, #letter asParser) compileWithConfiguration: configuration.
   241     parser := (#digit asParser , #letter asParser) compileUsingCompiler:compiler.
   242     
   242     
   243     self assert: parser parse: '1a' to: {$1 .$a}.
   243     self assert: parser parse: '1a' to: {$1 .$a}.
   244     
   244     
   245     
   245     
   246 !
   246 !
   247 
   247 
   248 testCompileSequence2
   248 testCompileSequence2
   249     parser := (#digit asParser, #space asParser, #letter asParser) compileWithConfiguration: configuration.
   249     parser := (#digit asParser , #space asParser , #letter asParser) 
       
   250                     compileUsingCompiler:compiler.
   250     
   251     
   251     self assert: parser parse: '9 c' to: {$9 . Character space. $c }.	
   252     self assert: parser parse: '9 c' to: {$9 . Character space. $c }.	
   252     self assert: parser fail: '9c'.
   253     self assert: parser fail: '9c'.
   253     
   254     
   254 !
   255 !
   255 
   256 
   256 testCompileSequence3
   257 testCompileSequence3
   257     parser := (#any asParser, #any asParser, #any asParser) compileWithConfiguration: configuration.
   258     parser := (#any asParser , #any asParser , #any asParser) 
       
   259                     compileUsingCompiler:compiler.
   258     
   260     
   259     self assert: parser parse: 'foo' to: #($f $o $o).	
   261     self assert: parser parse: 'foo' to: #($f $o $o).	
   260     self assert: parser fail: 'fo'.
   262     self assert: parser fail: 'fo'.
   261     
   263     
   262 !
   264 !
   263 
   265 
   264 testCompileStar
   266 testCompileStar
   265     parser := #letter asParser star compileWithConfiguration: configuration.
   267     parser := #letter asParser star compileUsingCompiler:compiler.
   266     
   268     
   267     self assert: parser parse: 'lorem' to: {$l. $o. $r. $e. $m} .
   269     self assert: parser parse: 'lorem' to: {$l. $o. $r. $e. $m} .
   268     self assert: parser parse: '' to: {}.
   270     self assert: parser parse: '' to: {}.
   269     self assert: parser parse: '123' to: {} end: 0.
   271     self assert: parser parse: '123' to: {} end: 0.
   270     self assert: parser parse: 'ab123' to: {$a . $b} end: 2.
   272     self assert: parser parse: 'ab123' to: {$a . $b} end: 2.
   271 !
   273 !
   272 
   274 
   273 testCompileStarLiteral
   275 testCompileStarLiteral
   274     parser := 'foo' asParser star compileWithConfiguration: configuration.
   276     parser := 'foo' asParser star compileUsingCompiler:compiler.
   275     
   277     
   276     self assert: parser parse: 'foo' to: #('foo' ) .
   278     self assert: parser parse: 'foo' to: #('foo' ) .
   277     self assert: parser parse: 'foofoo' to: #('foo' 'foo') .
   279     self assert: parser parse: 'foofoo' to: #('foo' 'foo') .
   278     self assert: parser parse: 'foofoofoo' to: #('foo' 'foo' 'foo') .
   280     self assert: parser parse: 'foofoofoo' to: #('foo' 'foo' 'foo') .
   279     self assert: parser parse: '' to: #().
   281     self assert: parser parse: '' to: #().
   280     self assert: parser parse: 'bar' to: #() end: 0.
   282     self assert: parser parse: 'bar' to: #() end: 0.
   281 !
   283 !
   282 
   284 
   283 testCompileStarPredicate
   285 testCompileStarPredicate
   284     parser := #letter asParser star compileWithConfiguration: configuration.
   286     parser := #letter asParser star compileUsingCompiler:compiler.
   285     
   287     
   286     self assert: parser parse: 'foo' to: #($f $o $o ) .
   288     self assert: parser parse: 'foo' to: #($f $o $o ) .
   287     self assert: parser parse: '' to: #().
   289     self assert: parser parse: '' to: #().
   288     self assert: parser parse: '123' to: #() end: 0.
   290     self assert: parser parse: '123' to: #() end: 0.
   289 !
   291 !
   290 
   292 
   291 testCompileSymbolBlock
   293 testCompileSymbolBlock
   292     parser := (#letter asParser) plus ==> #second.
   294     parser := (#letter asParser) plus ==> #second.
   293     parser := parser compileWithConfiguration: configuration.
   295     parser := parser compileUsingCompiler:compiler.
   294     
   296     
   295     self assert: parser parse: 'foo' to: $o.
   297     self assert: parser parse: 'foo' to: $o.
   296     self assert: parser parse: 'bar' to: $a.
   298     self assert: parser parse: 'bar' to: $a.
   297     self assert: parser fail: ''.
   299     self assert: parser fail: ''.
   298     self should: [ parser parse: 'f' ] raise: Error.
   300     self should: [ parser parse: 'f' ] raise: Error.
   299 !
   301 !
   300 
   302 
   301 testCompileTrim
   303 testCompileTrim
   302     parser := $a asParser trim compileWithConfiguration: configuration.
   304     parser := $a asParser trim compileUsingCompiler:compiler.
   303     
   305     
   304     self assert: parser fail: ''.
   306     self assert: parser fail: ''.
   305     self assert: parser parse: 'a' to: $a.
   307     self assert: parser parse: 'a' to: $a.
   306     self assert: parser parse: '   a' to: $a.
   308     self assert: parser parse: '   a' to: $a.
   307     self assert: parser parse: 'a    ' to: $a.
   309     self assert: parser parse: 'a    ' to: $a.
   311 testCompileTrimmingToken
   313 testCompileTrimmingToken
   312     | token1 token2 |
   314     | token1 token2 |
   313     token1 := (#letter asParser) plus trimmingToken.
   315     token1 := (#letter asParser) plus trimmingToken.
   314     token2 := (#letter asParser) plus trimmingToken.
   316     token2 := (#letter asParser) plus trimmingToken.
   315     
   317     
   316     parser := (token1, token2) compileWithConfiguration: configuration.
   318     parser := (token1 , token2) compileUsingCompiler:compiler.
   317     
   319     
   318     self assert: parser parse: 'foo bar'.
   320     self assert: parser parse: 'foo bar'.
   319     self assert: parser parse: ' foo bar '.
   321     self assert: parser parse: ' foo bar '.
   320 !
   322 !
   321 
   323 
   322 testCompileTrimmingToken2
   324 testCompileTrimmingToken2
   323     | token1 token2 |
   325     | token1 token2 |
   324     token1 := (#letter asParser) plus trimmingToken.
   326     token1 := (#letter asParser) plus trimmingToken.
   325     token2 := (#letter asParser) plus trimmingToken / 'foo' asParser trimmingToken.
   327     token2 := (#letter asParser) plus trimmingToken / 'foo' asParser trimmingToken.
   326     
   328     
   327     parser := (token1, token2) compileWithConfiguration: configuration.
   329     parser := (token1 , token2) compileUsingCompiler:compiler.
   328     
   330     
   329     self assert: parser parse: 'foo bar'.
   331     self assert: parser parse: 'foo bar'.
   330     self assert: parser parse: ' foo bar '.
   332     self assert: parser parse: ' foo bar '.
   331 !
   333 !
   332 
   334 
   333 testCompileTrimmingToken3
   335 testCompileTrimmingToken3
   334     | token1 token2 |
   336     | token1 token2 |
   335     token1 := ($a asParser, $b asParser) trimmingToken name: 'token1'.
   337     token1 := ($a asParser, $b asParser) trimmingToken name: 'token1'.
   336     token2 := (token1 not, $c asParser) trimmingToken name: 'token2'.
   338     token2 := (token1 not, $c asParser) trimmingToken name: 'token2'.
   337     
   339     
   338     parser := (token1 / token2) compileWithConfiguration: configuration.
   340     parser := (token1 / token2) compileUsingCompiler:compiler.
   339 
   341 
   340     self assert: (parser class methodDictionary includesKey: #'token1').
   342     self assert: (parser class methodDictionary includesKey: #'token1').
   341     self assert: (parser class methodDictionary includesKey: #'token1_fast').
   343     self assert: (parser class methodDictionary includesKey: #'token1_fast').
   342     
   344     
   343     self assert: parser parse: 'ab'.
   345     self assert: parser parse: 'ab'.
   351 ! !
   353 ! !
   352 
   354 
   353 !PPCUniversalTest methodsFor:'tests - extra'!
   355 !PPCUniversalTest methodsFor:'tests - extra'!
   354 
   356 
   355 testCompileSmalltalkToken
   357 testCompileSmalltalkToken
   356     parser := (#letter asParser, ((#letter asParser / #digit asParser) star)) smalltalkToken compileWithConfiguration: configuration.
   358     parser := (#letter asParser , ((#letter asParser / #digit asParser) star)) 
       
   359                     smalltalkToken compileUsingCompiler:compiler.
   357     
   360     
   358     self assert: parser parse: 'foo'.
   361     self assert: parser parse: 'foo'.
   359     self assert: result inputValue = 'foo'.
   362     self assert: result inputValue = 'foo'.
   360     self assert: parser parse: 'a'.
   363     self assert: parser parse: 'a'.
   361     self assert: result inputValue = 'a'.
   364     self assert: result inputValue = 'a'.
   386     
   389     
   387     p1 := PPDelegateParser new.
   390     p1 := PPDelegateParser new.
   388     block := ${ asParser, p1, $} asParser / nil asParser.
   391     block := ${ asParser, p1, $} asParser / nil asParser.
   389     p1 setParser: block.
   392     p1 setParser: block.
   390     
   393     
   391     parser := block compileWithConfiguration: configuration.
   394     parser := block compileUsingCompiler:compiler.
   392     self assert: parser parse: '{}' to: { ${. nil . $} }.
   395     self assert: parser parse: '{}' to: { ${. nil . $} }.
   393     self assert: parser parse: '{{}}' to: { ${. { ${ . nil . $} } . $} }.
   396     self assert: parser parse: '{{}}' to: { ${. { ${ . nil . $} } . $} }.
   394     
   397     
   395 !
   398 !
   396 
   399 
   397 testSmalltalkToken
   400 testSmalltalkToken
   398     parser := (#letter asParser, (#digit asParser / #letter asParser) star) smalltalkToken compileWithConfiguration: configuration.
   401     parser := (#letter asParser , (#digit asParser / #letter asParser) star) 
       
   402                     smalltalkToken compileUsingCompiler:compiler.
   399     
   403     
   400     self assert: parser class methodDictionary size = 5.
   404     self assert: parser class methodDictionary size = 5.
   401     self assert: parser parse: 'foo'.
   405     self assert: parser parse: 'foo'.
   402     self assert: result inputValue = 'foo'.
   406     self assert: result inputValue = 'foo'.
   403     self assert: context invocationCount = 8.
   407     self assert: context invocationCount = 8.
   413         
   417         
   414     parser := (id wrapped, $: asParser) smalltalkToken 
   418     parser := (id wrapped, $: asParser) smalltalkToken 
   415         name: 'kw';
   419         name: 'kw';
   416         yourself.
   420         yourself.
   417     
   421     
   418     parser := parser compileWithConfiguration: configuration.
   422     parser := parser compileUsingCompiler:compiler.
   419     
   423     
   420     self assert: parser parse: 'foo:'.
   424     self assert: parser parse: 'foo:'.
   421     self assert: result inputValue = 'foo:'.
   425     self assert: result inputValue = 'foo:'.
   422 !
   426 !
   423 
   427 
   424 testToken
   428 testToken
   425     parser := (#letter asParser, (#digit asParser / #letter asParser) star) flatten compileWithConfiguration: configuration.
   429     parser := (#letter asParser , (#digit asParser / #letter asParser) star) flatten 
       
   430                     compileUsingCompiler:compiler.
   426     
   431     
   427     self assert: parser parse: 'foo' to: 'foo'.
   432     self assert: parser parse: 'foo' to: 'foo'.
   428     self assert: parser parse: 'a' to: 'a'.
   433     self assert: parser parse: 'a' to: 'a'.
   429     self assert: parser parse: 'f123a' to: 'f123a'.
   434     self assert: parser parse: 'f123a' to: 'f123a'.
   430     self assert: parser fail: ''.
   435     self assert: parser fail: ''.
   431 !
   436 !
   432 
   437 
   433 testToken2
   438 testToken2
   434     parser := (#letter asParser, (#digit asParser / #letter asParser) star) token compileWithConfiguration: configuration.
   439     parser := (#letter asParser , (#digit asParser / #letter asParser) star) token 
       
   440                     compileUsingCompiler:compiler.
   435     
   441     
   436     self assert: parser class methodDictionary size = 4.
   442     self assert: parser class methodDictionary size = 4.
   437     self assert: parser parse: 'foo'.
   443     self assert: parser parse: 'foo'.
   438     self assert: result inputValue = 'foo'.
   444     self assert: result inputValue = 'foo'.
   439     self assert: context invocationCount = 6.
   445     self assert: context invocationCount = 6.
   441     self assert: context lwRememberCount = 0.
   447     self assert: context lwRememberCount = 0.
   442     self assert: context lwRestoreCount = 0.	
   448     self assert: context lwRestoreCount = 0.	
   443 !
   449 !
   444 
   450 
   445 testTrimmingToken
   451 testTrimmingToken
   446     parser := (#letter asParser, (#digit asParser / #letter asParser) star) trimmingToken compileWithConfiguration: configuration.
   452     parser := (#letter asParser , (#digit asParser / #letter asParser) star) 
       
   453                     trimmingToken compileUsingCompiler:compiler.
   447 
   454 
   448     self assert: parser class methodDictionary size = 4.
   455     self assert: parser class methodDictionary size = 4.
   449     self assert: parser parse: 'foo'.
   456     self assert: parser parse: 'foo'.
   450     self assert: result inputValue = 'foo'.
   457     self assert: result inputValue = 'foo'.
   451 
   458 
   470     self assert: parser fail: ''.
   477     self assert: parser fail: ''.
   471 !
   478 !
   472 
   479 
   473 testTrimmingToken2
   480 testTrimmingToken2
   474 
   481 
   475     parser := 'foo' asParser trimmingToken, 'bar' asParser trimmingToken
   482     parser := 'foo' asParser trimmingToken , 'bar' asParser trimmingToken 
   476         compileWithConfiguration: configuration.
   483                     compileUsingCompiler:compiler.
   477     
   484     
   478     self assert: parser parse: 'foobar'.
   485     self assert: parser parse: 'foobar'.
   479     self assert: result first inputValue = 'foo'.
   486     self assert: result first inputValue = 'foo'.
   480     self assert: result second inputValue = 'bar'.	
   487     self assert: result second inputValue = 'bar'.	
   481     self assert: context invocationCount = 3.
   488     self assert: context invocationCount = 3.
   492     
   499     
   493 !
   500 !
   494 
   501 
   495 testTrimmingToken3
   502 testTrimmingToken3
   496 
   503 
   497     parser := ('foo' asParser trimmingToken / 'bar' asParser trimmingToken)
   504     parser := ('foo' asParser trimmingToken / 'bar' asParser trimmingToken) 
   498         compileWithConfiguration: configuration.
   505                     compileUsingCompiler:compiler.
   499     
   506     
   500     self assert: parser parse: 'foo'.
   507     self assert: parser parse: 'foo'.
   501     self assert: result inputValue = 'foo'.
   508     self assert: result inputValue = 'foo'.
   502     self assert: context invocationCount = 2.
   509     self assert: context invocationCount = 2.
   503 
   510 
   518     | identifier kw |
   525     | identifier kw |
   519     kw := 'false' asParser trimmingToken name: #kw.
   526     kw := 'false' asParser trimmingToken name: #kw.
   520     identifier := (kw not, (#letter asParser, #word asParser star)) trimmingToken name: #identifier.
   527     identifier := (kw not, (#letter asParser, #word asParser star)) trimmingToken name: #identifier.
   521     
   528     
   522     parser := identifier / kw.
   529     parser := identifier / kw.
   523     parser := parser compileWithConfiguration: configuration.
   530     parser := parser compileUsingCompiler:compiler.
   524     self assert: parser class methodDictionary size = 5.
   531     self assert: parser class methodDictionary size = 5.
   525 
   532 
   526     self assert: parser parse: 'foo'.
   533     self assert: parser parse: 'foo'.
   527     self assert: result inputValue = 'foo'.
   534     self assert: result inputValue = 'foo'.
   528 
   535 
   534     | identifier kw |
   541     | identifier kw |
   535     kw := 'false' asParser trimmingToken name: #kw.
   542     kw := 'false' asParser trimmingToken name: #kw.
   536     identifier := (kw not, (#letter asParser, #word asParser star)) trimmingToken name: #identifier.
   543     identifier := (kw not, (#letter asParser, #word asParser star)) trimmingToken name: #identifier.
   537     
   544     
   538     parser := identifier / kw.
   545     parser := identifier / kw.
   539     parser := parser compileWithConfiguration: configuration.
   546     parser := parser compileUsingCompiler:compiler.
   540     self assert: parser class methodDictionary size = 5.
   547     self assert: parser class methodDictionary size = 5.
   541 
   548 
   542     self assert: parser parse: 'foo'.
   549     self assert: parser parse: 'foo'.
   543     self assert: result inputValue = 'foo'.
   550     self assert: result inputValue = 'foo'.
   544 
   551 
   550     | identifier kw |
   557     | identifier kw |
   551     kw := ('false' asParser, #word asParser not) trimmingToken name: #kw.
   558     kw := ('false' asParser, #word asParser not) trimmingToken name: #kw.
   552     identifier := (kw not, (#letter asParser, #word asParser star)) trimmingToken name: #identifier.
   559     identifier := (kw not, (#letter asParser, #word asParser star)) trimmingToken name: #identifier.
   553     
   560     
   554     parser := identifier / kw.
   561     parser := identifier / kw.
   555     parser := parser compileWithConfiguration: configuration.
   562     parser := parser compileUsingCompiler:compiler.
   556     self assert: parser class methodDictionary size = 8.
   563     self assert: parser class methodDictionary size = 8.
   557     self assert: (parser class methodDictionary values anySatisfy: [ :m | m selector = #kw ]).
   564     self assert: (parser class methodDictionary values anySatisfy: [ :m | m selector = #kw ]).
   558     self assert: (parser class methodDictionary values anySatisfy: [ :m | m selector = #kw_fast ]).
   565     self assert: (parser class methodDictionary values anySatisfy: [ :m | m selector = #kw_fast ]).
   559 
   566 
   560     self assert: parser parse: 'foo'.
   567     self assert: parser parse: 'foo'.
   567 ! !
   574 ! !
   568 
   575 
   569 !PPCUniversalTest methodsFor:'tests - ids'!
   576 !PPCUniversalTest methodsFor:'tests - ids'!
   570 
   577 
   571 setUp
   578 setUp
   572     options := PPCCompilationOptions default
   579     options := (PPCCompilationOptions default)
   573         profile: true;
   580             profile:true;
   574         debug: true;
   581             debug:true;
   575         tokenize: false;
   582             tokenize:false;
   576         yourself.
   583             yourself.
   577         
   584     compiler := PPCCompiler new.
   578     configuration := PPCConfiguration new.
   585     compiler context options:options
   579     configuration context options: options
       
   580 
   586 
   581     "Modified: / 04-09-2015 / 16:21:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   587     "Modified: / 04-09-2015 / 16:21:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   582 ! !
   588 ! !
   583 
   589 
   584 !PPCUniversalTest class methodsFor:'documentation'!
   590 !PPCUniversalTest class methodsFor:'documentation'!