kronk 1.3.1 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.rdoc +28 -0
- data/Manifest.txt +4 -0
- data/README.rdoc +46 -18
- data/Rakefile +0 -3
- data/bin/kronk +2 -1
- data/lib/kronk.rb +19 -98
- data/lib/kronk/cmd.rb +22 -12
- data/lib/kronk/data_set.rb +55 -228
- data/lib/kronk/diff.rb +65 -4
- data/lib/kronk/path.rb +427 -0
- data/lib/kronk/path/transaction.rb +204 -0
- data/lib/kronk/request.rb +66 -5
- data/lib/kronk/response.rb +1 -1
- data/lib/kronk/test/assertions.rb +4 -8
- data/lib/kronk/test/core_ext.rb +57 -9
- data/lib/kronk/xml_parser.rb +41 -7
- data/script/kronk_completion +3 -2
- data/test/test_core_ext.rb +2 -2
- data/test/test_data_set.rb +4 -297
- data/test/test_diff.rb +12 -12
- data/test/test_kronk.rb +2 -0
- data/test/test_path.rb +370 -0
- data/test/test_request.rb +0 -10
- data/test/test_transaction.rb +330 -0
- metadata +31 -63
- data/.gemtest +0 -0
data/script/kronk_completion
CHANGED
@@ -8,10 +8,11 @@ _kronk()
|
|
8
8
|
|
9
9
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
10
10
|
|
11
|
-
kronk_keys="$HOME/.
|
11
|
+
kronk_keys="$HOME/.kronk/history"
|
12
|
+
test -f "$kronk_keys" || kronk_keys="$HOME/.kronk_history"
|
12
13
|
|
13
14
|
if [ -f "$kronk_keys" ]; then
|
14
|
-
COMPREPLY=( $(compgen -W "$(cat $kronk_keys)" -- ${cur}) )
|
15
|
+
COMPREPLY=( $(compgen -W "$(cat $kronk_keys $old_kronk_keys)" -- ${cur}) )
|
15
16
|
return 0
|
16
17
|
fi
|
17
18
|
|
data/test/test_core_ext.rb
CHANGED
@@ -12,14 +12,14 @@ class TestCoreExt < Test::Unit::TestCase
|
|
12
12
|
def test_has_path_array
|
13
13
|
assert @array.has_path?("**/foo")
|
14
14
|
assert @array.has_path?("**/foo=other")
|
15
|
-
|
15
|
+
assert !@array.has_path?("**/foobar")
|
16
16
|
end
|
17
17
|
|
18
18
|
|
19
19
|
def test_has_path_hash
|
20
20
|
assert @hash.has_path?("**/foo")
|
21
21
|
assert @hash.has_path?("**/foo=other")
|
22
|
-
|
22
|
+
assert !@hash.has_path?("**/foobar")
|
23
23
|
end
|
24
24
|
|
25
25
|
|
data/test/test_data_set.rb
CHANGED
@@ -2,7 +2,6 @@ require 'test/test_helper'
|
|
2
2
|
|
3
3
|
class TestDataSet < Test::Unit::TestCase
|
4
4
|
|
5
|
-
|
6
5
|
def setup
|
7
6
|
@data = {
|
8
7
|
:key1 => {
|
@@ -28,6 +27,8 @@ class TestDataSet < Test::Unit::TestCase
|
|
28
27
|
@dataset = Kronk::DataSet.new @data
|
29
28
|
|
30
29
|
@dataset_mock = Kronk::DataSet.new mock_data
|
30
|
+
|
31
|
+
Kronk::Cmd.expects :warn
|
31
32
|
end
|
32
33
|
|
33
34
|
|
@@ -48,12 +49,14 @@ class TestDataSet < Test::Unit::TestCase
|
|
48
49
|
|
49
50
|
|
50
51
|
def test_modify_only_data_with
|
52
|
+
Kronk::Cmd.expects :warn
|
51
53
|
data = @dataset_mock.modify :only_data_with => "subs/1"
|
52
54
|
assert_equal({"subs" => ["a", "b"]}, data)
|
53
55
|
end
|
54
56
|
|
55
57
|
|
56
58
|
def test_modify_only_and_ignored_data
|
59
|
+
Kronk::Cmd.expects :warn
|
57
60
|
data = @dataset_mock.modify :ignore_data => "subs/1", :only_data => "subs/1"
|
58
61
|
assert_equal({"subs" => [nil]}, data)
|
59
62
|
end
|
@@ -207,300 +210,4 @@ class TestDataSet < Test::Unit::TestCase
|
|
207
210
|
|
208
211
|
assert_equal expected, data
|
209
212
|
end
|
210
|
-
|
211
|
-
|
212
|
-
def test_find_data_index
|
213
|
-
keys = []
|
214
|
-
data_points = []
|
215
|
-
|
216
|
-
@dataset.find_data "*/*/0|1" do |data, key, path|
|
217
|
-
keys << key
|
218
|
-
data_points << data
|
219
|
-
end
|
220
|
-
|
221
|
-
assert_equal [0,1,0,1], keys
|
222
|
-
assert_equal 2, data_points.count(@data[:key1][:key1a])
|
223
|
-
assert_equal 2, data_points.count(@data[:key3][:key3a])
|
224
|
-
end
|
225
|
-
|
226
|
-
|
227
|
-
def test_find_data_recursive_wildcard_value
|
228
|
-
keys = []
|
229
|
-
paths = []
|
230
|
-
data_points = []
|
231
|
-
|
232
|
-
@dataset.find_data "**=foo*" do |data, key, path|
|
233
|
-
keys << key
|
234
|
-
data_points << data
|
235
|
-
paths << path
|
236
|
-
end
|
237
|
-
|
238
|
-
expected_paths = [[:key1,:key1a,0], [:key1,:key1a,2], [:key2]]
|
239
|
-
|
240
|
-
assert_equal [0,2,:key2], ([0,2,:key2] | keys)
|
241
|
-
assert_equal expected_paths, (expected_paths | paths)
|
242
|
-
end
|
243
|
-
|
244
|
-
|
245
|
-
def test_find_data_recursive
|
246
|
-
keys = []
|
247
|
-
paths = []
|
248
|
-
data_points = []
|
249
|
-
|
250
|
-
@dataset.find_data "**/findme" do |data, key, path|
|
251
|
-
keys << key.to_s
|
252
|
-
data_points << data
|
253
|
-
paths << path
|
254
|
-
end
|
255
|
-
|
256
|
-
expected_paths =
|
257
|
-
[[:key1,:key1a,3,:findme], ["findme"], ["findme",2,:findme]]
|
258
|
-
|
259
|
-
assert_equal 3, keys.length
|
260
|
-
assert_equal 1, keys.uniq.length
|
261
|
-
assert_equal "findme", keys.first
|
262
|
-
|
263
|
-
assert data_points.include?(@data)
|
264
|
-
assert data_points.include?(@data[:key1][:key1a].last)
|
265
|
-
assert data_points.include?(@data['findme'].last)
|
266
|
-
|
267
|
-
assert_equal expected_paths, (expected_paths | paths)
|
268
|
-
end
|
269
|
-
|
270
|
-
|
271
|
-
def test_find_data_wildcard
|
272
|
-
keys = []
|
273
|
-
data_points = []
|
274
|
-
|
275
|
-
@dataset.find_data "*/key1?" do |data, key, path|
|
276
|
-
keys << key.to_s
|
277
|
-
data_points << data
|
278
|
-
end
|
279
|
-
|
280
|
-
assert_equal ['key1a', 'key1b'], keys.sort
|
281
|
-
assert_equal [@data[:key1], @data[:key1]], data_points
|
282
|
-
end
|
283
|
-
|
284
|
-
|
285
|
-
def test_parse_data_path
|
286
|
-
data_path = "key1/key\\/2=value/key*=*value/**=value2/key\\=thing"
|
287
|
-
key, value, rec, data_path = @dataset.parse_data_path data_path
|
288
|
-
|
289
|
-
assert_equal "key1", key
|
290
|
-
assert_nil value
|
291
|
-
assert !rec, "Should not return recursive = true"
|
292
|
-
assert_equal "key\\/2=value/key*=*value/**=value2/key\\=thing", data_path
|
293
|
-
end
|
294
|
-
|
295
|
-
|
296
|
-
def test_parse_data_path_escaped_slash
|
297
|
-
key, value, rec, data_path =
|
298
|
-
@dataset.parse_data_path \
|
299
|
-
"key\\/2=value/key*=*value/**=value2/key\\=thing"
|
300
|
-
|
301
|
-
assert_equal "key/2", key
|
302
|
-
assert_equal "value", value
|
303
|
-
assert !rec, "Should not return recursive = true"
|
304
|
-
assert_equal "key*=*value/**=value2/key\\=thing", data_path
|
305
|
-
end
|
306
|
-
|
307
|
-
|
308
|
-
def test_parse_data_path_wildcard
|
309
|
-
key, value, rec, data_path = @dataset.parse_data_path "*/key1?"
|
310
|
-
|
311
|
-
assert_equal(/^(.*)$/i, key)
|
312
|
-
assert_nil value
|
313
|
-
assert !rec, "Should not return recursive = true"
|
314
|
-
assert_equal "key1?", data_path
|
315
|
-
end
|
316
|
-
|
317
|
-
|
318
|
-
def test_parse_data_path_recursive_value
|
319
|
-
key, value, rec, data_path =
|
320
|
-
@dataset.parse_data_path "**=value2/key\\=thing"
|
321
|
-
|
322
|
-
assert_equal(/.*/, key)
|
323
|
-
assert_equal "value2", value
|
324
|
-
assert rec, "Should return recursive = true"
|
325
|
-
assert_equal "key\\=thing", data_path
|
326
|
-
end
|
327
|
-
|
328
|
-
|
329
|
-
def test_parse_data_path_recursive
|
330
|
-
data_path = "**"
|
331
|
-
key, value, rec, data_path = @dataset.parse_data_path "**"
|
332
|
-
|
333
|
-
assert_equal(/.*/, key)
|
334
|
-
assert_nil value
|
335
|
-
assert rec, "Should return recursive = true"
|
336
|
-
assert_nil data_path
|
337
|
-
end
|
338
|
-
|
339
|
-
|
340
|
-
def test_parse_data_path_recursive_key
|
341
|
-
data_path = "**"
|
342
|
-
key, value, rec, data_path = @dataset.parse_data_path "**/key"
|
343
|
-
|
344
|
-
assert_equal "key", key
|
345
|
-
assert_nil value
|
346
|
-
assert rec, "Should return recursive = true"
|
347
|
-
assert_nil data_path
|
348
|
-
end
|
349
|
-
|
350
|
-
|
351
|
-
def test_parse_data_path_escaped_equal
|
352
|
-
key, value, rec, data_path = @dataset.parse_data_path "key\\=thing"
|
353
|
-
|
354
|
-
assert_equal "key=thing", key
|
355
|
-
assert_nil value
|
356
|
-
assert !rec, "Should not return recursive = true"
|
357
|
-
assert_equal nil, data_path
|
358
|
-
end
|
359
|
-
|
360
|
-
|
361
|
-
def test_parse_data_path_last
|
362
|
-
key, value, rec, data_path = @dataset.parse_data_path "key*"
|
363
|
-
|
364
|
-
assert_equal(/^(key.*)$/i, key)
|
365
|
-
assert_nil value
|
366
|
-
assert !rec, "Should not return recursive = true"
|
367
|
-
assert_equal nil, data_path
|
368
|
-
end
|
369
|
-
|
370
|
-
|
371
|
-
def test_parse_data_path_empty
|
372
|
-
key, value, rec, data_path = @dataset.parse_data_path ""
|
373
|
-
|
374
|
-
assert_equal nil, key
|
375
|
-
assert_nil value
|
376
|
-
assert !rec, "Should not return recursive = true"
|
377
|
-
assert_equal nil, data_path
|
378
|
-
end
|
379
|
-
|
380
|
-
|
381
|
-
def test_parse_path_item
|
382
|
-
assert_equal "foo", @dataset.parse_path_item("foo")
|
383
|
-
|
384
|
-
assert_equal(/^(foo.*bar)$/i, @dataset.parse_path_item("foo*bar"))
|
385
|
-
assert_equal(/^(foo|bar)$/i, @dataset.parse_path_item("foo|bar"))
|
386
|
-
assert_equal(/^(foo.?bar)$/i, @dataset.parse_path_item("foo?bar"))
|
387
|
-
|
388
|
-
assert_equal(/^(foo.?\?bar)$/i, @dataset.parse_path_item("foo?\\?bar"))
|
389
|
-
assert_equal(/^(key.*)$/i, @dataset.parse_path_item("key*"))
|
390
|
-
|
391
|
-
assert_equal "foo*bar", @dataset.parse_path_item("foo\\*bar")
|
392
|
-
assert_equal "foo|bar", @dataset.parse_path_item("foo\\|bar")
|
393
|
-
assert_equal "foo?bar", @dataset.parse_path_item("foo\\?bar")
|
394
|
-
|
395
|
-
assert_equal 1..3, @dataset.parse_path_item("1..3")
|
396
|
-
assert_equal 1...3, @dataset.parse_path_item("1...3")
|
397
|
-
assert_equal 3...6, @dataset.parse_path_item("3,3")
|
398
|
-
end
|
399
|
-
|
400
|
-
|
401
|
-
def test_yield_data_points
|
402
|
-
keys = []
|
403
|
-
|
404
|
-
@dataset.yield_data_points @data, /key/ do |data, key|
|
405
|
-
keys << key.to_s
|
406
|
-
assert_equal @data, data
|
407
|
-
end
|
408
|
-
|
409
|
-
assert_equal ['key1', 'key2', 'key3'], keys.sort
|
410
|
-
end
|
411
|
-
|
412
|
-
|
413
|
-
def test_yield_data_points_recursive
|
414
|
-
keys = []
|
415
|
-
data_points = []
|
416
|
-
|
417
|
-
@dataset.yield_data_points @data, :findme, nil, true do |data, key|
|
418
|
-
keys << key.to_s
|
419
|
-
data_points << data
|
420
|
-
end
|
421
|
-
|
422
|
-
assert_equal 3, keys.length
|
423
|
-
assert_equal 1, keys.uniq.length
|
424
|
-
assert_equal "findme", keys.first
|
425
|
-
|
426
|
-
assert_equal 3, data_points.length
|
427
|
-
assert data_points.include?(@data)
|
428
|
-
assert data_points.include?({:findme => "thing"})
|
429
|
-
assert data_points.include?({:findme => 123456})
|
430
|
-
end
|
431
|
-
|
432
|
-
|
433
|
-
def test_yield_data_points_value
|
434
|
-
keys = []
|
435
|
-
data_points = []
|
436
|
-
|
437
|
-
@dataset.yield_data_points @data, nil, "findme" do |data, key|
|
438
|
-
keys << key.to_s
|
439
|
-
data_points << data
|
440
|
-
end
|
441
|
-
|
442
|
-
assert keys.empty?
|
443
|
-
assert data_points.empty?
|
444
|
-
|
445
|
-
@dataset.yield_data_points @data, nil, "findme", true do |data, key|
|
446
|
-
keys << key.to_s
|
447
|
-
data_points << data
|
448
|
-
end
|
449
|
-
|
450
|
-
assert_equal ['key1b'], keys
|
451
|
-
assert_equal [@data[:key1]], data_points
|
452
|
-
end
|
453
|
-
|
454
|
-
|
455
|
-
def test_match_data_item
|
456
|
-
assert @dataset.match_data_item(:key, "key")
|
457
|
-
assert @dataset.match_data_item("key", :key)
|
458
|
-
|
459
|
-
assert @dataset.match_data_item(/key/, "foo_key")
|
460
|
-
assert !@dataset.match_data_item("foo_key", /key/)
|
461
|
-
assert @dataset.match_data_item(/key/, /key/)
|
462
|
-
|
463
|
-
assert @dataset.match_data_item(nil, "foo_key")
|
464
|
-
assert !@dataset.match_data_item("foo_key", nil)
|
465
|
-
|
466
|
-
assert @dataset.match_data_item(1..3, 1)
|
467
|
-
assert !@dataset.match_data_item(1, 1..3)
|
468
|
-
assert @dataset.match_data_item(1..3, 1..3)
|
469
|
-
end
|
470
|
-
|
471
|
-
|
472
|
-
def test_hash_each_data_item
|
473
|
-
hash = {
|
474
|
-
:a => 1,
|
475
|
-
:b => 2,
|
476
|
-
:c => 3
|
477
|
-
}
|
478
|
-
|
479
|
-
keys = []
|
480
|
-
values = []
|
481
|
-
|
482
|
-
@dataset.each_data_item hash do |key, val|
|
483
|
-
keys << key
|
484
|
-
values << val
|
485
|
-
end
|
486
|
-
|
487
|
-
assert_equal keys, (keys | hash.keys)
|
488
|
-
assert_equal values, (values | hash.values)
|
489
|
-
end
|
490
|
-
|
491
|
-
|
492
|
-
def test_array_each_data_item
|
493
|
-
ary = [:a, :b, :c]
|
494
|
-
|
495
|
-
keys = []
|
496
|
-
values = []
|
497
|
-
|
498
|
-
@dataset.each_data_item ary do |key, val|
|
499
|
-
keys << key
|
500
|
-
values << val
|
501
|
-
end
|
502
|
-
|
503
|
-
assert_equal [0,1,2], keys
|
504
|
-
assert_equal ary, values
|
505
|
-
end
|
506
213
|
end
|
data/test/test_diff.rb
CHANGED
@@ -75,16 +75,16 @@ class TestDiff < Test::Unit::TestCase
|
|
75
75
|
]
|
76
76
|
],
|
77
77
|
{
|
78
|
+
:tests => [
|
79
|
+
"D3a",
|
80
|
+
"D3b"
|
81
|
+
],
|
78
82
|
"test" => [
|
79
83
|
[
|
80
84
|
"D1a\\nContent goes here",
|
81
85
|
"D1b"
|
82
86
|
],
|
83
87
|
"D2"
|
84
|
-
],
|
85
|
-
:tests => [
|
86
|
-
"D3a",
|
87
|
-
"D3b"
|
88
88
|
]
|
89
89
|
}
|
90
90
|
],
|
@@ -93,14 +93,14 @@ class TestDiff < Test::Unit::TestCase
|
|
93
93
|
"b"
|
94
94
|
],
|
95
95
|
"tests" => {
|
96
|
+
:foo => :bar,
|
96
97
|
"test" => [
|
97
98
|
[
|
98
99
|
1,
|
99
100
|
2
|
100
101
|
],
|
101
102
|
2.123
|
102
|
-
]
|
103
|
-
:foo => :bar
|
103
|
+
]
|
104
104
|
}
|
105
105
|
}
|
106
106
|
STR
|
@@ -140,16 +140,16 @@ STR
|
|
140
140
|
]
|
141
141
|
],
|
142
142
|
{
|
143
|
+
:tests => [
|
144
|
+
String,
|
145
|
+
String
|
146
|
+
],
|
143
147
|
"test" => [
|
144
148
|
[
|
145
149
|
String,
|
146
150
|
String
|
147
151
|
],
|
148
152
|
String
|
149
|
-
],
|
150
|
-
:tests => [
|
151
|
-
String,
|
152
|
-
String
|
153
153
|
]
|
154
154
|
}
|
155
155
|
],
|
@@ -158,14 +158,14 @@ STR
|
|
158
158
|
String
|
159
159
|
],
|
160
160
|
"tests" => {
|
161
|
+
:foo => Symbol,
|
161
162
|
"test" => [
|
162
163
|
[
|
163
164
|
Fixnum,
|
164
165
|
Fixnum
|
165
166
|
],
|
166
167
|
Float
|
167
|
-
]
|
168
|
-
:foo => Symbol
|
168
|
+
]
|
169
169
|
}
|
170
170
|
}
|
171
171
|
STR
|
data/test/test_kronk.rb
CHANGED
@@ -486,6 +486,8 @@ STR
|
|
486
486
|
options = {}
|
487
487
|
argv = %w{this is --argv -- one -two -- -three four :parents :-not_parents}
|
488
488
|
|
489
|
+
Kronk::Cmd.expects(:warn).times(2)
|
490
|
+
|
489
491
|
options = Kronk::Cmd.parse_data_path_args options, argv
|
490
492
|
|
491
493
|
assert_equal %w{one four}, options[:only_data]
|
data/test/test_path.rb
ADDED
@@ -0,0 +1,370 @@
|
|
1
|
+
require 'test/test_helper'
|
2
|
+
|
3
|
+
class TestPath < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@data = {
|
7
|
+
:key1 => {
|
8
|
+
:key1a => [
|
9
|
+
"foo",
|
10
|
+
"bar",
|
11
|
+
"foobar",
|
12
|
+
{:findme => "thing"}
|
13
|
+
],
|
14
|
+
'key1b' => "findme"
|
15
|
+
},
|
16
|
+
'findme' => [
|
17
|
+
123,
|
18
|
+
456,
|
19
|
+
{:findme => 123456}
|
20
|
+
],
|
21
|
+
:key2 => "foobar",
|
22
|
+
:key3 => {
|
23
|
+
:key3a => ["val1", "val2", "val3"]
|
24
|
+
}
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
def test_each_data_item_hash
|
30
|
+
hash = {
|
31
|
+
:a => 1,
|
32
|
+
:b => 2,
|
33
|
+
:c => 3
|
34
|
+
}
|
35
|
+
|
36
|
+
keys = []
|
37
|
+
values = []
|
38
|
+
|
39
|
+
Kronk::Path.each_data_item hash do |key, val|
|
40
|
+
keys << key
|
41
|
+
values << val
|
42
|
+
end
|
43
|
+
|
44
|
+
assert_equal keys, (keys | hash.keys)
|
45
|
+
assert_equal values, (values | hash.values)
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
def test_each_data_item_array
|
50
|
+
ary = [:a, :b, :c]
|
51
|
+
|
52
|
+
keys = []
|
53
|
+
values = []
|
54
|
+
|
55
|
+
Kronk::Path.each_data_item ary do |key, val|
|
56
|
+
keys << key
|
57
|
+
values << val
|
58
|
+
end
|
59
|
+
|
60
|
+
assert_equal [2,1,0], keys
|
61
|
+
assert_equal ary.reverse, values
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
def test_match_data_item
|
66
|
+
assert Kronk::Path.match_data_item(:key, "key")
|
67
|
+
assert Kronk::Path.match_data_item("key", :key)
|
68
|
+
|
69
|
+
assert Kronk::Path.match_data_item(/key/, "foo_key")
|
70
|
+
assert !Kronk::Path.match_data_item("foo_key", /key/)
|
71
|
+
assert Kronk::Path.match_data_item(/key/, /key/)
|
72
|
+
|
73
|
+
assert Kronk::Path.match_data_item(Kronk::Path::ANY_VALUE, "foo_key")
|
74
|
+
assert !Kronk::Path.match_data_item("foo_key", Kronk::Path::ANY_VALUE)
|
75
|
+
|
76
|
+
assert Kronk::Path.match_data_item(1..3, 1)
|
77
|
+
assert !Kronk::Path.match_data_item(1, 1..3)
|
78
|
+
assert Kronk::Path.match_data_item(1..3, 1..3)
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
def test_find_match
|
83
|
+
keys = []
|
84
|
+
|
85
|
+
Kronk::Path.find_match @data, /key/ do |data, key|
|
86
|
+
keys << key.to_s
|
87
|
+
assert_equal @data, data
|
88
|
+
end
|
89
|
+
|
90
|
+
assert_equal ['key1', 'key2', 'key3'], keys.sort
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
def test_find_match_recursive
|
95
|
+
keys = []
|
96
|
+
data_points = []
|
97
|
+
|
98
|
+
Kronk::Path.find_match @data, :findme, ANY_VALUE, true do |data, key|
|
99
|
+
keys << key.to_s
|
100
|
+
data_points << data
|
101
|
+
end
|
102
|
+
|
103
|
+
assert_equal 3, keys.length
|
104
|
+
assert_equal 1, keys.uniq.length
|
105
|
+
assert_equal "findme", keys.first
|
106
|
+
|
107
|
+
assert_equal 3, data_points.length
|
108
|
+
assert data_points.include?(@data)
|
109
|
+
assert data_points.include?({:findme => "thing"})
|
110
|
+
assert data_points.include?({:findme => 123456})
|
111
|
+
end
|
112
|
+
|
113
|
+
|
114
|
+
def test_find_match_value
|
115
|
+
keys = []
|
116
|
+
data_points = []
|
117
|
+
|
118
|
+
Kronk::Path.find_match @data, ANY_VALUE, "findme" do |data, key|
|
119
|
+
keys << key.to_s
|
120
|
+
data_points << data
|
121
|
+
end
|
122
|
+
|
123
|
+
assert keys.empty?
|
124
|
+
assert data_points.empty?
|
125
|
+
|
126
|
+
Kronk::Path.find_match @data, ANY_VALUE, "findme", true do |data, key|
|
127
|
+
keys << key.to_s
|
128
|
+
data_points << data
|
129
|
+
end
|
130
|
+
|
131
|
+
assert_equal ['key1b'], keys
|
132
|
+
assert_equal [@data[:key1]], data_points
|
133
|
+
end
|
134
|
+
|
135
|
+
|
136
|
+
def test_find_wildcard
|
137
|
+
keys = []
|
138
|
+
data_points = []
|
139
|
+
|
140
|
+
Kronk::Path.find "*/key1?", @data do |data, key, path|
|
141
|
+
keys << key.to_s
|
142
|
+
data_points << data
|
143
|
+
end
|
144
|
+
|
145
|
+
assert_equal ['key1a', 'key1b'], keys.sort
|
146
|
+
assert_equal [@data[:key1], @data[:key1]], data_points
|
147
|
+
end
|
148
|
+
|
149
|
+
|
150
|
+
def test_find_recursive
|
151
|
+
keys = []
|
152
|
+
paths = []
|
153
|
+
data_points = []
|
154
|
+
|
155
|
+
Kronk::Path.find "**/findme", @data do |data, key, path|
|
156
|
+
keys << key.to_s
|
157
|
+
data_points << data
|
158
|
+
paths << path
|
159
|
+
end
|
160
|
+
|
161
|
+
expected_paths =
|
162
|
+
[[:key1,:key1a,3,:findme], ["findme"], ["findme",2,:findme]]
|
163
|
+
|
164
|
+
assert_equal 3, keys.length
|
165
|
+
assert_equal 1, keys.uniq.length
|
166
|
+
assert_equal "findme", keys.first
|
167
|
+
|
168
|
+
assert data_points.include?(@data)
|
169
|
+
assert data_points.include?(@data[:key1][:key1a].last)
|
170
|
+
assert data_points.include?(@data['findme'].last)
|
171
|
+
|
172
|
+
assert_equal expected_paths, (expected_paths | paths)
|
173
|
+
end
|
174
|
+
|
175
|
+
|
176
|
+
def test_find_index
|
177
|
+
keys = []
|
178
|
+
data_points = []
|
179
|
+
|
180
|
+
Kronk::Path.find "*/*/0|1", @data do |data, key, path|
|
181
|
+
keys << key
|
182
|
+
data_points << data
|
183
|
+
end
|
184
|
+
|
185
|
+
assert_equal [1,0,1,0], keys
|
186
|
+
assert_equal 2, data_points.count(@data[:key1][:key1a])
|
187
|
+
assert_equal 2, data_points.count(@data[:key3][:key3a])
|
188
|
+
end
|
189
|
+
|
190
|
+
|
191
|
+
def test_find_data_recursive_wildcard_value
|
192
|
+
keys = []
|
193
|
+
paths = []
|
194
|
+
data_points = []
|
195
|
+
|
196
|
+
Kronk::Path.find "**=foo*", @data do |data, key, path|
|
197
|
+
keys << key
|
198
|
+
data_points << data
|
199
|
+
paths << path
|
200
|
+
end
|
201
|
+
|
202
|
+
expected_paths = [[:key1,:key1a,0], [:key1,:key1a,2], [:key2]]
|
203
|
+
|
204
|
+
assert_equal [0,2,:key2], ([0,2,:key2] | keys)
|
205
|
+
assert_equal expected_paths, (expected_paths | paths)
|
206
|
+
end
|
207
|
+
|
208
|
+
|
209
|
+
def test_parse_path_item_range
|
210
|
+
assert_equal 1..4, Kronk::Path.parse_path_item("1..4")
|
211
|
+
assert_equal 1...4, Kronk::Path.parse_path_item("1...4")
|
212
|
+
assert_equal "1..4", Kronk::Path.parse_path_item("\\1..4")
|
213
|
+
assert_equal "1..4", Kronk::Path.parse_path_item("1\\..4")
|
214
|
+
assert_equal "1..4", Kronk::Path.parse_path_item("1.\\.4")
|
215
|
+
assert_equal "1..4", Kronk::Path.parse_path_item("1..\\4")
|
216
|
+
assert_equal "1..4", Kronk::Path.parse_path_item("1..4\\")
|
217
|
+
end
|
218
|
+
|
219
|
+
|
220
|
+
def test_parse_path_item_index_length
|
221
|
+
assert_equal 2...6, Kronk::Path.parse_path_item("2,4")
|
222
|
+
assert_equal "2,4", Kronk::Path.parse_path_item("\\2,4")
|
223
|
+
assert_equal "2,4", Kronk::Path.parse_path_item("2\\,4")
|
224
|
+
assert_equal "2,4", Kronk::Path.parse_path_item("2,\\4")
|
225
|
+
assert_equal "2,4", Kronk::Path.parse_path_item("2,4\\")
|
226
|
+
end
|
227
|
+
|
228
|
+
|
229
|
+
def test_parse_path_item_anyval
|
230
|
+
assert_equal Kronk::Path::ANY_VALUE, Kronk::Path.parse_path_item("*")
|
231
|
+
assert_equal Kronk::Path::ANY_VALUE, Kronk::Path.parse_path_item("")
|
232
|
+
assert_equal Kronk::Path::ANY_VALUE, Kronk::Path.parse_path_item("**?*?*?")
|
233
|
+
assert_equal Kronk::Path::ANY_VALUE, Kronk::Path.parse_path_item(nil)
|
234
|
+
end
|
235
|
+
|
236
|
+
|
237
|
+
def test_parse_path_item_regex
|
238
|
+
assert_equal(/\A(test.*)\Z/, Kronk::Path.parse_path_item("test*"))
|
239
|
+
assert_equal(/\A(.?test.*)\Z/, Kronk::Path.parse_path_item("?test*"))
|
240
|
+
assert_equal(/\A(\?test.*)\Z/, Kronk::Path.parse_path_item("\\?test*"))
|
241
|
+
assert_equal(/\A(.?test\*.*)\Z/, Kronk::Path.parse_path_item("?test\\**"))
|
242
|
+
assert_equal(/\A(.?test.*)\Z/, Kronk::Path.parse_path_item("?test*?**??"))
|
243
|
+
assert_equal(/\A(a|b)\Z/, Kronk::Path.parse_path_item("a|b"))
|
244
|
+
assert_equal(/\A(a|b(c|d))\Z/, Kronk::Path.parse_path_item("a|b(c|d)"))
|
245
|
+
|
246
|
+
assert_equal(/\A(a|b(c|d))\Z/i,
|
247
|
+
Kronk::Path.parse_path_item("a|b(c|d)", Regexp::IGNORECASE))
|
248
|
+
end
|
249
|
+
|
250
|
+
|
251
|
+
def test_parse_path_item_string
|
252
|
+
assert_equal "a|b", Kronk::Path.parse_path_item("a\\|b")
|
253
|
+
assert_equal "a(b", Kronk::Path.parse_path_item("a\\(b")
|
254
|
+
assert_equal "a?b", Kronk::Path.parse_path_item("a\\?b")
|
255
|
+
assert_equal "a*b", Kronk::Path.parse_path_item("a\\*b")
|
256
|
+
end
|
257
|
+
|
258
|
+
|
259
|
+
def test_parse_path_item_passthru
|
260
|
+
assert_equal Kronk::Path::PARENT,
|
261
|
+
Kronk::Path.parse_path_item(Kronk::Path::PARENT)
|
262
|
+
|
263
|
+
assert_equal :thing, Kronk::Path.parse_path_item(:thing)
|
264
|
+
end
|
265
|
+
|
266
|
+
|
267
|
+
def test_parse_path_str_yield
|
268
|
+
all_args = []
|
269
|
+
|
270
|
+
Kronk::Path.parse_path_str "path/**/to=foo/item" do |*args|
|
271
|
+
all_args << args
|
272
|
+
end
|
273
|
+
|
274
|
+
expected = [
|
275
|
+
["path", ANY_VALUE, false, false],
|
276
|
+
["to", "foo", true, false],
|
277
|
+
["item", ANY_VALUE, false, true],
|
278
|
+
]
|
279
|
+
|
280
|
+
assert_equal expected, all_args
|
281
|
+
end
|
282
|
+
|
283
|
+
|
284
|
+
def test_parse_path_str_simple
|
285
|
+
assert_path %w{path to item}, "path/to/item"
|
286
|
+
assert_path %w{path to item}, "///path//to/././item///"
|
287
|
+
assert_path %w{path to item}, "///path//to/./item///"
|
288
|
+
assert_path %w{path/to item}, "path\\/to/item"
|
289
|
+
|
290
|
+
assert_path %w{path/to item/ i}, "path\\/to/item\\//i"
|
291
|
+
|
292
|
+
assert_path [/\A(path\/\.to)\Z/i, /\A(item)\Z/i],
|
293
|
+
"path\\/.to/item", Regexp::IGNORECASE
|
294
|
+
|
295
|
+
assert_path ['path', /\A(to|for)\Z/, 'item'], "path/to|for/item"
|
296
|
+
end
|
297
|
+
|
298
|
+
|
299
|
+
def test_parse_path_str_value
|
300
|
+
assert_path ['path', ['to', 'foo'], 'item'], "path/to=foo/item"
|
301
|
+
assert_path ['path', [nil, 'foo'], 'item'], "path/*=foo/item"
|
302
|
+
assert_path ['path', [nil, 'foo'], 'item'], "path/=foo/item"
|
303
|
+
|
304
|
+
assert_path ['path', ['to', /\A(foo|bar)\Z/], 'item'],
|
305
|
+
"path/to=foo|bar/item"
|
306
|
+
|
307
|
+
assert_path [/\A(path)\Z/i, [/\A(to)\Z/i, /\A(foo)\Z/i], /\A(item)\Z/i],
|
308
|
+
"path/to=foo/item", Regexp::IGNORECASE
|
309
|
+
end
|
310
|
+
|
311
|
+
|
312
|
+
def test_parse_path_str_recur
|
313
|
+
assert_path ['path', ['to', 'foo', true], 'item'], "path/**/to=foo/item"
|
314
|
+
assert_path [['path', nil, true], 'to', 'item'], "**/**/path/to/item"
|
315
|
+
assert_path ['path', 'to', 'item', [nil, nil, true]], "path/to/item/**/**"
|
316
|
+
assert_path ['path', [nil, 'foo', true], 'item'], "path/**=foo/item"
|
317
|
+
end
|
318
|
+
|
319
|
+
|
320
|
+
def test_parse_path_str_parent
|
321
|
+
assert_path ['path', PARENT, 'item'], "path/../item"
|
322
|
+
assert_path ['path', [PARENT, 'foo'], 'item'], "path/..=foo/item"
|
323
|
+
assert_path ['path', [nil, 'foo', true], 'item'], "path/**/..=foo/item"
|
324
|
+
assert_path ['path', [nil, 'foo', true], 'item'], "path/**/=foo/item"
|
325
|
+
assert_path ['path', ['item', nil, true]], "path/**/../item"
|
326
|
+
assert_path ['path', PARENT, ['item', nil, true]], "path/../**/item"
|
327
|
+
end
|
328
|
+
|
329
|
+
|
330
|
+
def test_parse_regex_opts
|
331
|
+
path = "path/to/item///mix"
|
332
|
+
opts = Kronk::Path.parse_regex_opts! path
|
333
|
+
|
334
|
+
assert_equal "path/to/item/", path
|
335
|
+
|
336
|
+
expected_opts = Regexp::IGNORECASE | Regexp::EXTENDED | Regexp::MULTILINE
|
337
|
+
assert_equal expected_opts, opts
|
338
|
+
end
|
339
|
+
|
340
|
+
|
341
|
+
def test_parse_regex_opts_mix
|
342
|
+
opts = Kronk::Path.parse_regex_opts! "path/to/item//m", Regexp::EXTENDED
|
343
|
+
assert_equal Regexp::EXTENDED | Regexp::MULTILINE, opts
|
344
|
+
end
|
345
|
+
|
346
|
+
|
347
|
+
def test_parse_regex_opts_none
|
348
|
+
assert_nil Kronk::Path.parse_regex_opts!("path/to/item//")
|
349
|
+
assert_equal Regexp::EXTENDED,
|
350
|
+
Kronk::Path.parse_regex_opts!("path/to/item//", Regexp::EXTENDED)
|
351
|
+
end
|
352
|
+
|
353
|
+
|
354
|
+
private
|
355
|
+
|
356
|
+
PARENT = Kronk::Path::PARENT
|
357
|
+
ANY_VALUE = Kronk::Path::ANY_VALUE
|
358
|
+
|
359
|
+
def assert_path match, path, regexp_opt=nil
|
360
|
+
match.map! do |i|
|
361
|
+
i = [i] unless Array === i
|
362
|
+
i[0] ||= ANY_VALUE
|
363
|
+
i[1] ||= ANY_VALUE
|
364
|
+
i[2] ||= false
|
365
|
+
i
|
366
|
+
end
|
367
|
+
|
368
|
+
assert_equal match, Kronk::Path.parse_path_str(path, regexp_opt)
|
369
|
+
end
|
370
|
+
end
|