author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Fri, 03 Oct 2014 01:59:10 +0100 | |
changeset 376 | a2656b27cace |
parent 375 | e2b2f08d054e |
child 377 | 6112a403a52d |
permissions | -rw-r--r-- |
376
a2656b27cace
Added monticelloName to package definition to ease export to .mcz
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
375
diff
changeset
|
1 |
"{ Package: 'stx:goodies/petitparser/tests' }" |
0 | 2 |
|
3 |
PPCompositeParserTest subclass:#PPLambdaParserTest |
|
4 |
instanceVariableNames:'' |
|
5 |
classVariableNames:'' |
|
6 |
poolDictionaries:'' |
|
7 |
category:'PetitTests-Tests' |
|
8 |
! |
|
9 |
||
10 |
||
11 |
!PPLambdaParserTest methodsFor:'accessing'! |
|
12 |
||
13 |
parserClass |
|
14 |
^ PPLambdaParser |
|
15 |
! ! |
|
16 |
||
17 |
!PPLambdaParserTest methodsFor:'testing'! |
|
18 |
||
19 |
testAbstraction |
|
20 |
self assert: '\x.y' is: #('x' 'y'). |
|
21 |
self assert: '\x.\y.z' is: #('x' ('y' 'z')) |
|
22 |
! |
|
23 |
||
24 |
testApplication |
|
25 |
self assert: '(x x)' is: #('x' 'x'). |
|
26 |
self assert: '(x y)' is: #('x' 'y'). |
|
27 |
self assert: '((x y) z)' is: #(('x' 'y') 'z'). |
|
28 |
self assert: '(x (y z))' is: #('x' ('y' 'z')) |
|
29 |
! |
|
30 |
||
31 |
testVariable |
|
32 |
self assert: 'x' is: 'x'. |
|
33 |
self assert: 'xy' is: 'xy'. |
|
34 |
self assert: 'x12' is: 'x12' |
|
35 |
! ! |
|
36 |
||
37 |
!PPLambdaParserTest methodsFor:'testing-curch'! |
|
38 |
||
39 |
testAnd |
|
40 |
self assert: self parserClass and = #('p' ('q' (('p' 'q') 'p'))) |
|
41 |
! |
|
42 |
||
43 |
testFalse |
|
44 |
self assert: self parserClass false = #('x' ('y' 'y')) |
|
45 |
! |
|
46 |
||
47 |
testIfThenElse |
|
48 |
self assert: self parserClass ifthenelse = #('p' 'p') |
|
49 |
! |
|
50 |
||
51 |
testNot |
|
52 |
self assert: self parserClass not = #('p' ('a' ('b' (('p' 'b') 'a')))) |
|
53 |
! |
|
54 |
||
55 |
testOr |
|
56 |
self assert: self parserClass or = #('p' ('q' (('p' 'p') 'q'))) |
|
57 |
! |
|
58 |
||
59 |
testTrue |
|
60 |
self assert: self parserClass true = #('x' ('y' 'x')) |
|
61 |
! ! |
|
62 |
||
63 |
!PPLambdaParserTest methodsFor:'testing-utilities'! |
|
64 |
||
65 |
testParseOnError |
|
189 | 66 |
| beenHere | |
67 |
result := self parserClass |
|
68 |
parse: '\x.y' |
|
69 |
onError: [ self fail ]. |
|
70 |
self assert: result = #('x' 'y'). |
|
71 |
||
72 |
beenHere := false. |
|
73 |
result := self parserClass |
|
74 |
parse: '\x.' |
|
75 |
onError: [ beenHere := true ]. |
|
76 |
self assert: beenHere. |
|
4 | 77 |
|
189 | 78 |
beenHere := false. |
79 |
result := self parserClass |
|
80 |
parse: '\x.' |
|
81 |
onError: [ :fail | beenHere := true. fail ]. |
|
82 |
self assert: beenHere. |
|
83 |
self assert: (result message findString: '$(') > 0. |
|
84 |
self assert: (result message findString: 'expected') > 0. |
|
85 |
self assert: (result position = 0). |
|
0 | 86 |
|
189 | 87 |
beenHere := false. |
88 |
result := self parserClass |
|
89 |
parse: '\x.' |
|
90 |
onError: [ :msg :pos | |
|
91 |
self assert: (msg findString: '$(') > 0. |
|
92 |
self assert: (msg findString: 'expected') > 0. |
|
93 |
self assert: (pos = 0). |
|
94 |
beenHere := true ]. |
|
95 |
self assert: result. |
|
96 |
self assert: beenHere |
|
0 | 97 |
! |
98 |
||
99 |
testParseStartingAtOnError |
|
100 |
| beenHere | |
|
101 |
result := self parserClass |
|
102 |
parse: 'x' |
|
103 |
startingAt: #variable |
|
104 |
onError: [ self fail ]. |
|
105 |
self assert: result = 'x'. |
|
37 | 106 |
|
0 | 107 |
beenHere := false. |
108 |
result := self parserClass |
|
109 |
parse: '\' |
|
110 |
startingAt: #variable |
|
111 |
onError: [ beenHere := true ]. |
|
112 |
self assert: beenHere. |
|
37 | 113 |
|
0 | 114 |
beenHere := false. |
115 |
result := self parserClass |
|
116 |
parse: '\' |
|
117 |
startingAt: #variable |
|
118 |
onError: [ :fail | beenHere := true. fail ]. |
|
119 |
self assert: beenHere. |
|
120 |
self assert: result message = 'letter expected'. |
|
121 |
self assert: result position = 0. |
|
122 |
||
123 |
beenHere := false. |
|
124 |
result := self parserClass |
|
125 |
parse: '\' |
|
126 |
startingAt: #variable |
|
37 | 127 |
onError: [ :msg :pos | |
0 | 128 |
self assert: msg = 'letter expected'. |
129 |
self assert: pos = 0. |
|
130 |
beenHere := true ]. |
|
131 |
self assert: beenHere |
|
132 |
! |
|
133 |
||
134 |
testProductionAt |
|
135 |
self assert: (parser productionAt: #foo) isNil. |
|
136 |
self assert: (parser productionAt: #foo ifAbsent: [ true ]). |
|
37 | 137 |
|
0 | 138 |
self assert: (parser productionAt: #start) notNil. |
139 |
self assert: (parser productionAt: #start ifAbsent: [ true ]) notNil. |
|
37 | 140 |
|
0 | 141 |
self assert: (parser productionAt: #variable) notNil. |
142 |
self assert: (parser productionAt: #variable ifAbsent: [ true ]) notNil |
|
143 |
! ! |
|
144 |
||
145 |
!PPLambdaParserTest class methodsFor:'documentation'! |
|
146 |
||
37 | 147 |
version |
189 | 148 |
^ '$Header: /cvs/stx/stx/goodies/petitparser/PPLambdaParserTest.st,v 1.4 2014-03-04 14:34:18 cg Exp $' |
37 | 149 |
! |
150 |
||
151 |
version_CVS |
|
189 | 152 |
^ '$Header: /cvs/stx/stx/goodies/petitparser/PPLambdaParserTest.st,v 1.4 2014-03-04 14:34:18 cg Exp $' |
37 | 153 |
! |
154 |
||
0 | 155 |
version_SVN |
189 | 156 |
^ '$Id: PPLambdaParserTest.st,v 1.4 2014-03-04 14:34:18 cg Exp $' |
0 | 157 |
! ! |
189 | 158 |