File: tool.test

package info (click to toggle)
tcllib 1.18-dfsg-3
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 64,304 kB
  • ctags: 28,857
  • sloc: tcl: 174,135; ansic: 14,215; sh: 2,643; xml: 1,766; yacc: 1,148; pascal: 583; makefile: 106; perl: 84; f90: 84; python: 33; ruby: 13; php: 11
file content (339 lines) | stat: -rw-r--r-- 8,404 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
# tool.test - Copyright (c) 2015 Sean Woods
# -------------------------------------------------------------------------

source [file join \
	[file dirname [file dirname [file join [pwd] [info script]]]] \
	devtools testutilities.tcl]

testsNeedTcl     8.6
testsNeedTcltest 2
testsNeed        TclOO 1

support {
    use oodialect/oodialect.tcl oo::dialect
    use dicttool/dicttool.tcl   dicttool
    use oometa/oometa.tcl       oo::meta
    use sha1/sha1.tcl           sha1
}
testing {
    useLocal index.tcl tool
}

# -------------------------------------------------------------------------

tool::class create OptionClass {
  property color green
  property mass  1200kg
  option bodystyle {default: sedan}
  option master {class organ default ::noop}
}

tool::class create OptionClass2 {
  superclass OptionClass
  property mass  1400kg
  option color {default: blue}
}

OptionClass create ObjectOptionTest1 
OptionClass create ObjectOptionTest2 bodystyle wagon transmission standard
OptionClass2 create ObjectOptionTest3
OptionClass2 create ObjectOptionTest4 bodystyle SUV transmission cvt color white

###
# Property ignores options
###
test tool-options-001 {Simple property queries} {
  ObjectOptionTest1 property color
} green

test tool-options-002 {Simple property queries} {
  ObjectOptionTest2 property color
} green

test tool-options-003 {Simple property queries} {
  ObjectOptionTest3 property color
} green

test tool-options-004 {Simple property queries} {
  ObjectOptionTest4 property color
} green

###
# Cget consults the options
###
test tool-options-005 {Simple property queries} {
  ObjectOptionTest1 cget color
} green

test tool-options-006 {Simple property queries} {
  ObjectOptionTest2 cget color
} green

test tool-options-007 {Simple property queries} {
  ObjectOptionTest3 cget color
} blue

test tool-options-008 {Simple property queries} {
  ObjectOptionTest4 cget color
} white

###
# Tests with options in an object changing class
###
test tool-options-009 {Simple property queries} {
  ObjectOptionTest3 property mass
} 1400kg

ObjectOptionTest3 morph OptionClass
# The option for color was already set. It should remain
test tool-options-010 {Simple property queries} {
  ObjectOptionTest3 cget color
} blue
# The "color" property on the other hand should revert
test tool-options-011 {Simple property queries} {
  ObjectOptionTest3 property color
} green
# The "mass" property on the other hand should revert
test tool-options-012 {Simple property queries} {
  ObjectOptionTest3 property mass
} 1200kg

# Change a OptionClass to a OptionClass2

test tool-options-013 {Simple property queries} {
  ObjectOptionTest2 property mass
} 1200kg

ObjectOptionTest2 morph OptionClass2
# When entering OptionClass2, the object will get any new options
test tool-options-014 {Simple property queries} {
  ObjectOptionTest2 cget color
} blue

test tool-options-015 {Simple property queries} {
  ObjectOptionTest2 property mass
} 1400kg

# When changing back, the set option remains
ObjectOptionTest2 morph OptionClass
test tool-options-016 {Simple property queries} {
  ObjectOptionTest2 cget color
} blue

test tool-options-017 {Simple property queries} {
  ObjectOptionTest2 property mass
} 1200kg


tool::class create ArrayEnsembleClass {
  # Burned in defaults
  meta branchset define {
    color: pink
  }

  array_ensemble define define {
    initialize {
      foo bar
    }
    custom {
      return custom
    }
    true {
      return true
    }
    false {
      return false
    }
  }
}

ArrayEnsembleClass create ArrayEnsembleObject

test tool-ensemble-001 {Test Array Ensemble} {
  ArrayEnsembleObject define true
} true
test tool-ensemble-002 {Test Array Ensemble} {
  ArrayEnsembleObject define false
} false
test tool-ensemble-003 {Test Array Ensemble retrieve initial value} {
  ArrayEnsembleObject define get foo
} bar
test tool-ensemble-004 {Test Array Ensemble Store a value} {
  ArrayEnsembleObject define set cc /usr/bin/cc
  ArrayEnsembleObject define get cc
} /usr/bin/cc

test tool-ensemble-005 {Test array add} {
  ArrayEnsembleObject define add path /bin
  ArrayEnsembleObject define get path
} /bin

test tool-ensemble-005 {Test array add} {
  ArrayEnsembleObject define add path /usr/bin
  ArrayEnsembleObject define get path
} {/bin /usr/bin}

test tool-ensemble-006 {Test array add (again)} {
  ArrayEnsembleObject define add path /usr/bin
  ArrayEnsembleObject define get path
} {/bin /usr/bin}


test tool-ensemble-007 {Test array lappend} {
  ArrayEnsembleObject define lappend path /usr/bin
  ArrayEnsembleObject define get path
} {/bin /usr/bin /usr/bin}

test tool-ensemble-008 {Test array remove} {
  ArrayEnsembleObject define remove path /usr/bin
  ArrayEnsembleObject define get path
} {/bin}

test tool-ensemble-009 {Test array exists} {
  ArrayEnsembleObject define exists counter
} 0

test tool-ensemble-010 {Test array incr} {
  ArrayEnsembleObject define incr counter
  ArrayEnsembleObject define get counter
} 1

test tool-ensemble-011 {Test array incr} {
  ArrayEnsembleObject define incr counter
  ArrayEnsembleObject define get counter
} 2

test tool-ensemble-012 {Test array exists} {
  ArrayEnsembleObject define exists counter
} 1

test tool-ensemble-013 {Test array reset} {
  ArrayEnsembleObject define reset
  lsort -stride 2 [ArrayEnsembleObject define dump]
} {color pink foo bar}

tool::class create DictEnsembleClass {
  # Burned in defaults
  meta branchset define {
    color: pink
  }

  dict_ensemble define define {
    initialize {
      foo bar
    }
    custom {
      return custom
    }
    true {
      return true
    }
    false {
      return false
    }
  }
}

DictEnsembleClass create DictEnsembleObject

test tool-ensemble-001 {Test Array Ensemble} {
  DictEnsembleObject define true
} true
test tool-ensemble-002 {Test Array Ensemble} {
  DictEnsembleObject define false
} false
test tool-ensemble-003 {Test Array Ensemble retrieve initial value} {
  DictEnsembleObject define get foo
} bar
test tool-ensemble-004 {Test Array Ensemble Store a value} {
  DictEnsembleObject define set cc /usr/bin/cc
  DictEnsembleObject define get cc
} /usr/bin/cc

test tool-ensemble-005 {Test array add} {
  DictEnsembleObject define add path /bin
  DictEnsembleObject define get path
} /bin

test tool-ensemble-005 {Test array add} {
  DictEnsembleObject define add path /usr/bin
  DictEnsembleObject define get path
} {/bin /usr/bin}

test tool-ensemble-006 {Test array add (again)} {
  DictEnsembleObject define add path /usr/bin
  DictEnsembleObject define get path
} {/bin /usr/bin}


test tool-ensemble-007 {Test array lappend} {
  DictEnsembleObject define lappend path /usr/bin
  DictEnsembleObject define get path
} {/bin /usr/bin /usr/bin}

test tool-ensemble-008 {Test array remove} {
  DictEnsembleObject define remove path /usr/bin
  DictEnsembleObject define get path
} {/bin}

test tool-ensemble-009 {Test array exists} {
  DictEnsembleObject define exists counter
} 0

test tool-ensemble-010 {Test array incr} {
  DictEnsembleObject define incr counter
  DictEnsembleObject define get counter
} 1

test tool-ensemble-011 {Test array incr} {
  DictEnsembleObject define incr counter
  DictEnsembleObject define get counter
} 2

test tool-ensemble-012 {Test array exists} {
  DictEnsembleObject define exists counter
} 1

test tool-ensemble-013 {Test array reset} {
  DictEnsembleObject define reset
  lsort -stride 2 [DictEnsembleObject define dump]
} {color pink foo bar}




test tool-option_class-001 {Test option class} {
  ObjectOptionTest1 meta get option master
} {default: ::noop class: organ widget: label set-command: {my graft %field% %value%} get-command: {my organ %field%}}

proc GNDN args {
  return $args
}

ObjectOptionTest1 configure master GNDN
test tool-option_class-002 {Test option class} {
  ObjectOptionTest1 organ master
} GNDN

test tool-option_class-003 {Test option class} {
  ObjectOptionTest1 <master> puts FOO
} {puts FOO}

OptionClass2 create ObjectOptionTest5 bodystyle SUV transmission cvt color white master GNDN

test tool-option_class-002 {Test option class} {
  ObjectOptionTest5 organ master
} GNDN

test tool-option_class-003 {Test option class} {
  ObjectOptionTest5 <master> puts FOO
} {puts FOO}
# -------------------------------------------------------------------------


testsuiteCleanup

# Local variables:
# mode: tcl
# indent-tabs-mode: nil
# End: