author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Sun, 26 Oct 2014 01:28:07 +0000 | |
changeset 392 | 9b297f0d949c |
parent 380 | 8fe3cb4e607f |
child 405 | 0470a5e6e712 |
permissions | -rw-r--r-- |
376
a2656b27cace
Added monticelloName to package definition to ease export to .mcz
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
375
diff
changeset
|
1 |
"{ Package: 'stx:goodies/petitparser/tests' }" |
0 | 2 |
|
194 | 3 |
PPAbstractParserTest subclass:#PPTokenTest |
0 | 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 '. |
|
377
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
376
diff
changeset
|
22 |
result := self parse: input using: self identifier. |
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
376
diff
changeset
|
23 |
self assert: result collection equals: input. |
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
376
diff
changeset
|
24 |
self assert: result collection == input |
0 | 25 |
! |
26 |
||
194 | 27 |
testInitialize |
28 |
PPToken initialize |
|
29 |
! |
|
30 |
||
0 | 31 |
testNew |
32 |
self should: [ PPToken new ] raise: Error. |
|
38 | 33 |
|
0 | 34 |
! |
35 |
||
36 |
testPrinting |
|
37 |
| result | |
|
38 |
result := PPToken on: 'var'. |
|
377
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
376
diff
changeset
|
39 |
self assert: (result printString includesSubstring: 'PPToken[1,3]') |
0 | 40 |
! |
41 |
||
42 |
testSize |
|
43 |
| result | |
|
377
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
376
diff
changeset
|
44 |
result := self parse: 'foo' using: self identifier. |
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
376
diff
changeset
|
45 |
self assert: result size equals: 3 |
0 | 46 |
! |
47 |
||
48 |
testStart |
|
49 |
| result | |
|
377
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
376
diff
changeset
|
50 |
result := self parse: 'foo' using: self identifier. |
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
376
diff
changeset
|
51 |
self assert: result start equals: 1 |
0 | 52 |
! |
53 |
||
54 |
testStop |
|
55 |
| result | |
|
377
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
376
diff
changeset
|
56 |
result := self parse: 'foo' using: self identifier. |
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
376
diff
changeset
|
57 |
self assert: result stop equals: 3 |
0 | 58 |
! |
59 |
||
60 |
testValue |
|
194 | 61 |
| result | |
62 |
result := PPToken on: 'var'. |
|
63 |
self should: [ result value ] raise: Notification |
|
0 | 64 |
! ! |
65 |
||
66 |
!PPTokenTest methodsFor:'testing-comparing'! |
|
67 |
||
68 |
testEquality |
|
69 |
| token1 token2 | |
|
377
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
376
diff
changeset
|
70 |
token1 := self parse: 'foo' using: self identifier. |
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
376
diff
changeset
|
71 |
token2 := self parse: 'foo' using: self identifier. |
0 | 72 |
self deny: token1 == token2. |
377
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
376
diff
changeset
|
73 |
self assert: token1 equals: token2. |
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
376
diff
changeset
|
74 |
self assert: token1 hash equals: token2 hash |
0 | 75 |
! ! |
76 |
||
77 |
!PPTokenTest methodsFor:'testing-copying'! |
|
78 |
||
79 |
testCopyFromTo |
|
80 |
| result other | |
|
81 |
result := PPToken on: 'abc'. |
|
82 |
other := result copyFrom: 2 to: 2. |
|
377
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
376
diff
changeset
|
83 |
self assert: other size equals: 1. |
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
376
diff
changeset
|
84 |
self assert: other start equals: 2. |
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
376
diff
changeset
|
85 |
self assert: other stop equals: 2. |
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
376
diff
changeset
|
86 |
self assert: other collection equals: result collection |
0 | 87 |
! ! |
88 |
||
89 |
!PPTokenTest methodsFor:'testing-querying'! |
|
90 |
||
91 |
testColumn |
|
380
8fe3cb4e607f
Remove Pharoisms to make code more portable and running on Smalltalk/X
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
377
diff
changeset
|
92 |
| input parser result | |
8fe3cb4e607f
Remove Pharoisms to make code more portable and running on Smalltalk/X
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
377
diff
changeset
|
93 |
input := '1' , (String with: (Character codePoint: 13)) , '12' , (String with: (Character codePoint: 13) with: (Character codePoint: 10)) , '123' |
8fe3cb4e607f
Remove Pharoisms to make code more portable and running on Smalltalk/X
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
377
diff
changeset
|
94 |
, (String with: (Character codePoint: 10)) , '1234'. |
8fe3cb4e607f
Remove Pharoisms to make code more portable and running on Smalltalk/X
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
377
diff
changeset
|
95 |
parser := #any asParser token star. |
8fe3cb4e607f
Remove Pharoisms to make code more portable and running on Smalltalk/X
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
377
diff
changeset
|
96 |
result := parser parse: input. |
8fe3cb4e607f
Remove Pharoisms to make code more portable and running on Smalltalk/X
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
377
diff
changeset
|
97 |
result with: #(1 2 1 2 3 4 1 2 3 4 1 2 3 4) do: [ :token :line | self assert: token column equals: line ] |
8fe3cb4e607f
Remove Pharoisms to make code more portable and running on Smalltalk/X
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
377
diff
changeset
|
98 |
|
8fe3cb4e607f
Remove Pharoisms to make code more portable and running on Smalltalk/X
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
377
diff
changeset
|
99 |
"Modified: / 03-10-2014 / 23:53:40 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
0 | 100 |
! |
101 |
||
102 |
testLine |
|
380
8fe3cb4e607f
Remove Pharoisms to make code more portable and running on Smalltalk/X
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
377
diff
changeset
|
103 |
| input parser result | |
8fe3cb4e607f
Remove Pharoisms to make code more portable and running on Smalltalk/X
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
377
diff
changeset
|
104 |
input := '1' , (String with: (Character codePoint: 13)) , '12' , (String with:(Character codePoint: 13) with: (Character codePoint: 10)) , '123' |
8fe3cb4e607f
Remove Pharoisms to make code more portable and running on Smalltalk/X
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
377
diff
changeset
|
105 |
, (String with: (Character codePoint: 10)) , '1234'. |
8fe3cb4e607f
Remove Pharoisms to make code more portable and running on Smalltalk/X
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
377
diff
changeset
|
106 |
parser := #any asParser token star. |
8fe3cb4e607f
Remove Pharoisms to make code more portable and running on Smalltalk/X
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
377
diff
changeset
|
107 |
result := parser parse: input. |
8fe3cb4e607f
Remove Pharoisms to make code more portable and running on Smalltalk/X
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
377
diff
changeset
|
108 |
result with: #(1 1 2 2 2 2 3 3 3 3 4 4 4 4) do: [ :token :line | self assert: token line equals: line ] |
8fe3cb4e607f
Remove Pharoisms to make code more portable and running on Smalltalk/X
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
377
diff
changeset
|
109 |
|
8fe3cb4e607f
Remove Pharoisms to make code more portable and running on Smalltalk/X
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
377
diff
changeset
|
110 |
"Modified: / 03-10-2014 / 23:54:22 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
0 | 111 |
! ! |
112 |
||
194 | 113 |
!PPTokenTest methodsFor:'testing-values'! |
114 |
||
115 |
testInputValue |
|
116 |
| input result | |
|
117 |
input := 'foo'. |
|
377
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
376
diff
changeset
|
118 |
result := self parse: input using: self identifier. |
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
376
diff
changeset
|
119 |
self assert: result inputValue equals: input. |
194 | 120 |
self deny: result inputValue == input |
121 |
! |
|
122 |
||
123 |
testParsedValue |
|
124 |
| input result | |
|
125 |
input := 'foo'. |
|
377
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
376
diff
changeset
|
126 |
result := self parse: input using: self identifier. |
6112a403a52d
Updated to latest version from Moose repository.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
376
diff
changeset
|
127 |
self assert: result parsedValue equals: #($f $o $o) |
194 | 128 |
! ! |
129 |
||
0 | 130 |
!PPTokenTest methodsFor:'utilities'! |
131 |
||
132 |
parse: aString using: aParser |
|
133 |
^ aParser parse: aString |
|
134 |
! ! |
|
135 |
||
136 |
!PPTokenTest class methodsFor:'documentation'! |
|
137 |
||
38 | 138 |
version |
194 | 139 |
^ '$Header: /cvs/stx/stx/goodies/petitparser/PPTokenTest.st,v 1.5 2014-03-04 14:34:24 cg Exp $' |
38 | 140 |
! |
141 |
||
142 |
version_CVS |
|
194 | 143 |
^ '$Header: /cvs/stx/stx/goodies/petitparser/PPTokenTest.st,v 1.5 2014-03-04 14:34:24 cg Exp $' |
38 | 144 |
! |
145 |
||
0 | 146 |
version_SVN |
194 | 147 |
^ '$Id: PPTokenTest.st,v 1.5 2014-03-04 14:34:24 cg Exp $' |
0 | 148 |
! ! |
194 | 149 |