compiler/tests/PPCDistinctScannerTest.st
changeset 537 fb212e14d1f4
parent 534 a949c4fe44df
child 538 16e8536f5cfb
equal deleted inserted replaced
536:548996aca274 537:fb212e14d1f4
     1 "{ Package: 'stx:goodies/petitparser/compiler/tests' }"
     1 "{ Package: 'stx:goodies/petitparser/compiler/tests' }"
     2 
     2 
     3 "{ NameSpace: Smalltalk }"
     3 "{ NameSpace: Smalltalk }"
     4 
     4 
     5 TestCase subclass:#PPCDistinctScannerTest
     5 TestCase subclass:#PPCDistinctScannerTest
     6 	instanceVariableNames:'configuration scanner'
     6 	instanceVariableNames:'compiler scanner'
     7 	classVariableNames:''
     7 	classVariableNames:''
     8 	poolDictionaries:''
     8 	poolDictionaries:''
     9 	category:'PetitCompiler-Tests-Core-Tokenizing'
     9 	category:'PetitCompiler-Tests-Core-Tokenizing'
    10 !
    10 !
    11 
    11 
    51 overlappingToken
    51 overlappingToken
    52     ^ 'a' asParser token / 'a' asParser token
    52     ^ 'a' asParser token / 'a' asParser token
    53 !
    53 !
    54 
    54 
    55 setUp
    55 setUp
    56     configuration := PPCConfiguration tokenizing.
    56     compiler := PPCCompiler tokenizing.
    57 !
    57 !
    58 
    58 
    59 testConsumeToken
    59 testConsumeToken
    60     | parser |
    60     | parser |
    61     parser := self fooToken, self overlappingToken.
    61     parser := self fooToken, self overlappingToken.
    62     parser compileWithConfiguration: configuration.
    62     parser compileUsingCompiler:compiler.
    63     scanner := (Smalltalk at: configuration context options scannerName) new.
    63     scanner := (Smalltalk at: compiler context options scannerName) new.
    64 
    64 
    65     scanner stream: 'foobaz' asPetitStream.
    65     scanner stream: 'foobaz' asPetitStream.
    66     scanner perform: #'consume_foo'.
    66     scanner perform: #'consume_foo'.
    67     
    67     
    68     self assert: scanner position = 3.
    68     self assert: scanner position = 3.
    73 !
    73 !
    74 
    74 
    75 testConsumeToken2
    75 testConsumeToken2
    76     | parser |
    76     | parser |
    77     parser := self fooToken, self barToken.
    77     parser := self fooToken, self barToken.
    78     parser compileWithConfiguration: configuration.
    78     parser compileUsingCompiler:compiler.
    79     scanner := (Smalltalk at: configuration context options scannerName) new.
    79     scanner := (Smalltalk at: compiler context options scannerName) new.
    80 
    80 
    81     scanner stream: 'foobar' asPetitStream.
    81     scanner stream: 'foobar' asPetitStream.
    82     scanner perform: #'consume_foo'.
    82     scanner perform: #'consume_foo'.
    83     
    83     
    84     self assert: scanner position = 3.
    84     self assert: scanner position = 3.
    89 !
    89 !
    90 
    90 
    91 testScan
    91 testScan
    92     | parser |
    92     | parser |
    93     parser := self aToken.
    93     parser := self aToken.
    94     parser compileWithConfiguration: configuration.
    94     parser compileUsingCompiler:compiler.
    95     
    95     
    96     scanner := (Smalltalk at: configuration context options scannerName) new.
    96     scanner := (Smalltalk at: compiler context options scannerName) new.
    97 
    97 
    98     scanner stream: 'a' asPetitStream.
    98     scanner stream: 'a' asPetitStream.
    99     scanner perform: #'scan_token'.
    99     scanner perform: #'scan_token'.
   100     
   100     
   101     self assert: scanner position = 0.
   101     self assert: scanner position = 0.
   106 !
   106 !
   107 
   107 
   108 testScan2
   108 testScan2
   109     | parser |
   109     | parser |
   110     parser := self fooToken.
   110     parser := self fooToken.
   111     parser compileWithConfiguration: configuration.
   111     parser compileUsingCompiler:compiler.
   112     
   112     
   113     scanner := (Smalltalk at: configuration context options scannerName) new.
   113     scanner := (Smalltalk at: compiler context options scannerName) new.
   114 
   114 
   115     scanner stream: 'foo' asPetitStream.
   115     scanner stream: 'foo' asPetitStream.
   116     scanner perform: #'scan_foo'.
   116     scanner perform: #'scan_foo'.
   117     
   117     
   118     self assert: scanner position = 0.
   118     self assert: scanner position = 0.
   123 !
   123 !
   124 
   124 
   125 testScan3
   125 testScan3
   126     | parser |
   126     | parser |
   127     parser := self fooToken.
   127     parser := self fooToken.
   128     parser compileWithConfiguration: configuration.
   128     parser compileUsingCompiler:compiler.
   129     
   129     
   130     scanner := (Smalltalk at: configuration context options scannerName) new.
   130     scanner := (Smalltalk at: compiler context options scannerName) new.
   131 
   131 
   132     scanner stream: 'bar' asPetitStream.
   132     scanner stream: 'bar' asPetitStream.
   133     scanner perform: #'scan_foo'.
   133     scanner perform: #'scan_foo'.
   134     
   134     
   135     self assert: scanner position = 0.
   135     self assert: scanner position = 0.
   140 !
   140 !
   141 
   141 
   142 testScan4
   142 testScan4
   143     | parser |
   143     | parser |
   144     parser := self fooToken, self idToken.
   144     parser := self fooToken, self idToken.
   145     parser compileWithConfiguration: configuration.
   145     parser compileUsingCompiler:compiler.
   146     
   146     
   147     scanner := (Smalltalk at: configuration context options scannerName) new.
   147     scanner := (Smalltalk at: compiler context options scannerName) new.
   148 
   148 
   149     scanner stream: 'foothere' asPetitStream.
   149     scanner stream: 'foothere' asPetitStream.
   150     scanner perform: #'scan_foo'.
   150     scanner perform: #'scan_foo'.
   151     
   151     
   152     self assert: scanner position = 0.
   152     self assert: scanner position = 0.
   163 !
   163 !
   164 
   164 
   165 testSequence
   165 testSequence
   166     | parser result |
   166     | parser result |
   167     parser := self fooTrimmingToken, self idTrimmingToken.
   167     parser := self fooTrimmingToken, self idTrimmingToken.
   168     parser compileWithConfiguration: configuration.
   168     parser compileUsingCompiler:compiler.
   169     
   169     
   170     scanner := (Smalltalk at: configuration context options scannerName) new.
   170     scanner := (Smalltalk at: compiler context options scannerName) new.
   171 
   171 
   172     scanner stream: 'foo there ' asPetitStream.
   172     scanner stream: 'foo there ' asPetitStream.
   173     scanner perform: #'foo'.
   173     scanner perform: #'foo'.
   174     
   174     
   175     self assert: scanner position = 0.
   175     self assert: scanner position = 0.
   193 !
   193 !
   194 
   194 
   195 testToken
   195 testToken
   196     | parser |
   196     | parser |
   197     parser := self fooToken, self idTrimmingToken.
   197     parser := self fooToken, self idTrimmingToken.
   198     parser compileWithConfiguration: configuration.
   198     parser compileUsingCompiler:compiler.
   199     
   199     
   200     scanner := (Smalltalk at: configuration context options scannerName) new.
   200     scanner := (Smalltalk at: compiler context options scannerName) new.
   201 
   201 
   202     scanner stream: 'foo there' asPetitStream.
   202     scanner stream: 'foo there' asPetitStream.
   203     scanner perform: #'foo'.
   203     scanner perform: #'foo'.
   204     
   204     
   205     self assert: scanner position = 0.
   205     self assert: scanner position = 0.
   211 !
   211 !
   212 
   212 
   213 testTrimmingScan
   213 testTrimmingScan
   214     | parser |
   214     | parser |
   215     parser := self fooTrimmingToken, self idTrimmingToken.
   215     parser := self fooTrimmingToken, self idTrimmingToken.
   216     parser compileWithConfiguration: configuration.
   216     parser compileUsingCompiler:compiler.
   217     
   217     
   218     scanner := (Smalltalk at: configuration context options scannerName) new.
   218     scanner := (Smalltalk at: compiler context options scannerName) new.
   219 
   219 
   220     scanner stream: 'foo there' asPetitStream.
   220     scanner stream: 'foo there' asPetitStream.
   221     scanner perform: #'scan_foo'.
   221     scanner perform: #'scan_foo'.
   222     
   222     
   223     self assert: scanner position = 0.
   223     self assert: scanner position = 0.
   228 !
   228 !
   229 
   229 
   230 testTrimmingToken
   230 testTrimmingToken
   231     | parser result |
   231     | parser result |
   232     parser := self fooTrimmingToken, self idTrimmingToken.
   232     parser := self fooTrimmingToken, self idTrimmingToken.
   233     parser compileWithConfiguration: configuration.
   233     parser compileUsingCompiler:compiler.
   234     
   234     
   235     scanner := (Smalltalk at: configuration context options scannerName) new.
   235     scanner := (Smalltalk at: compiler context options scannerName) new.
   236 
   236 
   237     scanner stream: 'foo there' asPetitStream.
   237     scanner stream: 'foo there' asPetitStream.
   238     result := scanner perform: #'foo'.
   238     result := scanner perform: #'foo'.
   239     
   239     
   240     self assert: scanner position = 0.
   240     self assert: scanner position = 0.