|
1 "{ Package: 'squeak:petitparser' }" |
|
2 |
|
3 PPAbstractParseTest 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 testNew |
|
30 self should: [ PPToken new ] raise: Error. |
|
31 |
|
32 ! |
|
33 |
|
34 testPrinting |
|
35 | result | |
|
36 result := PPToken on: 'var'. |
|
37 self assert: (result printString includesSubString: 'PPToken(var)') |
|
38 ! |
|
39 |
|
40 testSize |
|
41 | result | |
|
42 result := self |
|
43 parse: 'foo' |
|
44 using: self identifier. |
|
45 self assert: result size = 3 |
|
46 ! |
|
47 |
|
48 testStart |
|
49 | result | |
|
50 result := self |
|
51 parse: 'foo' |
|
52 using: self identifier. |
|
53 self assert: result start = 1 |
|
54 ! |
|
55 |
|
56 testStop |
|
57 | result | |
|
58 result := self |
|
59 parse: 'foo' |
|
60 using: self identifier. |
|
61 self assert: result stop = 3 |
|
62 ! |
|
63 |
|
64 testValue |
|
65 | input result | |
|
66 input := 'foo'. |
|
67 result := self |
|
68 parse: input |
|
69 using: self identifier. |
|
70 self assert: result value = input. |
|
71 self deny: result value == input |
|
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 | |
|
102 input := '1' , (String with: Character cr) , '12' , (String with: Character cr with: Character lf) , '123' , (String with: Character lf) , '1234'. |
|
103 parser := #any asParser token star. |
|
104 result := parser parse: input. |
|
105 result |
|
106 with: #(1 2 1 2 3 4 1 2 3 4 1 2 3 4) |
|
107 do: [ :token :line | self assert: token column = line ] |
|
108 ! |
|
109 |
|
110 testLine |
|
111 | input parser result | |
|
112 input := '1' , (String with: Character cr) , '12' , (String with: Character cr with: Character lf) , '123' , (String with: Character lf) , '1234'. |
|
113 parser := #any asParser token star. |
|
114 result := parser parse: input. |
|
115 result |
|
116 with: #(1 1 2 2 2 2 3 3 3 3 4 4 4 4) |
|
117 do: [ :token :line | self assert: token line = line ] |
|
118 ! ! |
|
119 |
|
120 !PPTokenTest methodsFor:'utilities'! |
|
121 |
|
122 parse: aString using: aParser |
|
123 ^ aParser parse: aString |
|
124 ! ! |
|
125 |
|
126 !PPTokenTest class methodsFor:'documentation'! |
|
127 |
|
128 version_SVN |
|
129 ^ '$Id: PPTokenTest.st,v 1.1 2011-08-18 18:56:17 cg Exp $' |
|
130 ! ! |