4
|
1 |
"{ Package: 'stx:goodies/petitparser' }"
|
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
|
37
|
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.
|
|
77 |
|
|
78 |
beenHere := false.
|
|
79 |
result := self parserClass
|
|
80 |
parse: '\x.'
|
|
81 |
onError: [ :fail | beenHere := true. fail ].
|
|
82 |
self assert: beenHere.
|
|
83 |
"We don't use $ before character sign in ST/X"
|
|
84 |
self assert: (result message includesSubString: '(').
|
|
85 |
"/ self assert: (result message includesSubString: '$(').
|
|
86 |
self assert: (result message includesSubString: 'expected').
|
|
87 |
self assert: (result position = 0).
|
4
|
88 |
|
37
|
89 |
beenHere := false.
|
|
90 |
result := self parserClass
|
|
91 |
parse: '\x.'
|
|
92 |
onError: [ :msg :pos |
|
|
93 |
"We don't use $ before character sign in ST/X"
|
|
94 |
self assert: (msg includesSubString: '(').
|
0
|
95 |
"/ self assert: (msg includesSubString: '$(').
|
37
|
96 |
self assert: (msg includesSubString: 'expected').
|
|
97 |
self assert: (pos = 0).
|
|
98 |
beenHere := true ].
|
|
99 |
self assert: result.
|
|
100 |
self assert: beenHere
|
0
|
101 |
|
|
102 |
"Modified: / 19-12-2010 / 16:52:33 / Jan Kurs <kurs.jan@post.cz>"
|
|
103 |
!
|
|
104 |
|
|
105 |
testParseStartingAtOnError
|
|
106 |
| beenHere |
|
|
107 |
result := self parserClass
|
|
108 |
parse: 'x'
|
|
109 |
startingAt: #variable
|
|
110 |
onError: [ self fail ].
|
|
111 |
self assert: result = 'x'.
|
37
|
112 |
|
0
|
113 |
beenHere := false.
|
|
114 |
result := self parserClass
|
|
115 |
parse: '\'
|
|
116 |
startingAt: #variable
|
|
117 |
onError: [ beenHere := true ].
|
|
118 |
self assert: beenHere.
|
37
|
119 |
|
0
|
120 |
beenHere := false.
|
|
121 |
result := self parserClass
|
|
122 |
parse: '\'
|
|
123 |
startingAt: #variable
|
|
124 |
onError: [ :fail | beenHere := true. fail ].
|
|
125 |
self assert: beenHere.
|
|
126 |
self assert: result message = 'letter expected'.
|
|
127 |
self assert: result position = 0.
|
|
128 |
|
|
129 |
beenHere := false.
|
|
130 |
result := self parserClass
|
|
131 |
parse: '\'
|
|
132 |
startingAt: #variable
|
37
|
133 |
onError: [ :msg :pos |
|
0
|
134 |
self assert: msg = 'letter expected'.
|
|
135 |
self assert: pos = 0.
|
|
136 |
beenHere := true ].
|
|
137 |
self assert: beenHere
|
|
138 |
!
|
|
139 |
|
|
140 |
testProductionAt
|
|
141 |
self assert: (parser productionAt: #foo) isNil.
|
|
142 |
self assert: (parser productionAt: #foo ifAbsent: [ true ]).
|
37
|
143 |
|
0
|
144 |
self assert: (parser productionAt: #start) notNil.
|
|
145 |
self assert: (parser productionAt: #start ifAbsent: [ true ]) notNil.
|
37
|
146 |
|
0
|
147 |
self assert: (parser productionAt: #variable) notNil.
|
|
148 |
self assert: (parser productionAt: #variable ifAbsent: [ true ]) notNil
|
|
149 |
! !
|
|
150 |
|
|
151 |
!PPLambdaParserTest class methodsFor:'documentation'!
|
|
152 |
|
37
|
153 |
version
|
|
154 |
^ '$Header: /cvs/stx/stx/goodies/petitparser/PPLambdaParserTest.st,v 1.3 2012-05-04 22:05:16 vrany Exp $'
|
|
155 |
!
|
|
156 |
|
|
157 |
version_CVS
|
|
158 |
^ '$Header: /cvs/stx/stx/goodies/petitparser/PPLambdaParserTest.st,v 1.3 2012-05-04 22:05:16 vrany Exp $'
|
|
159 |
!
|
|
160 |
|
0
|
161 |
version_SVN
|
37
|
162 |
^ '§Id: PPLambdaParserTest.st 5 2010-12-19 17:38:27Z kursjan §'
|
0
|
163 |
! !
|