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