1 "{ Package: 'stx:goodies/petitparser' }" |
|
2 |
|
3 PPAbstractParserTest subclass:#PPTokenTest |
|
4 instanceVariableNames:'' |
|
5 classVariableNames:'' |
|
6 poolDictionaries:'' |
|
7 category:'PetitTests-Tests' |
|
8 ! |
|
9 |
|
10 |
|
11 !PPTokenTest methodsFor:'accessing'! |
|
12 |
|
13 identifier |
|
14 ^ #word asParser plus token |
|
15 ! ! |
|
16 |
|
17 !PPTokenTest methodsFor:'testing'! |
|
18 |
|
19 testCollection |
|
20 | input result | |
|
21 input := 'foo '. |
|
22 result := self |
|
23 parse: input |
|
24 using: self identifier. |
|
25 self assert: (result collection = input). |
|
26 self assert: (result collection == input) |
|
27 ! |
|
28 |
|
29 testInitialize |
|
30 PPToken initialize |
|
31 ! |
|
32 |
|
33 testNew |
|
34 self should: [ PPToken new ] raise: Error. |
|
35 |
|
36 ! |
|
37 |
|
38 testPrinting |
|
39 | result | |
|
40 result := PPToken on: 'var'. |
|
41 self assert: (result printString findString: 'PPToken[1,3]') > 0 |
|
42 ! |
|
43 |
|
44 testSize |
|
45 | result | |
|
46 result := self |
|
47 parse: 'foo' |
|
48 using: self identifier. |
|
49 self assert: result size = 3 |
|
50 ! |
|
51 |
|
52 testStart |
|
53 | result | |
|
54 result := self |
|
55 parse: 'foo' |
|
56 using: self identifier. |
|
57 self assert: result start = 1 |
|
58 ! |
|
59 |
|
60 testStop |
|
61 | result | |
|
62 result := self |
|
63 parse: 'foo' |
|
64 using: self identifier. |
|
65 self assert: result stop = 3 |
|
66 ! |
|
67 |
|
68 testValue |
|
69 | result | |
|
70 result := PPToken on: 'var'. |
|
71 self should: [ result value ] raise: Notification |
|
72 ! ! |
|
73 |
|
74 !PPTokenTest methodsFor:'testing-comparing'! |
|
75 |
|
76 testEquality |
|
77 | token1 token2 | |
|
78 token1 := self parse: 'foo' using: self identifier. |
|
79 token2 := self parse: 'foo' using: self identifier. |
|
80 self deny: token1 == token2. |
|
81 self assert: token1 = token2. |
|
82 self assert: token1 hash = token2 hash. |
|
83 ! ! |
|
84 |
|
85 !PPTokenTest methodsFor:'testing-copying'! |
|
86 |
|
87 testCopyFromTo |
|
88 | result other | |
|
89 result := PPToken on: 'abc'. |
|
90 other := result copyFrom: 2 to: 2. |
|
91 |
|
92 self assert: other size = 1. |
|
93 self assert: other start = 2. |
|
94 self assert: other stop = 2. |
|
95 self assert: other collection = result collection |
|
96 ! ! |
|
97 |
|
98 !PPTokenTest methodsFor:'testing-querying'! |
|
99 |
|
100 testColumn |
|
101 | input parser result cr | |
|
102 |
|
103 cr := Smalltalk isSmalltalkX |
|
104 ifTrue:[ Character return] |
|
105 ifFalse:[ Character cr ]. |
|
106 input := '1' , (String with:cr) , '12' , (String with: cr with: Character lf) , '123' , (String with: Character lf) , '1234'. |
|
107 parser := #any asParser token star. |
|
108 result := parser parse: input. |
|
109 result |
|
110 with: #(1 2 1 2 3 4 1 2 3 4 1 2 3 4) |
|
111 do: [ :token :line | self assert: token column = line ] |
|
112 ! |
|
113 |
|
114 testLine |
|
115 | input parser result cr| |
|
116 |
|
117 cr := Smalltalk isSmalltalkX |
|
118 ifTrue:[Character return] |
|
119 ifFalse:[Character cr]. |
|
120 input := '1' , (String with: cr) , '12' , (String with: cr with: Character lf) , '123' , (String with: Character lf) , '1234'. |
|
121 parser := #any asParser token star. |
|
122 result := parser parse: input. |
|
123 result |
|
124 with: #(1 1 2 2 2 2 3 3 3 3 4 4 4 4) |
|
125 do: [ :token :line | self assert: token line = line ] |
|
126 ! ! |
|
127 |
|
128 !PPTokenTest methodsFor:'testing-values'! |
|
129 |
|
130 testInputValue |
|
131 | input result | |
|
132 input := 'foo'. |
|
133 result := self |
|
134 parse: input |
|
135 using: self identifier. |
|
136 self assert: result inputValue = input. |
|
137 self deny: result inputValue == input |
|
138 ! |
|
139 |
|
140 testParsedValue |
|
141 | input result | |
|
142 input := 'foo'. |
|
143 result := self |
|
144 parse: input |
|
145 using: self identifier. |
|
146 self assert: result parsedValue = #($f $o $o) |
|
147 ! ! |
|
148 |
|
149 !PPTokenTest methodsFor:'utilities'! |
|
150 |
|
151 parse: aString using: aParser |
|
152 ^ aParser parse: aString |
|
153 ! ! |
|
154 |
|
155 !PPTokenTest class methodsFor:'documentation'! |
|
156 |
|
157 version |
|
158 ^ '$Header: /cvs/stx/stx/goodies/petitparser/PPTokenTest.st,v 1.5 2014-03-04 14:34:24 cg Exp $' |
|
159 ! |
|
160 |
|
161 version_CVS |
|
162 ^ '$Header: /cvs/stx/stx/goodies/petitparser/PPTokenTest.st,v 1.5 2014-03-04 14:34:24 cg Exp $' |
|
163 ! |
|
164 |
|
165 version_SVN |
|
166 ^ '$Id: PPTokenTest.st,v 1.5 2014-03-04 14:34:24 cg Exp $' |
|
167 ! ! |
|
168 |
|