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