566
|
1 |
"{ Package: 'stx:goodies/petitparser/tests' }"
|
|
2 |
|
|
3 |
"{ NameSpace: Smalltalk }"
|
|
4 |
|
|
5 |
PPAbstractParserTest subclass:#PPMappingTest
|
|
6 |
instanceVariableNames:''
|
|
7 |
classVariableNames:''
|
|
8 |
poolDictionaries:''
|
|
9 |
category:'PetitTests-Tests'
|
|
10 |
!
|
|
11 |
|
|
12 |
|
|
13 |
!PPMappingTest methodsFor:'testing'!
|
|
14 |
|
|
15 |
testFoldLeft2
|
|
16 |
| parser |
|
|
17 |
parser := #any asParser star
|
|
18 |
foldLeft: [ :a :b | Array with: a with: b ].
|
|
19 |
|
|
20 |
self assert: parser parse: #(a) to: #a.
|
|
21 |
self assert: parser parse: #(a b) to: #(a b).
|
|
22 |
self assert: parser parse: #(a b c) to: #((a b) c).
|
|
23 |
self assert: parser parse: #(a b c d) to: #(((a b) c) d).
|
|
24 |
self assert: parser parse: #(a b c d e) to: #((((a b) c) d) e)
|
|
25 |
!
|
|
26 |
|
|
27 |
testFoldLeft3
|
|
28 |
| parser |
|
|
29 |
parser := #any asParser star
|
|
30 |
foldLeft: [ :a :b :c | Array with: a with: b with: c ].
|
|
31 |
|
|
32 |
self assert: parser parse: #(a) to: #a.
|
|
33 |
self assert: parser parse: #(a b c) to: #(a b c).
|
|
34 |
self assert: parser parse: #(a b c d e) to: #((a b c) d e)
|
|
35 |
!
|
|
36 |
|
|
37 |
testFoldRight2
|
|
38 |
| parser |
|
|
39 |
parser := #any asParser star
|
|
40 |
foldRight: [ :a :b | Array with: a with: b ].
|
|
41 |
|
|
42 |
self assert: parser parse: #(a) to: #a.
|
|
43 |
self assert: parser parse: #(a b) to: #(a b).
|
|
44 |
self assert: parser parse: #(a b c) to: #(a (b c)).
|
|
45 |
self assert: parser parse: #(a b c d) to: #(a (b (c d))).
|
|
46 |
self assert: parser parse: #(a b c d e) to: #(a (b (c (d e))))
|
|
47 |
!
|
|
48 |
|
|
49 |
testFoldRight3
|
|
50 |
| parser |
|
|
51 |
parser := #any asParser star
|
|
52 |
foldRight: [ :a :b :c | Array with: a with: b with: c ].
|
|
53 |
|
|
54 |
self assert: parser parse: #(a) to: #a.
|
|
55 |
self assert: parser parse: #(a b c) to: #(a b c).
|
|
56 |
self assert: parser parse: #(a b c d e) to: #(a b (c d e))
|
|
57 |
!
|
|
58 |
|
|
59 |
testMap1
|
|
60 |
| parser |
|
|
61 |
parser := #any asParser
|
|
62 |
map: [ :a | Array with: a ].
|
|
63 |
|
|
64 |
self assert: parser parse: #(a) to: #(a)
|
|
65 |
!
|
|
66 |
|
|
67 |
testMap2
|
|
68 |
| parser |
|
|
69 |
parser := (#any asParser , #any asParser)
|
|
70 |
map: [ :a :b | Array with: b with: a ].
|
|
71 |
|
|
72 |
self assert: parser parse: #(a b) to: #(b a)
|
|
73 |
!
|
|
74 |
|
|
75 |
testMap3
|
|
76 |
| parser |
|
|
77 |
parser := (#any asParser , #any asParser , #any asParser)
|
|
78 |
map: [ :a :b :c | Array with: c with: b with: a ].
|
|
79 |
|
|
80 |
self assert: parser parse: #(a b c) to: #(c b a)
|
|
81 |
! !
|
|
82 |
|
|
83 |
!PPMappingTest class methodsFor:'documentation'!
|
|
84 |
|
|
85 |
version
|
|
86 |
^ '$Header$'
|
|
87 |
!
|
|
88 |
|
|
89 |
version_CVS
|
|
90 |
^ '$Header$'
|
|
91 |
! !
|
|
92 |
|