compiler/tests/PPCDistinctScannerTest.st
changeset 534 a949c4fe44df
parent 529 439c4057517f
child 537 fb212e14d1f4
equal deleted inserted replaced
533:666372dbe307 534:a949c4fe44df
     7 	classVariableNames:''
     7 	classVariableNames:''
     8 	poolDictionaries:''
     8 	poolDictionaries:''
     9 	category:'PetitCompiler-Tests-Core-Tokenizing'
     9 	category:'PetitCompiler-Tests-Core-Tokenizing'
    10 !
    10 !
    11 
    11 
       
    12 
    12 !PPCDistinctScannerTest methodsFor:'as yet unclassified'!
    13 !PPCDistinctScannerTest methodsFor:'as yet unclassified'!
    13 
    14 
    14 aToken
    15 aToken
    15     ^ 'a' asParser token 
    16     ^ 'a' asParser token 
    16         name: #token;
    17         name: #token;
    57 
    58 
    58 testConsumeToken
    59 testConsumeToken
    59     | parser |
    60     | parser |
    60     parser := self fooToken, self overlappingToken.
    61     parser := self fooToken, self overlappingToken.
    61     parser compileWithConfiguration: configuration.
    62     parser compileWithConfiguration: configuration.
    62     scanner := (Smalltalk at: configuration options scannerName) new.
    63     scanner := (Smalltalk at: configuration context options scannerName) new.
    63 
    64 
    64     scanner stream: 'foobaz' asPetitStream.
    65     scanner stream: 'foobaz' asPetitStream.
    65     scanner perform: #'consume_foo'.
    66     scanner perform: #'consume_foo'.
    66     
    67     
    67     self assert: scanner position = 3.
    68     self assert: scanner position = 3.
    68     self assert: scanner resultPosition = 3.
    69     self assert: scanner resultPosition = 3.
    69     self assert: scanner result isNil.
    70     self assert: scanner result isNil.
       
    71 
       
    72     "Modified: / 28-08-2015 / 14:15:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    70 !
    73 !
    71 
    74 
    72 testConsumeToken2
    75 testConsumeToken2
    73     | parser |
    76     | parser |
    74     parser := self fooToken, self barToken.
    77     parser := self fooToken, self barToken.
    75     parser compileWithConfiguration: configuration.
    78     parser compileWithConfiguration: configuration.
    76     scanner := (Smalltalk at: configuration options scannerName) new.
    79     scanner := (Smalltalk at: configuration context options scannerName) new.
    77 
    80 
    78     scanner stream: 'foobar' asPetitStream.
    81     scanner stream: 'foobar' asPetitStream.
    79     scanner perform: #'consume_foo'.
    82     scanner perform: #'consume_foo'.
    80     
    83     
    81     self assert: scanner position = 3.
    84     self assert: scanner position = 3.
    82     self assert: scanner resultPosition = 6.
    85     self assert: scanner resultPosition = 6.
    83     self assert: scanner result = #bar.
    86     self assert: scanner result = #bar.
       
    87 
       
    88     "Modified: / 28-08-2015 / 14:16:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    84 !
    89 !
    85 
    90 
    86 testScan
    91 testScan
    87     | parser |
    92     | parser |
    88     parser := self aToken.
    93     parser := self aToken.
    89     parser compileWithConfiguration: configuration.
    94     parser compileWithConfiguration: configuration.
    90     
    95     
    91     scanner := (Smalltalk at: configuration options scannerName) new.
    96     scanner := (Smalltalk at: configuration context options scannerName) new.
    92 
    97 
    93     scanner stream: 'a' asPetitStream.
    98     scanner stream: 'a' asPetitStream.
    94     scanner perform: #'scan_token'.
    99     scanner perform: #'scan_token'.
    95     
   100     
    96     self assert: scanner position = 0.
   101     self assert: scanner position = 0.
    97     self assert: scanner resultPosition = 1.
   102     self assert: scanner resultPosition = 1.
    98     self assert: scanner result = #token.
   103     self assert: scanner result = #token.
       
   104 
       
   105     "Modified: / 28-08-2015 / 14:16:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    99 !
   106 !
   100 
   107 
   101 testScan2
   108 testScan2
   102     | parser |
   109     | parser |
   103     parser := self fooToken.
   110     parser := self fooToken.
   104     parser compileWithConfiguration: configuration.
   111     parser compileWithConfiguration: configuration.
   105     
   112     
   106     scanner := (Smalltalk at: configuration options scannerName) new.
   113     scanner := (Smalltalk at: configuration context options scannerName) new.
   107 
   114 
   108     scanner stream: 'foo' asPetitStream.
   115     scanner stream: 'foo' asPetitStream.
   109     scanner perform: #'scan_foo'.
   116     scanner perform: #'scan_foo'.
   110     
   117     
   111     self assert: scanner position = 0.
   118     self assert: scanner position = 0.
   112     self assert: scanner resultPosition = 3.
   119     self assert: scanner resultPosition = 3.
   113     self assert: scanner result = #foo.
   120     self assert: scanner result = #foo.
       
   121 
       
   122     "Modified: / 28-08-2015 / 14:16:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   114 !
   123 !
   115 
   124 
   116 testScan3
   125 testScan3
   117     | parser |
   126     | parser |
   118     parser := self fooToken.
   127     parser := self fooToken.
   119     parser compileWithConfiguration: configuration.
   128     parser compileWithConfiguration: configuration.
   120     
   129     
   121     scanner := (Smalltalk at: configuration options scannerName) new.
   130     scanner := (Smalltalk at: configuration context options scannerName) new.
   122 
   131 
   123     scanner stream: 'bar' asPetitStream.
   132     scanner stream: 'bar' asPetitStream.
   124     scanner perform: #'scan_foo'.
   133     scanner perform: #'scan_foo'.
   125     
   134     
   126     self assert: scanner position = 0.
   135     self assert: scanner position = 0.
   127     self assert: scanner resultPosition = 0.
   136     self assert: scanner resultPosition = 0.
   128     self assert: scanner result isNil.
   137     self assert: scanner result isNil.
       
   138 
       
   139     "Modified: / 28-08-2015 / 14:16:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   129 !
   140 !
   130 
   141 
   131 testScan4
   142 testScan4
   132     | parser |
   143     | parser |
   133     parser := self fooToken, self idToken.
   144     parser := self fooToken, self idToken.
   134     parser compileWithConfiguration: configuration.
   145     parser compileWithConfiguration: configuration.
   135     
   146     
   136     scanner := (Smalltalk at: configuration options scannerName) new.
   147     scanner := (Smalltalk at: configuration context options scannerName) new.
   137 
   148 
   138     scanner stream: 'foothere' asPetitStream.
   149     scanner stream: 'foothere' asPetitStream.
   139     scanner perform: #'scan_foo'.
   150     scanner perform: #'scan_foo'.
   140     
   151     
   141     self assert: scanner position = 0.
   152     self assert: scanner position = 0.
   145     scanner perform: #'consume_foo'.
   156     scanner perform: #'consume_foo'.
   146 
   157 
   147     self assert: scanner position = 3.
   158     self assert: scanner position = 3.
   148     self assert: scanner resultPosition = 8.
   159     self assert: scanner resultPosition = 8.
   149     self assert: scanner result = #id.
   160     self assert: scanner result = #id.
       
   161 
       
   162     "Modified: / 28-08-2015 / 14:16:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   150 !
   163 !
   151 
   164 
   152 testSequence
   165 testSequence
   153     | parser result |
   166     | parser result |
   154     parser := self fooTrimmingToken, self idTrimmingToken.
   167     parser := self fooTrimmingToken, self idTrimmingToken.
   155     parser compileWithConfiguration: configuration.
   168     parser compileWithConfiguration: configuration.
   156     
   169     
   157     scanner := (Smalltalk at: configuration options scannerName) new.
   170     scanner := (Smalltalk at: configuration context options scannerName) new.
   158 
   171 
   159     scanner stream: 'foo there ' asPetitStream.
   172     scanner stream: 'foo there ' asPetitStream.
   160     scanner perform: #'foo'.
   173     scanner perform: #'foo'.
   161     
   174     
   162     self assert: scanner position = 0.
   175     self assert: scanner position = 0.
   163     self assert: scanner resultPosition = 3.
   176     self assert: scanner resultPosition = 3.
   164     self assert: scanner stream position = 4.
   177     self assert: scanner stream position = 4.
   165     self assert: scanner result = #foo.	
   178     self assert: scanner result = #foo.         
   166     
   179     
   167     result := scanner perform: #'consume_foo'.
   180     result := scanner perform: #'consume_foo'.
   168 
   181 
   169     self assert: scanner position = 4.
   182     self assert: scanner position = 4.
   170     self assert: scanner resultPosition = 9.
   183     self assert: scanner resultPosition = 9.
   173     
   186     
   174     self assert: (result isKindOf: PPToken).
   187     self assert: (result isKindOf: PPToken).
   175     self assert: result start = 1.
   188     self assert: result start = 1.
   176     self assert: result stop = 3.
   189     self assert: result stop = 3.
   177     self assert: result inputValue = 'foo'.
   190     self assert: result inputValue = 'foo'.
       
   191 
       
   192     "Modified: / 28-08-2015 / 14:16:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   178 !
   193 !
   179 
   194 
   180 testToken
   195 testToken
   181     | parser |
   196     | parser |
   182     parser := self fooToken, self idTrimmingToken.
   197     parser := self fooToken, self idTrimmingToken.
   183     parser compileWithConfiguration: configuration.
   198     parser compileWithConfiguration: configuration.
   184     
   199     
   185     scanner := (Smalltalk at: configuration options scannerName) new.
   200     scanner := (Smalltalk at: configuration context options scannerName) new.
   186 
   201 
   187     scanner stream: 'foo there' asPetitStream.
   202     scanner stream: 'foo there' asPetitStream.
   188     scanner perform: #'foo'.
   203     scanner perform: #'foo'.
   189     
   204     
   190     self assert: scanner position = 0.
   205     self assert: scanner position = 0.
   191     self assert: scanner resultPosition = 3.
   206     self assert: scanner resultPosition = 3.
   192     self assert: scanner stream position = 3.
   207     self assert: scanner stream position = 3.
   193     self assert: scanner result = #foo.		
   208     self assert: scanner result = #foo.
       
   209 
       
   210     "Modified: / 28-08-2015 / 14:16:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   194 !
   211 !
   195 
   212 
   196 testTrimmingScan
   213 testTrimmingScan
   197     | parser |
   214     | parser |
   198     parser := self fooTrimmingToken, self idTrimmingToken.
   215     parser := self fooTrimmingToken, self idTrimmingToken.
   199     parser compileWithConfiguration: configuration.
   216     parser compileWithConfiguration: configuration.
   200     
   217     
   201     scanner := (Smalltalk at: configuration options scannerName) new.
   218     scanner := (Smalltalk at: configuration context options scannerName) new.
   202 
   219 
   203     scanner stream: 'foo there' asPetitStream.
   220     scanner stream: 'foo there' asPetitStream.
   204     scanner perform: #'scan_foo'.
   221     scanner perform: #'scan_foo'.
   205     
   222     
   206     self assert: scanner position = 0.
   223     self assert: scanner position = 0.
   207     self assert: scanner resultPosition = 3.
   224     self assert: scanner resultPosition = 3.
   208     self assert: scanner result = #foo.	
   225     self assert: scanner result = #foo.
       
   226 
       
   227     "Modified: / 28-08-2015 / 14:16:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   209 !
   228 !
   210 
   229 
   211 testTrimmingToken
   230 testTrimmingToken
   212     | parser result |
   231     | parser result |
   213     parser := self fooTrimmingToken, self idTrimmingToken.
   232     parser := self fooTrimmingToken, self idTrimmingToken.
   214     parser compileWithConfiguration: configuration.
   233     parser compileWithConfiguration: configuration.
   215     
   234     
   216     scanner := (Smalltalk at: configuration options scannerName) new.
   235     scanner := (Smalltalk at: configuration context options scannerName) new.
   217 
   236 
   218     scanner stream: 'foo there' asPetitStream.
   237     scanner stream: 'foo there' asPetitStream.
   219     result := scanner perform: #'foo'.
   238     result := scanner perform: #'foo'.
   220     
   239     
   221     self assert: scanner position = 0.
   240     self assert: scanner position = 0.
   222     self assert: scanner resultPosition = 3.
   241     self assert: scanner resultPosition = 3.
   223     self assert: scanner stream position = 4.
   242     self assert: scanner stream position = 4.
   224     self assert: scanner result = #foo.		
   243     self assert: scanner result = #foo.                 
   225         
   244         
   226     self assert: result.
   245     self assert: result.
       
   246 
       
   247     "Modified: / 28-08-2015 / 14:16:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   227 ! !
   248 ! !
   228 
   249 
       
   250 !PPCDistinctScannerTest class methodsFor:'documentation'!
       
   251 
       
   252 version_HG
       
   253 
       
   254     ^ '$Changeset: <not expanded> $'
       
   255 ! !
       
   256