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