diakonos 0.8.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,70 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'diakonos/clipboard'
5
+
6
+ class TC_Clipboard < Test::Unit::TestCase
7
+ def test_01_addClip
8
+ c = Diakonos::Clipboard.new( 3 )
9
+ assert_equal false, c.addClip( nil )
10
+ assert_equal true, c.addClip( [ 'foo' ] )
11
+ assert_equal true, c.addClip( [ 'bar' ] )
12
+ assert_equal true, c.addClip( [ 'baz' ] )
13
+ assert_equal [ 'foo' ], c[ 2 ]
14
+ assert_nil c[ 3 ]
15
+ assert_equal true, c.addClip( [ 'fiz' ] )
16
+ assert_equal [ 'bar' ], c[ 2 ]
17
+ assert_nil c[ 3 ]
18
+ end
19
+
20
+ def test_02_brackets
21
+ c = Diakonos::Clipboard.new( 3 )
22
+ assert_nil c[ -1 ]
23
+ assert_nil c[ 0 ]
24
+ assert_nil c[ 1 ]
25
+ assert_equal false, c.addClip( nil )
26
+ x = [ 'foo' ]
27
+ assert_equal true, c.addClip( x )
28
+ assert_equal x, c[ -1 ]
29
+ assert_equal x, c[ 0 ]
30
+ assert_nil c[ 1 ]
31
+ end
32
+
33
+ def test_03_each
34
+ c = Diakonos::Clipboard.new( 10 )
35
+ 9.downto( 0 ) do |i|
36
+ c.addClip( [ i.to_s ] )
37
+ end
38
+ i = 0
39
+ c.each do |clip|
40
+ assert_equal( [ i.to_s ], clip )
41
+ i += 1
42
+ end
43
+ end
44
+
45
+ def test_04_appendToClip
46
+ c = Diakonos::Clipboard.new( 10 )
47
+ assert_equal false, c.appendToClip( nil )
48
+ x = [ 'foo' ]
49
+ assert_equal true, c.appendToClip( x )
50
+ assert_equal(
51
+ [ 'foo' ],
52
+ c.clip
53
+ )
54
+
55
+ assert_equal true, c.appendToClip( [ 'bar', 'baz' ] )
56
+ assert_equal(
57
+ [ 'foo', 'bar', 'baz' ],
58
+ c.clip
59
+ )
60
+
61
+ y = [ 'line with newline', '' ]
62
+ assert_equal true, c.addClip( y )
63
+ assert_equal y, c.clip
64
+ assert_equal true, c.appendToClip( [ 'another line' ] )
65
+ assert_equal(
66
+ [ 'line with newline', 'another line' ],
67
+ c.clip
68
+ )
69
+ end
70
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'diakonos'
5
+
6
+ class TC_Diakonos < Test::Unit::TestCase
7
+ def setup
8
+ $diakonos = Diakonos::Diakonos.new
9
+ end
10
+
11
+ def test_true
12
+ assert true
13
+ end
14
+ end
@@ -0,0 +1,404 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'diakonos'
5
+
6
+ class TC_Hash < Test::Unit::TestCase
7
+ def test_deleteKeyPath
8
+ g = {}
9
+ h = g.deep_clone
10
+ assert_equal(
11
+ {},
12
+ h.deleteKeyPath( [] )
13
+ )
14
+ h = g.deep_clone
15
+ assert_equal(
16
+ {},
17
+ h.deleteKeyPath( [ 'test' ] )
18
+ )
19
+ h = g.deep_clone
20
+ assert_equal(
21
+ {},
22
+ h.deleteKeyPath( [ 'test', 'test2' ] )
23
+ )
24
+
25
+ g = { 'a' => 'x' }
26
+ h = g.deep_clone
27
+ assert_equal(
28
+ { 'a' => 'x' },
29
+ h.deleteKeyPath( [] )
30
+ )
31
+ h = g.deep_clone
32
+ assert_equal(
33
+ { 'a' => 'x' },
34
+ h.deleteKeyPath( [ 'test' ] )
35
+ )
36
+ h = g.deep_clone
37
+ assert_equal(
38
+ { 'a' => 'x' },
39
+ h.deleteKeyPath( [ 'test', 'test2' ] )
40
+ )
41
+ h = g.deep_clone
42
+ assert_equal(
43
+ {},
44
+ h.deleteKeyPath( [ 'a' ] )
45
+ )
46
+ h = g.deep_clone
47
+ assert_equal(
48
+ { 'a' => 'x' },
49
+ h.deleteKeyPath( [ 'a', 'b' ] )
50
+ )
51
+
52
+ g = {
53
+ 'a' => {
54
+ 'b' => 'x'
55
+ }
56
+ }
57
+ h = g.deep_clone
58
+ assert_equal(
59
+ { 'a' => { 'b' => 'x' } },
60
+ h.deleteKeyPath( [] )
61
+ )
62
+ h = g.deep_clone
63
+ assert_equal(
64
+ { 'a' => { 'b' => 'x' } },
65
+ h.deleteKeyPath( [ 'z' ] )
66
+ )
67
+ h = g.deep_clone
68
+ assert_equal(
69
+ { 'a' => { 'b' => 'x' } },
70
+ h.deleteKeyPath( [ 'z', 'zz' ] )
71
+ )
72
+ h = g.deep_clone
73
+ assert_equal(
74
+ { 'a' => { 'b' => 'x' } },
75
+ h.deleteKeyPath( [ 'a', 'b', 'c' ] )
76
+ )
77
+ h = g.deep_clone
78
+ assert_equal(
79
+ {},
80
+ h.deleteKeyPath( [ 'a' ] )
81
+ )
82
+ h = g.deep_clone
83
+ assert_equal(
84
+ {},
85
+ h.deleteKeyPath( [ 'a', 'b' ] )
86
+ )
87
+
88
+ g = {
89
+ 'a' => {
90
+ 'b' => 'x',
91
+ 'c' => 'y'
92
+ }
93
+ }
94
+ h = g.deep_clone
95
+ assert_equal(
96
+ { 'a' => { 'b' => 'x', 'c' => 'y' } },
97
+ h.deleteKeyPath( [] )
98
+ )
99
+ h = g.deep_clone
100
+ assert_equal(
101
+ { 'a' => { 'b' => 'x', 'c' => 'y' } },
102
+ h.deleteKeyPath( [ 'z' ] )
103
+ )
104
+ h = g.deep_clone
105
+ assert_equal(
106
+ { 'a' => { 'b' => 'x', 'c' => 'y' } },
107
+ h.deleteKeyPath( [ 'z', 'zz' ] )
108
+ )
109
+ h = g.deep_clone
110
+ assert_equal(
111
+ { 'a' => { 'b' => 'x', 'c' => 'y' } },
112
+ h.deleteKeyPath( [ 'a', 'b', 'c' ] )
113
+ )
114
+ h = g.deep_clone
115
+ assert_equal(
116
+ {},
117
+ h.deleteKeyPath( [ 'a' ] )
118
+ )
119
+ h = g.deep_clone
120
+ assert_equal(
121
+ { 'a' => { 'c' => 'y' } },
122
+ h.deleteKeyPath( [ 'a', 'b' ] )
123
+ )
124
+ h = g.deep_clone
125
+ assert_equal(
126
+ { 'a' => { 'b' => 'x' } },
127
+ h.deleteKeyPath( [ 'a', 'c' ] )
128
+ )
129
+
130
+ g = {
131
+ 'a' => {
132
+ 'b' => 'x'
133
+ },
134
+ 'c' => {
135
+ 'd' => 'y'
136
+ }
137
+ }
138
+ h = g.deep_clone
139
+ assert_equal(
140
+ { 'a' => { 'b' => 'x' }, 'c' => { 'd' => 'y' } },
141
+ h.deleteKeyPath( [] )
142
+ )
143
+ h = g.deep_clone
144
+ assert_equal(
145
+ { 'a' => { 'b' => 'x' }, 'c' => { 'd' => 'y' } },
146
+ h.deleteKeyPath( [ 'z' ] )
147
+ )
148
+ h = g.deep_clone
149
+ assert_equal(
150
+ { 'a' => { 'b' => 'x' }, 'c' => { 'd' => 'y' } },
151
+ h.deleteKeyPath( [ 'z', 'zz' ] )
152
+ )
153
+ h = g.deep_clone
154
+ assert_equal(
155
+ { 'a' => { 'b' => 'x' }, 'c' => { 'd' => 'y' } },
156
+ h.deleteKeyPath( [ 'a', 'b', 'c' ] )
157
+ )
158
+ h = g.deep_clone
159
+ assert_equal(
160
+ { 'c' => { 'd' => 'y' } },
161
+ h.deleteKeyPath( [ 'a' ] )
162
+ )
163
+ h = g.deep_clone
164
+ assert_equal(
165
+ { 'a' => { 'b' => 'x' } },
166
+ h.deleteKeyPath( [ 'c' ] )
167
+ )
168
+ h = g.deep_clone
169
+ assert_equal(
170
+ { 'c' => { 'd' => 'y' } },
171
+ h.deleteKeyPath( [ 'a', 'b' ] )
172
+ )
173
+ h = g.deep_clone
174
+ assert_equal(
175
+ { 'a' => { 'b' => 'x' } },
176
+ h.deleteKeyPath( [ 'c', 'd' ] )
177
+ )
178
+ end
179
+
180
+ def test_setKeyPath
181
+ g = {}
182
+ h = g.deep_clone
183
+ assert_equal(
184
+ {},
185
+ h.setKeyPath( [], 'x' )
186
+ )
187
+ h = g.deep_clone
188
+ assert_equal(
189
+ { 'a' => 'x' },
190
+ h.setKeyPath( [ 'a' ], 'x' )
191
+ )
192
+ h = g.deep_clone
193
+ assert_equal(
194
+ { 'a' => { 'b' => 'x' } },
195
+ h.setKeyPath( [ 'a', 'b' ], 'x' )
196
+ )
197
+
198
+ g = { 'a' => 'x' }
199
+ h = g.deep_clone
200
+ assert_equal(
201
+ { 'a' => 'x' },
202
+ h.setKeyPath( [], 'x' )
203
+ )
204
+ h = g.deep_clone
205
+ assert_equal(
206
+ { 'a' => 'x' },
207
+ h.setKeyPath( [ 'a' ], 'x' )
208
+ )
209
+ h = g.deep_clone
210
+ assert_equal(
211
+ { 'a' => { 'b' => 'x' } },
212
+ h.setKeyPath( [ 'a', 'b' ], 'x' )
213
+ )
214
+
215
+ g = { 'c' => 'y' }
216
+ h = g.deep_clone
217
+ assert_equal(
218
+ { 'c' => 'y' },
219
+ h.setKeyPath( [], 'x' )
220
+ )
221
+ h = g.deep_clone
222
+ assert_equal(
223
+ { 'c' => 'y', 'a' => 'x' },
224
+ h.setKeyPath( [ 'a' ], 'x' )
225
+ )
226
+ h = g.deep_clone
227
+ assert_equal(
228
+ { 'c' => 'y', 'a' => { 'b' => 'x' } },
229
+ h.setKeyPath( [ 'a', 'b' ], 'x' )
230
+ )
231
+
232
+ g = { 'a' => { 'b' => 'x' } }
233
+ h = g.deep_clone
234
+ assert_equal(
235
+ { 'a' => { 'b' => 'x' } },
236
+ h.setKeyPath( [], 'x' )
237
+ )
238
+ h = g.deep_clone
239
+ assert_equal(
240
+ { 'a' => 'x' },
241
+ h.setKeyPath( [ 'a' ], 'x' )
242
+ )
243
+ h = g.deep_clone
244
+ assert_equal(
245
+ { 'a' => { 'b' => 'x' }, 'c' => 'y' },
246
+ h.setKeyPath( [ 'c' ], 'y' )
247
+ )
248
+ h = g.deep_clone
249
+ assert_equal(
250
+ { 'a' => { 'b' => 'x' }, 'c' => { 'd' => 'y' } },
251
+ h.setKeyPath( [ 'c', 'd' ], 'y' )
252
+ )
253
+ end
254
+
255
+ def test_getNode
256
+ h = {}
257
+ assert_equal(
258
+ nil,
259
+ h.getNode( [] )
260
+ )
261
+ assert_equal(
262
+ nil,
263
+ h.getNode( [ 'a' ] )
264
+ )
265
+ assert_equal(
266
+ nil,
267
+ h.getNode( [ 'a', 'b' ] )
268
+ )
269
+
270
+ h = { 'a' => 'x' }
271
+ assert_equal(
272
+ nil,
273
+ h.getNode( [] )
274
+ )
275
+ assert_equal(
276
+ nil,
277
+ h.getNode( [ 'b' ] )
278
+ )
279
+ assert_equal(
280
+ 'x',
281
+ h.getNode( [ 'a' ] )
282
+ )
283
+
284
+ h = { 'a' => { 'b' => 'x' } }
285
+ assert_equal(
286
+ nil,
287
+ h.getNode( [] )
288
+ )
289
+ assert_equal(
290
+ nil,
291
+ h.getNode( [ 'b' ] )
292
+ )
293
+ assert_equal(
294
+ { 'b' => 'x' },
295
+ h.getNode( [ 'a' ] )
296
+ )
297
+ assert_equal(
298
+ nil,
299
+ h.getNode( [ 'a', 'b', 'c' ] )
300
+ )
301
+ assert_equal(
302
+ nil,
303
+ h.getNode( [ 'a', 'c' ] )
304
+ )
305
+ assert_equal(
306
+ 'x',
307
+ h.getNode( [ 'a', 'b' ] )
308
+ )
309
+ end
310
+
311
+ def test_getLeaf
312
+ h = {}
313
+ assert_equal(
314
+ nil,
315
+ h.getLeaf( [] )
316
+ )
317
+ assert_equal(
318
+ nil,
319
+ h.getLeaf( [ 'a' ] )
320
+ )
321
+ assert_equal(
322
+ nil,
323
+ h.getLeaf( [ 'a', 'b' ] )
324
+ )
325
+
326
+ h = { 'a' => 'x' }
327
+ assert_equal(
328
+ nil,
329
+ h.getLeaf( [] )
330
+ )
331
+ assert_equal(
332
+ nil,
333
+ h.getLeaf( [ 'b' ] )
334
+ )
335
+ assert_equal(
336
+ 'x',
337
+ h.getLeaf( [ 'a' ] )
338
+ )
339
+
340
+ h = { 'a' => { 'b' => 'x' } }
341
+ assert_equal(
342
+ nil,
343
+ h.getLeaf( [] )
344
+ )
345
+ assert_equal(
346
+ nil,
347
+ h.getLeaf( [ 'b' ] )
348
+ )
349
+ assert_equal(
350
+ nil,
351
+ h.getLeaf( [ 'a' ] )
352
+ )
353
+ assert_equal(
354
+ nil,
355
+ h.getLeaf( [ 'a', 'b', 'c' ] )
356
+ )
357
+ assert_equal(
358
+ nil,
359
+ h.getLeaf( [ 'a', 'c' ] )
360
+ )
361
+ assert_equal(
362
+ 'x',
363
+ h.getLeaf( [ 'a', 'b' ] )
364
+ )
365
+ end
366
+
367
+ def test_leaves
368
+ h = {}
369
+ assert_equal(
370
+ Set.new( [] ),
371
+ h.leaves
372
+ )
373
+
374
+ h = { 'a' => 'x' }
375
+ assert_equal(
376
+ Set.new( [ 'x' ] ),
377
+ h.leaves
378
+ )
379
+
380
+ h = { 'a' => 'x', 'b' => 'y' }
381
+ assert_equal(
382
+ Set.new( [ 'x', 'y' ] ),
383
+ h.leaves
384
+ )
385
+
386
+ h = { 'a' => { 'b' => 'x' }, 'c' => 'y' }
387
+ assert_equal(
388
+ Set.new( [ 'x', 'y' ] ),
389
+ h.leaves
390
+ )
391
+
392
+ h = { 'a' => { 'b' => 'x' }, 'c' => { 'd' => 'y' } }
393
+ assert_equal(
394
+ Set.new( [ 'x', 'y' ] ),
395
+ h.leaves
396
+ )
397
+
398
+ h = { 'a' => { 'b' => 'x' }, 'c' => { 'd' => 'y', 'e' => 'z' }, 'f' => 'w' }
399
+ assert_equal(
400
+ Set.new( [ 'x', 'y', 'z', 'w' ] ),
401
+ h.leaves
402
+ )
403
+ end
404
+ end