compiler/tests/extras/PPTokenizedLL1ExpressionGrammarTest.st
changeset 510 869853decf31
parent 509 fd22630c7e62
child 511 527038bc8edf
equal deleted inserted replaced
509:fd22630c7e62 510:869853decf31
     1 "{ Package: 'stx:goodies/petitparser/compiler/tests/extras' }"
       
     2 
       
     3 "{ NameSpace: Smalltalk }"
       
     4 
       
     5 PPCompositeParserTest subclass:#PPTokenizedLL1ExpressionGrammarTest
       
     6 	instanceVariableNames:'context'
       
     7 	classVariableNames:''
       
     8 	poolDictionaries:''
       
     9 	category:'PetitCompiler-Extras-Tests-Expressions'
       
    10 !
       
    11 
       
    12 !PPTokenizedLL1ExpressionGrammarTest class methodsFor:'as yet unclassified'!
       
    13 
       
    14 resources
       
    15     ^ (OrderedCollection with: PPTokenizedLL1ExpressionGrammarResource)
       
    16         addAll: super resources;
       
    17         yourself
       
    18 ! !
       
    19 
       
    20 !PPTokenizedLL1ExpressionGrammarTest methodsFor:'as yet unclassified'!
       
    21 
       
    22 compilerArguments
       
    23     ^ PPCArguments default
       
    24         profile: true;
       
    25         ll: true;
       
    26         yourself
       
    27 !
       
    28 
       
    29 context
       
    30     ^ context := PPCProfilingContext new
       
    31 !
       
    32 
       
    33 parserClass
       
    34     ^ Smalltalk at: #PPTokenizedLL1ExpressionGrammar
       
    35 !
       
    36 
       
    37 parserInstanceFor: aSymbol
       
    38     ^ (Smalltalk at: #PPTokenizedLL1ExpressionGrammar) new startSymbol: aSymbol
       
    39 !
       
    40 
       
    41 testAdd
       
    42     result := self parse: '1+2' rule: #term.
       
    43     self assert: result isArray.
       
    44     self assert: result first = 1.
       
    45     self assert: result second inputValue = '+'.
       
    46     self assert: result third = 2.
       
    47 !
       
    48 
       
    49 testMul
       
    50     result := self parse: '1 * 2' rule: #mul.
       
    51     self assert: result isArray.
       
    52     self assert: result first = 1.
       
    53     self assert: result second inputValue = '*'.
       
    54     self assert: result third = 2.
       
    55 !
       
    56 
       
    57 testNumber
       
    58     result := self parse: '1' rule: #number.
       
    59     self assert: result = 1.
       
    60 !
       
    61 
       
    62 testParens
       
    63     result := self parse: '(1)' rule: #parens.
       
    64     self assert: result size = 3.
       
    65     self assert: result first inputValue = '('.
       
    66     self assert: result second = 1.
       
    67     self assert: result third inputValue = ')'.
       
    68     
       
    69 !
       
    70 
       
    71 testPrim
       
    72     result := self parse: '1' rule: #prim.
       
    73     self assert: result = 1.
       
    74 !
       
    75 
       
    76 testPrim2
       
    77     result := self parse: '(1)' rule: #prim.
       
    78     self assert: result size = 3.
       
    79     self assert: result second = 1.
       
    80 !
       
    81 
       
    82 testProd
       
    83     result := self parse: '1' rule: #prod.
       
    84     self assert: result = 1.
       
    85 !
       
    86 
       
    87 testTerm01
       
    88     result := self parse: '1' rule: #term.
       
    89     self assert: result = 1.
       
    90 
       
    91     self assert: context lwRememberCount = 2.	
       
    92     self assert: context lwRestoreCount = 0.
       
    93 !
       
    94 
       
    95 testTerm02
       
    96     result := self parse: '1+2' rule: #term.
       
    97     self assert: result size = 3.
       
    98     
       
    99     self assert: context lwRestoreCount = 0.
       
   100 !
       
   101 
       
   102 testTerm03
       
   103     result := self parse: '1*2+3*4' rule: #term.
       
   104     self assert: result size = 3.
       
   105     
       
   106 
       
   107     self assert: context lwRestoreCount = 0.
       
   108 !
       
   109 
       
   110 testTerm11
       
   111     result := self parse: '1 + 2' rule: #term.
       
   112     self assert: result size = 3.
       
   113     self assert: result first = 1.
       
   114     self assert: result second inputValue = '+'.
       
   115     self assert: result third = 2.
       
   116     
       
   117 !
       
   118 
       
   119 testTerm12
       
   120     result := self parse: '1 + 2 * 3' rule: #term.
       
   121     self assert: result size = 3.
       
   122     self assert: result second inputValue = '+'.
       
   123     self assert: result first = 1.
       
   124     self assert: result third isArray.
       
   125     self assert: result third first = 2.
       
   126     self assert: result third second inputValue = '*'.
       
   127     self assert: result third third = 3.	
       
   128 !
       
   129 
       
   130 testTerm13
       
   131     result := self parse: '1 * 2 + 3' rule: #term.
       
   132     self assert: result size = 3.
       
   133     self assert: result first isArray.
       
   134     self assert: result first first = 1.
       
   135     self assert: result first second inputValue = '*'.
       
   136     self assert: result first third = 2.	
       
   137     self assert: result second inputValue = '+'.
       
   138     self assert: result third = 3.
       
   139 ! !
       
   140