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