compiler/tests/PPLL1ExpressionGrammarTest.st
changeset 464 f6d77fee9811
parent 459 4751c407bb40
child 465 f729f6cd3c76
child 502 1e45d3c96ec5
equal deleted inserted replaced
459:4751c407bb40 464:f6d77fee9811
     1 "{ Package: 'stx:goodies/petitparser/compiler/tests' }"
       
     2 
       
     3 "{ NameSpace: Smalltalk }"
       
     4 
       
     5 PPCompositeParserTest subclass:#PPLL1ExpressionGrammarTest
       
     6 	instanceVariableNames:''
       
     7 	classVariableNames:''
       
     8 	poolDictionaries:''
       
     9 	category:'PetitCompiler-Tests-ExpressionGrammar'
       
    10 !
       
    11 
       
    12 !PPLL1ExpressionGrammarTest methodsFor:'as yet unclassified'!
       
    13 
       
    14 parserClass
       
    15     ^ PPLL1ExpressionGrammar
       
    16 !
       
    17 
       
    18 testAdd
       
    19     result := self parse: '1+2' rule: #add.
       
    20     self assert: result isArray.
       
    21     self assert: result first = 1.
       
    22     self assert: result second inputValue = '+'.
       
    23     self assert: result third = 2.
       
    24 !
       
    25 
       
    26 testMul
       
    27     result := self parse: '1 * 2' rule: #mul.
       
    28     self assert: result isArray.
       
    29     self assert: result first = 1.
       
    30     self assert: result second inputValue = '*'.
       
    31     self assert: result third = 2.
       
    32 !
       
    33 
       
    34 testNumber
       
    35     result := self parse: '1' rule: #number.
       
    36     self assert: result = 1.
       
    37 !
       
    38 
       
    39 testParens
       
    40     result := self parse: '(1)' rule: #parens.
       
    41     self assert: result size = 3.
       
    42     self assert: result first inputValue = '('.
       
    43     self assert: result second = 1.
       
    44     self assert: result third inputValue = ')'.
       
    45     
       
    46 !
       
    47 
       
    48 testPrim
       
    49     result := self parse: '1' rule: #prim.
       
    50     self assert: result = 1.
       
    51 !
       
    52 
       
    53 testPrim2
       
    54     result := self parse: '(1)' rule: #prim.
       
    55     self assert: result size = 3.
       
    56     self assert: result second = 1.
       
    57 !
       
    58 
       
    59 testProd
       
    60     result := self parse: '1' rule: #prod.
       
    61     self assert: result = 1.
       
    62 !
       
    63 
       
    64 testTerm
       
    65     result := self parse: '1' rule: #term.
       
    66     self assert: result = 1.
       
    67     
       
    68 !
       
    69 
       
    70 testTerm11
       
    71     result := self parse: '1 + 2' rule: #term.
       
    72     self assert: result size = 3.
       
    73     self assert: result first = 1.
       
    74     self assert: result second inputValue = '+'.
       
    75     self assert: result third = 2.
       
    76     
       
    77 !
       
    78 
       
    79 testTerm12
       
    80     result := self parse: '1 + 2 * 3' rule: #term.
       
    81     self assert: result size = 3.
       
    82     self assert: result second inputValue = '+'.
       
    83     self assert: result first = 1.
       
    84     self assert: result third isArray.
       
    85     self assert: result third first = 2.
       
    86     self assert: result third second inputValue = '*'.
       
    87     self assert: result third third = 3.
       
    88 !
       
    89 
       
    90 testTerm13
       
    91     result := self parse: '1 * 2 + 3' rule: #term.
       
    92     self assert: result size = 3.
       
    93     self assert: result first isArray.
       
    94     self assert: result first first = 1.
       
    95     self assert: result first second inputValue = '*'.
       
    96     self assert: result first third = 2.	
       
    97     self assert: result second inputValue = '+'.
       
    98     self assert: result third = 3.
       
    99 ! !
       
   100