13481
|
1 |
"
|
|
2 |
COPYRIGHT (c) 2010 by Jan Vrany, SWING Research Group. CTU in Prague
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
Permission is hereby granted, free of charge, to any person
|
|
6 |
obtaining a copy of this software and associated documentation
|
|
7 |
files (the 'Software'), to deal in the Software without
|
|
8 |
restriction, including without limitation the rights to use,
|
|
9 |
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10 |
copies of the Software, and to permit persons to whom the
|
|
11 |
Software is furnished to do so, subject to the following
|
|
12 |
conditions:
|
|
13 |
|
|
14 |
The above copyright notice and this permission notice shall be
|
|
15 |
included in all copies or substantial portions of the Software.
|
|
16 |
|
|
17 |
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
18 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
19 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
20 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
21 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
22 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
23 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
24 |
OTHER DEALINGS IN THE SOFTWARE.
|
|
25 |
"
|
13402
|
26 |
"{ Package: 'stx:libbasic' }"
|
|
27 |
|
13481
|
28 |
nil subclass:#CmdLineParserTest
|
13402
|
29 |
instanceVariableNames:'optionA optionB optionBValue'
|
|
30 |
classVariableNames:''
|
|
31 |
poolDictionaries:''
|
|
32 |
category:'System-Support-Command line'
|
|
33 |
!
|
|
34 |
|
13481
|
35 |
!CmdLineParserTest class methodsFor:'documentation'!
|
|
36 |
|
|
37 |
copyright
|
|
38 |
"
|
|
39 |
COPYRIGHT (c) 2010 by Jan Vrany, SWING Research Group. CTU in Prague
|
|
40 |
All Rights Reserved
|
|
41 |
|
|
42 |
Permission is hereby granted, free of charge, to any person
|
|
43 |
obtaining a copy of this software and associated documentation
|
|
44 |
files (the 'Software'), to deal in the Software without
|
|
45 |
restriction, including without limitation the rights to use,
|
|
46 |
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
47 |
copies of the Software, and to permit persons to whom the
|
|
48 |
Software is furnished to do so, subject to the following
|
|
49 |
conditions:
|
|
50 |
|
|
51 |
The above copyright notice and this permission notice shall be
|
|
52 |
included in all copies or substantial portions of the Software.
|
|
53 |
|
|
54 |
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
55 |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
56 |
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
57 |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
58 |
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
59 |
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
60 |
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
61 |
OTHER DEALINGS IN THE SOFTWARE.
|
|
62 |
"
|
|
63 |
! !
|
13402
|
64 |
|
|
65 |
!CmdLineParserTest methodsFor:'accessing'!
|
|
66 |
|
|
67 |
cmdlineOptionA
|
|
68 |
|
|
69 |
^CmdLineOption new
|
|
70 |
short: $a;
|
|
71 |
long: 'option-a';
|
|
72 |
description: 'option a with no arg';
|
|
73 |
action:[optionA := true]
|
|
74 |
|
|
75 |
"Created: / 28-01-2009 / 11:56:28 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
|
76 |
"Modified: / 08-06-2009 / 14:34:00 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
|
77 |
!
|
|
78 |
|
|
79 |
cmdlineOptionB
|
|
80 |
|
|
81 |
^CmdLineOption new
|
|
82 |
short: $b;
|
|
83 |
long: 'option-b';
|
|
84 |
description: 'option b with one arg';
|
|
85 |
action:[:value | optionB := true. optionBValue := value]
|
|
86 |
|
|
87 |
"Created: / 28-01-2009 / 12:01:43 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
|
88 |
"Modified: / 08-06-2009 / 14:33:50 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
|
89 |
! !
|
|
90 |
|
|
91 |
!CmdLineParserTest methodsFor:'initialization'!
|
|
92 |
|
|
93 |
setUp
|
|
94 |
|
|
95 |
optionA := optionB := false.
|
|
96 |
optionBValue := nil
|
|
97 |
|
|
98 |
"Created: / 28-01-2009 / 12:01:01 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
|
99 |
! !
|
|
100 |
|
|
101 |
!CmdLineParserTest methodsFor:'tests'!
|
|
102 |
|
|
103 |
test_01
|
|
104 |
|
|
105 |
CmdLineParser
|
|
106 |
parse: #('-a')
|
|
107 |
for: self.
|
|
108 |
|
|
109 |
self assert: optionA.
|
|
110 |
self deny: optionB.
|
|
111 |
|
|
112 |
"Created: / 28-01-2009 / 14:19:18 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
|
113 |
"Modified: / 29-05-2009 / 15:47:19 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
|
114 |
!
|
|
115 |
|
|
116 |
test_02
|
|
117 |
|
|
118 |
CmdLineParser
|
|
119 |
parse: #('--option-a')
|
|
120 |
for: self.
|
|
121 |
|
|
122 |
self assert: optionA.
|
|
123 |
self deny: optionB.
|
|
124 |
|
|
125 |
"Created: / 28-01-2009 / 14:19:38 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
|
126 |
"Modified: / 29-05-2009 / 15:47:30 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
|
127 |
!
|
|
128 |
|
|
129 |
test_04a
|
|
130 |
|
|
131 |
CmdLineParser
|
|
132 |
parse: #('--option-b= value')
|
|
133 |
for: self.
|
|
134 |
|
|
135 |
self deny: optionA.
|
|
136 |
self assert: optionB.
|
|
137 |
self assert: optionBValue = ' value'
|
|
138 |
|
|
139 |
"Created: / 30-01-2009 / 10:43:40 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
|
140 |
"Modified: / 29-05-2009 / 15:47:34 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
|
141 |
!
|
|
142 |
|
|
143 |
test_04b
|
|
144 |
|
|
145 |
self
|
|
146 |
should:[CmdLineParser parse: #('--option-b') for: self]
|
|
147 |
raise: CmdLineOptionError
|
|
148 |
|
|
149 |
"Created: / 30-01-2009 / 10:43:37 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
|
150 |
"Modified: / 29-05-2009 / 15:47:39 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
|
151 |
!
|
|
152 |
|
|
153 |
test_04c
|
|
154 |
|
|
155 |
CmdLineParser parse: #('--option-b=') for: self.
|
|
156 |
|
|
157 |
self deny: optionA.
|
|
158 |
self assert: optionB.
|
|
159 |
self assert: optionBValue = ''
|
|
160 |
|
|
161 |
"Created: / 30-01-2009 / 10:44:20 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
|
162 |
"Modified: / 29-05-2009 / 15:47:44 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
|
163 |
!
|
|
164 |
|
|
165 |
test_05
|
|
166 |
|
|
167 |
CmdLineParser
|
|
168 |
parse: #('-b' 'value')
|
|
169 |
for: self.
|
|
170 |
|
|
171 |
self deny: optionA.
|
|
172 |
self assert: optionB.
|
|
173 |
self assert: optionBValue = 'value'.
|
|
174 |
|
|
175 |
"Created: / 03-02-2009 / 17:38:51 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
|
176 |
"Modified: / 29-05-2009 / 15:47:50 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
|
177 |
!
|
|
178 |
|
|
179 |
test_06
|
|
180 |
|
|
181 |
CmdLineParser
|
|
182 |
parse: #('-a' '-b' 'value')
|
|
183 |
for: self.
|
|
184 |
|
|
185 |
self assert: optionA.
|
|
186 |
self assert: optionB.
|
|
187 |
self assert: optionBValue = 'value'.
|
|
188 |
|
|
189 |
"Created: / 03-02-2009 / 17:39:54 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
|
190 |
"Modified: / 29-05-2009 / 15:47:56 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
|
191 |
!
|
|
192 |
|
|
193 |
test_07
|
|
194 |
|
|
195 |
CmdLineParser
|
|
196 |
parse: #('-ab' 'value')
|
|
197 |
for: self.
|
|
198 |
|
|
199 |
self assert: optionA.
|
|
200 |
self assert: optionB.
|
|
201 |
self assert: optionBValue = 'value'.
|
|
202 |
|
|
203 |
"Created: / 03-02-2009 / 17:40:04 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
|
204 |
"Modified: / 29-05-2009 / 15:48:02 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
|
205 |
!
|
|
206 |
|
|
207 |
test_08
|
|
208 |
|
|
209 |
| rest |
|
|
210 |
rest := CmdLineParser
|
|
211 |
parse: #('-a' '/tmp/abc.txt')
|
|
212 |
for: self.
|
|
213 |
|
|
214 |
self assert: optionA.
|
|
215 |
self assert: optionB not.
|
|
216 |
self assert: rest asArray = #('/tmp/abc.txt')
|
|
217 |
|
|
218 |
"Created: / 08-06-2009 / 14:51:54 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
|
219 |
!
|
|
220 |
|
|
221 |
test_09
|
|
222 |
|
|
223 |
| rest |
|
|
224 |
rest := CmdLineParser
|
|
225 |
parse: #('/tmp/abc.txt')
|
|
226 |
for: self.
|
|
227 |
|
|
228 |
self assert: optionA not.
|
|
229 |
self assert: optionB not.
|
|
230 |
self assert: rest asArray = #('/tmp/abc.txt')
|
|
231 |
|
|
232 |
"Created: / 08-06-2009 / 14:52:13 / Jan Vrany <vranyj1@fel.cvut.cz>"
|
|
233 |
! !
|
|
234 |
|
|
235 |
!CmdLineParserTest class methodsFor:'documentation'!
|
|
236 |
|
13481
|
237 |
version_CVS
|
|
238 |
^ '$Header: /cvs/stx/stx/libbasic/CmdLineParserTest.st,v 1.2 2011-07-03 15:06:55 cg Exp $'
|
|
239 |
!
|
|
240 |
|
|
241 |
version_SVN
|
|
242 |
^'§Id: CmdLineParserTest.st,v 1.1 2011/06/28 10:54:52 vrany Exp §'
|
13402
|
243 |
! !
|