kronk 1.6.2 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/History.rdoc +29 -1
  2. data/Manifest.txt +6 -1
  3. data/README.rdoc +74 -28
  4. data/Rakefile +4 -3
  5. data/TODO.rdoc +7 -5
  6. data/bin/kronk +2 -11
  7. data/lib/kronk/async/em_ext.rb +34 -0
  8. data/lib/kronk/async/request.rb +73 -0
  9. data/lib/kronk/async/response.rb +70 -0
  10. data/lib/kronk/async.rb +118 -0
  11. data/lib/kronk/cmd.rb +111 -43
  12. data/lib/kronk/constants.rb +1 -0
  13. data/lib/kronk/core_ext.rb +1 -1
  14. data/lib/kronk/data_string.rb +251 -0
  15. data/lib/kronk/diff/output.rb +132 -100
  16. data/lib/kronk/diff.rb +20 -24
  17. data/lib/kronk/path/matcher.rb +8 -4
  18. data/lib/kronk/path/path_match.rb +48 -4
  19. data/lib/kronk/path/transaction.rb +74 -53
  20. data/lib/kronk/path.rb +11 -6
  21. data/lib/kronk/player/benchmark.rb +11 -12
  22. data/lib/kronk/player/input_reader.rb +40 -3
  23. data/lib/kronk/player/request_parser.rb +4 -1
  24. data/lib/kronk/player/stream.rb +2 -2
  25. data/lib/kronk/player/suite.rb +16 -9
  26. data/lib/kronk/player.rb +93 -143
  27. data/lib/kronk/queue_runner.rb +238 -0
  28. data/lib/kronk/request.rb +25 -20
  29. data/lib/kronk/response.rb +39 -10
  30. data/lib/kronk/test/assertions.rb +2 -2
  31. data/lib/kronk/test/helper_methods.rb +1 -1
  32. data/lib/kronk.rb +56 -24
  33. data/test/test_assertions.rb +4 -4
  34. data/test/test_cmd.rb +38 -10
  35. data/test/test_data_string.rb +242 -1
  36. data/test/test_diff.rb +8 -303
  37. data/test/test_helper.rb +1 -1
  38. data/test/test_kronk.rb +21 -28
  39. data/test/test_path.rb +29 -0
  40. data/test/test_path_match.rb +47 -2
  41. data/test/test_path_matcher.rb +42 -1
  42. data/test/test_player.rb +71 -72
  43. data/test/test_request.rb +31 -6
  44. data/test/test_request_parser.rb +7 -1
  45. data/test/test_response.rb +1 -1
  46. data/test/test_transaction.rb +78 -30
  47. metadata +64 -8
  48. data/lib/kronk/data_renderer.rb +0 -219
data/test/test_diff.rb CHANGED
@@ -39,306 +39,8 @@ class TestDiff < Test::Unit::TestCase
39
39
 
40
40
  diff = Kronk::Diff.new_from_data mock_data, other_data
41
41
 
42
- assert_equal Kronk::Diff.ordered_data_string(mock_data), diff.str1
43
- assert_equal Kronk::Diff.ordered_data_string(other_data), diff.str2
44
- end
45
-
46
-
47
- def test_ordered_data_string_json
48
- expected = <<STR
49
- {
50
- "acks": [
51
- [
52
- 56,
53
- 78
54
- ],
55
- [
56
- "12",
57
- "34"
58
- ]
59
- ],
60
- "root": [
61
- [
62
- "B1",
63
- "B2"
64
- ],
65
- [
66
- "A1",
67
- "A2"
68
- ],
69
- [
70
- "C1",
71
- "C2",
72
- [
73
- "C3a",
74
- "C3b"
75
- ]
76
- ],
77
- {
78
- ":tests": [
79
- "D3a",
80
- "D3b"
81
- ],
82
- "test": [
83
- [
84
- "D1a\\nContent goes here",
85
- "D1b"
86
- ],
87
- "D2"
88
- ]
89
- }
90
- ],
91
- "subs": [
92
- "a",
93
- "b"
94
- ],
95
- "tests": {
96
- ":foo": ":bar",
97
- "test": [
98
- [
99
- 1,
100
- 2
101
- ],
102
- 2.123
103
- ]
104
- }
105
- }
106
- STR
107
-
108
- assert_equal expected.strip, Kronk::Diff.ordered_data_string(mock_data)
109
- end
110
-
111
-
112
- def test_ordered_data_string_struct_json
113
- expected = <<STR
114
- {
115
- "acks": [
116
- [
117
- "Fixnum",
118
- "Fixnum"
119
- ],
120
- [
121
- "String",
122
- "String"
123
- ]
124
- ],
125
- "root": [
126
- [
127
- "String",
128
- "String"
129
- ],
130
- [
131
- "String",
132
- "String"
133
- ],
134
- [
135
- "String",
136
- "String",
137
- [
138
- "String",
139
- "String"
140
- ]
141
- ],
142
- {
143
- ":tests": [
144
- "String",
145
- "String"
146
- ],
147
- "test": [
148
- [
149
- "String",
150
- "String"
151
- ],
152
- "String"
153
- ]
154
- }
155
- ],
156
- "subs": [
157
- "String",
158
- "String"
159
- ],
160
- "tests": {
161
- ":foo": "Symbol",
162
- "test": [
163
- [
164
- "Fixnum",
165
- "Fixnum"
166
- ],
167
- "Float"
168
- ]
169
- }
170
- }
171
- STR
172
-
173
- assert_equal expected.strip,
174
- Kronk::Diff.ordered_data_string(mock_data, true)
175
- end
176
-
177
- def test_ordered_data_string_json
178
- expected = <<STR
179
- {
180
- "acks": [
181
- [
182
- 56,
183
- 78
184
- ],
185
- [
186
- "12",
187
- "34"
188
- ]
189
- ],
190
- "root": [
191
- [
192
- "B1",
193
- "B2"
194
- ],
195
- [
196
- "A1",
197
- "A2"
198
- ],
199
- [
200
- "C1",
201
- "C2",
202
- [
203
- "C3a",
204
- "C3b"
205
- ]
206
- ],
207
- {
208
- ":tests": [
209
- "D3a",
210
- "D3b"
211
- ],
212
- "test": [
213
- [
214
- "D1a\\nContent goes here",
215
- "D1b"
216
- ],
217
- "D2"
218
- ]
219
- }
220
- ],
221
- "subs": [
222
- "a",
223
- "b"
224
- ],
225
- "tests": {
226
- ":foo": ":bar",
227
- "test": [
228
- [
229
- 1,
230
- 2
231
- ],
232
- 2.123
233
- ]
234
- }
235
- }
236
- STR
237
-
238
- assert_equal expected.strip, Kronk::Diff.ordered_data_string(mock_data)
239
- end
240
-
241
-
242
- def test_ordered_data_string_ruby_paths
243
- with_config :render_lang => 'ruby', :render_paths => true do
244
- expected = <<STR
245
- {
246
- "/acks/0/0" => 56,
247
- "/acks/0/1" => 78,
248
- "/acks/1/0" => "12",
249
- "/acks/1/1" => "34",
250
- "/root/0/0" => "B1",
251
- "/root/0/1" => "B2",
252
- "/root/1/0" => "A1",
253
- "/root/1/1" => "A2",
254
- "/root/2/0" => "C1",
255
- "/root/2/1" => "C2",
256
- "/root/2/2/0" => "C3a",
257
- "/root/2/2/1" => "C3b",
258
- "/root/3/test/0/0" => "D1a\\nContent goes here",
259
- "/root/3/test/0/1" => "D1b",
260
- "/root/3/test/1" => "D2",
261
- "/root/3/tests/0" => "D3a",
262
- "/root/3/tests/1" => "D3b",
263
- "/subs/0" => "a",
264
- "/subs/1" => "b",
265
- "/tests/foo" => :bar,
266
- "/tests/test/0/0" => 1,
267
- "/tests/test/0/1" => 2,
268
- "/tests/test/1" => 2.123
269
- }
270
- STR
271
-
272
- assert_equal expected.strip, Kronk::Diff.ordered_data_string(mock_data)
273
- end
274
- end
275
-
276
-
277
- def test_ordered_data_string_struct_ruby
278
- with_config :render_lang => 'ruby' do
279
- expected = <<STR
280
- {
281
- "acks" => [
282
- [
283
- Fixnum,
284
- Fixnum
285
- ],
286
- [
287
- String,
288
- String
289
- ]
290
- ],
291
- "root" => [
292
- [
293
- String,
294
- String
295
- ],
296
- [
297
- String,
298
- String
299
- ],
300
- [
301
- String,
302
- String,
303
- [
304
- String,
305
- String
306
- ]
307
- ],
308
- {
309
- :tests => [
310
- String,
311
- String
312
- ],
313
- "test" => [
314
- [
315
- String,
316
- String
317
- ],
318
- String
319
- ]
320
- }
321
- ],
322
- "subs" => [
323
- String,
324
- String
325
- ],
326
- "tests" => {
327
- :foo => Symbol,
328
- "test" => [
329
- [
330
- Fixnum,
331
- Fixnum
332
- ],
333
- Float
334
- ]
335
- }
336
- }
337
- STR
338
-
339
- assert_equal expected.strip,
340
- Kronk::Diff.ordered_data_string(mock_data, true)
341
- end
42
+ assert_equal Kronk::DataString.new(mock_data), diff.str1
43
+ assert_equal Kronk::DataString.new(other_data), diff.str2
342
44
  end
343
45
 
344
46
 
@@ -579,7 +281,7 @@ STR
579
281
  (<<-STR
580
282
  \e[1;33m--- test/mocks/200_response_diff.json
581
283
  +++ test/mocks/200_response.json\e[0m
582
- \e[1;35m@@ -6,7 +6,7 @@\e[0m business/description
284
+ \e[1;35m@@ -6,7 +6,7 @@\e[0m /business/description
583
285
  "additional_urls": [
584
286
  {
585
287
  "destination": "http://example.com",
@@ -588,7 +290,7 @@ STR
588
290
  }
589
291
  ],
590
292
  "general_info": "<p>A Paint Your Own Pottery Studios..</p>",
591
- \e[1;35m@@ -15,11 +15,12 @@\e[0m business/description
293
+ \e[1;35m@@ -15,11 +15,12 @@\e[0m /business/description
592
294
  "slogan": "<p>Pottery YOU dress up</p>"
593
295
  },
594
296
  "distance": 0.0,
@@ -603,7 +305,7 @@ STR
603
305
  "improvable": true,
604
306
  "latitude": 42.882561,
605
307
  "listing_id": "1234",
606
- \e[1;35m@@ -34,12 +35,12 @@\e[0m business
308
+ \e[1;35m@@ -34,12 +35,12 @@\e[0m /business
607
309
  "rating_count": 0,
608
310
  "red_listing": false,
609
311
  "state": "MI",
@@ -667,6 +369,7 @@ STR
667
369
  str = <<STR
668
370
  --- left
669
371
  +++ right
372
+ @@ -1,17 +1,16 @@
670
373
  - HTTP/1.1 302 Found
671
374
  - Location: http://igoogle.com/
672
375
  + HTTP/1.1 301 Moved Permanently
@@ -698,6 +401,7 @@ STR
698
401
  str = <<STR
699
402
  --- left
700
403
  +++ right
404
+ @@ -1,17 +1,16 @@
701
405
  1| - HTTP/1.1 302 Found
702
406
  2| - Location: http://igoogle.com/
703
407
  | 1 + HTTP/1.1 301 Moved Permanently
@@ -730,6 +434,7 @@ STR
730
434
  str = <<STR
731
435
  \e[1;33m--- left
732
436
  +++ right\033[0m
437
+ \e[1;35m@@ -1,17 +1,16 @@\e[0m
733
438
  \033[1;31m- HTTP/1.1 302 Found\033[0m
734
439
  \033[1;31m- Location: http://igoogle.com/\033[0m
735
440
  \033[1;32m+ HTTP/1.1 301 Moved Permanently\033[0m
data/test/test_helper.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require "test/unit"
2
- require "kronk"
2
+ require "kronk/async"
3
3
  require "mocha"
4
4
 
5
5
  Kronk.config[:context] = nil
data/test/test_kronk.rb CHANGED
@@ -4,6 +4,7 @@ class TestKronk < Test::Unit::TestCase
4
4
 
5
5
  def test_default_config
6
6
  expected = {
7
+ :async => 'auto',
7
8
  :content_types => {
8
9
  'js' => 'JSON',
9
10
  'json' => 'JSON',
@@ -31,6 +32,7 @@ class TestKronk < Test::Unit::TestCase
31
32
  def test_load_config
32
33
  with_config do
33
34
  mock_config = {
35
+ :async => false,
34
36
  :content_types => {
35
37
  'soap' => "SOAPParser",
36
38
  'js' => "JsEngine"
@@ -60,6 +62,7 @@ class TestKronk < Test::Unit::TestCase
60
62
  Kronk.load_config "foobar"
61
63
 
62
64
  expected = {
65
+ :async => false,
63
66
  :content_types => {
64
67
  'soap' => "SOAPParser",
65
68
  'js' => "JsEngine",
@@ -80,7 +83,7 @@ class TestKronk < Test::Unit::TestCase
80
83
  :ignore_headers => ["Content-Type"],
81
84
  :uri_options => {'example.com' => {:parser => 'JSON'}},
82
85
  :user_agents =>
83
- Kronk::USER_AGENTS.merge(:win_ie6 => 'piece of crap browser'),
86
+ Kronk::USER_AGENTS.merge('win_ie6' => 'piece of crap browser'),
84
87
  :foo => :bar
85
88
  }
86
89
 
@@ -365,11 +368,11 @@ class TestKronk < Test::Unit::TestCase
365
368
  :show_headers => true,
366
369
  :raw => true
367
370
 
368
- resp1 = Kronk.retrieve "test/mocks/200_response.json",
371
+ resp1 = Kronk.request "test/mocks/200_response.json",
369
372
  :show_headers => true,
370
373
  :raw => true
371
374
 
372
- resp2 = Kronk.retrieve "test/mocks/200_response.xml",
375
+ resp2 = Kronk.request "test/mocks/200_response.xml",
373
376
  :show_headers => true,
374
377
  :raw => true
375
378
 
@@ -446,10 +449,10 @@ class TestKronk < Test::Unit::TestCase
446
449
  "test/mocks/200_response.xml",
447
450
  :show_headers => true
448
451
 
449
- resp1 = Kronk.retrieve "test/mocks/200_response.json",
452
+ resp1 = Kronk.request "test/mocks/200_response.json",
450
453
  :show_headers => true
451
454
 
452
- resp2 = Kronk.retrieve "test/mocks/200_response.xml",
455
+ resp2 = Kronk.request "test/mocks/200_response.xml",
453
456
  :show_headers => true
454
457
 
455
458
  exp_diff = Kronk::Diff.new_from_data \
@@ -469,13 +472,15 @@ class TestKronk < Test::Unit::TestCase
469
472
  req = Kronk::Request.new "http://www.google.com/"
470
473
  req.stubs(:retrieve).returns res
471
474
 
472
- Kronk::Request.stubs(:new).with("http://www.google.com/",{}).returns req
475
+ Kronk::Request.stubs(:new).
476
+ with("http://www.google.com/",{:follow_redirects => true}).returns req
477
+
473
478
  Kronk::Request.expects(:new).
474
479
  with("http://www.google.com/", :follow_redirects => true).returns req
475
480
 
476
481
  assert_raises Timeout::Error do
477
482
  timeout(2) do
478
- Kronk.retrieve "http://www.google.com/", :follow_redirects => true
483
+ Kronk.request "http://www.google.com/", :follow_redirects => true
479
484
  end
480
485
  end
481
486
  end
@@ -487,38 +492,39 @@ class TestKronk < Test::Unit::TestCase
487
492
  req.stubs(:retrieve).returns res
488
493
 
489
494
  Kronk::Request.expects(:new).
490
- with("http://www.google.com/",{}).returns(req).times(3)
495
+ with("http://www.google.com/",{:follow_redirects => 3}).returns(req).
496
+ times(3)
491
497
 
492
498
  Kronk::Request.expects(:new).
493
499
  with("http://www.google.com/", :follow_redirects => 3).returns req
494
500
 
495
- Kronk.retrieve "http://www.google.com/", :follow_redirects => 3
501
+ Kronk.request "http://www.google.com/", :follow_redirects => 3
496
502
  end
497
503
 
498
504
 
499
505
  def test_follow_redirect_no_redirect
500
506
  res = Kronk::Response.new mock_200_response
501
507
  req = Kronk::Request.new "http://www.google.com/"
502
- req.stubs(:retrieve).returns res
508
+ req.stubs(:request).returns res
503
509
 
504
510
  Kronk::Request.expects(:new).with("http://www.google.com/",{}).never
505
511
  Kronk::Request.expects(:new).
506
512
  with("http://www.google.com/", :follow_redirects => true).returns req
507
513
 
508
- Kronk.retrieve "http://www.google.com/", :follow_redirects => true
514
+ Kronk.request "http://www.google.com/", :follow_redirects => true
509
515
  end
510
516
 
511
517
 
512
518
  def test_do_not_follow_redirect
513
519
  res = Kronk::Response.new mock_302_response
514
520
  req = Kronk::Request.new "http://www.google.com/"
515
- req.stubs(:retrieve).returns res
521
+ req.stubs(:request).returns res
516
522
 
517
523
  Kronk::Request.expects(:new).with("http://www.google.com/",{}).never
518
524
  Kronk::Request.expects(:new).
519
525
  with("http://www.google.com/", :follow_redirects => false).returns req
520
526
 
521
- Kronk.retrieve "http://www.google.com/", :follow_redirects => false
527
+ Kronk.request "http://www.google.com/", :follow_redirects => false
522
528
  end
523
529
 
524
530
 
@@ -536,8 +542,8 @@ class TestKronk < Test::Unit::TestCase
536
542
  assert_equal 2, kronk.responses.length
537
543
  assert_equal diff, kronk.diff
538
544
 
539
- resp1 = kronk.retrieve "test/mocks/200_response.xml"
540
- resp2 = kronk.retrieve "test/mocks/200_response.json"
545
+ resp1 = kronk.request "test/mocks/200_response.xml"
546
+ resp2 = kronk.request "test/mocks/200_response.json"
541
547
 
542
548
  assert_equal json_resp.raw, kronk.response.raw
543
549
  assert_equal json_resp.raw, kronk.responses.last.raw
@@ -557,19 +563,6 @@ class TestKronk < Test::Unit::TestCase
557
563
  end
558
564
 
559
565
 
560
- def test_parse_data_path_args
561
- options = {}
562
- argv = %w{this is --argv -- one -two -- -three four}
563
-
564
- options = Kronk::Cmd.parse_data_path_args options, argv
565
-
566
- assert_equal %w{one four}, options[:only_data]
567
- assert_equal %w{two - three}, options[:ignore_data]
568
-
569
- assert_equal %w{this is --argv}, argv
570
- end
571
-
572
-
573
566
  private
574
567
 
575
568
  def mock_uri_options
data/test/test_path.rb CHANGED
@@ -63,6 +63,35 @@ class TestPath < Test::Unit::TestCase
63
63
  assert data_points.include?(@data['findme'].last)
64
64
 
65
65
  assert_equal expected_paths, (expected_paths | paths)
66
+
67
+ splat_path = paths.find{|pa| pa[0] == :key1}
68
+ assert_equal [:key1, :key1a, 3], splat_path.splat[0][1]
69
+ end
70
+
71
+
72
+ def test_find_recursive_many_splat
73
+ path_match = nil
74
+
75
+ Kronk::Path.find "**/key1a/**=thing", @data do |data, key, path|
76
+ path_match = path
77
+ end
78
+
79
+ assert path_match
80
+ assert_equal [:key1], path_match.splat[0][1]
81
+ assert_equal [3], path_match.splat[1][1]
82
+ end
83
+
84
+
85
+ def test_find_recursive_many_splat_end_match
86
+ path_match = nil
87
+
88
+ Kronk::Path.find "**/key1a/**/*=thing", @data do |data, key, path|
89
+ path_match = path
90
+ end
91
+
92
+ assert path_match
93
+ assert_equal [:key1], path_match.splat[0][1]
94
+ assert_equal [3], path_match.splat[1][1]
66
95
  end
67
96
 
68
97
 
@@ -5,6 +5,12 @@ class TestPathMatch < Test::Unit::TestCase
5
5
  def setup
6
6
  @pmatch = Kronk::Path::PathMatch.new %w{path to resource}
7
7
  @pmatch.matches = %w{this is 4 foo}
8
+
9
+ @splat = @pmatch.dup
10
+ @splat.append_splat "first", "path"
11
+ @splat.append_splat "first", "to"
12
+ @splat.append_splat "second", "resource"
13
+ @splat.append_splat "second", "bar"
8
14
  end
9
15
 
10
16
 
@@ -29,9 +35,24 @@ class TestPathMatch < Test::Unit::TestCase
29
35
  end
30
36
 
31
37
 
32
- def test_make_path_bad_token
38
+ def test_make_path_consecutive
39
+ path = @pmatch.make_path "/%3%4/2/path/%1"
40
+ assert_equal %w{4foo 2 path this}, path
41
+ end
42
+
43
+
44
+ def test_make_path_no_splat
33
45
  path = @pmatch.make_path "/%%3/2/path/%4_%1"
34
- assert_equal %w{4 2 path foo_this}, path
46
+ assert_equal %w{3 2 path foo_this}, path
47
+ end
48
+
49
+
50
+ def test_make_path_consecutive_no_splat
51
+ path = @pmatch.make_path "/%%%4/2/path/%1"
52
+ assert_equal %w{foo 2 path this}, path
53
+
54
+ path = @pmatch.make_path "/%4%%/2/path/%1"
55
+ assert_equal %w{foo 2 path this}, path
35
56
  end
36
57
 
37
58
 
@@ -57,4 +78,28 @@ class TestPathMatch < Test::Unit::TestCase
57
78
  path = @pmatch.make_path "/%31/2/path/%4_%1"
58
79
  assert_equal ["", "2", "path", "foo_this"], path
59
80
  end
81
+
82
+
83
+ def test_make_path_splat
84
+ path = @splat.make_path "/%4%%/2/thing"
85
+ assert_equal ["foopath", "to", "2", "thing"], path
86
+
87
+ path = @splat.make_path "/%4/%%/2/thing"
88
+ assert_equal ["foo", "path", "to", "2", "thing"], path
89
+
90
+ path = @splat.make_path "/%4/bah%%2/thing"
91
+ assert_equal ["foo", "bahpath", "to2", "thing"], path
92
+ end
93
+
94
+
95
+ def test_make_path_splat_multiple
96
+ path = @splat.make_path "/%4%%%%/2/thing"
97
+ assert_equal ["foopath", "toresource", "bar", "2", "thing"], path
98
+
99
+ path = @splat.make_path "/%4/%%/2/thing/%%"
100
+ assert_equal ["foo", "path", "to", "2", "thing", "resource", "bar"], path
101
+
102
+ path = @splat.make_path "%%/%4/bah%%2/thing/%%"
103
+ assert_equal %w{path to foo bahresource bar2 thing}, path
104
+ end
60
105
  end
@@ -107,11 +107,12 @@ class TestPathMatcher < Test::Unit::TestCase
107
107
  matcher = Kronk::Path::Matcher.new :key => :findme,
108
108
  :recursive => true
109
109
 
110
- matcher.find_in @data do |data, key|
110
+ path_matches = matcher.find_in @data do |data, key|
111
111
  keys << key.to_s
112
112
  data_points << data
113
113
  end
114
114
 
115
+ assert path_matches.find{|pm| pm.splat == [[matcher, [:key1, :key1a, 3]]]}
115
116
  assert_equal 3, keys.length
116
117
  assert_equal 1, keys.uniq.length
117
118
  assert_equal "findme", keys.first
@@ -204,6 +205,11 @@ class TestPathMatcher < Test::Unit::TestCase
204
205
  [:key3]
205
206
  ]
206
207
 
208
+ paths.each do |path|
209
+ assert path.splat.empty?,
210
+ "Expected empty splat for #{path.inspect} but got #{path.splat.inspect}"
211
+ end
212
+
207
213
  assert_equal expected_paths, (expected_paths | paths)
208
214
  assert_equal Kronk::Path::PathMatch, paths.first.class
209
215
  assert_equal expected_paths, (expected_paths | paths.map{|p| p.matches})
@@ -269,6 +275,41 @@ class TestPathMatcher < Test::Unit::TestCase
269
275
  end
270
276
 
271
277
 
278
+ def test_find_in_match_splat
279
+ matcher = Kronk::Path::Matcher.new :key => "findme",
280
+ :recursive => true
281
+
282
+ matches = matcher.find_in @data
283
+
284
+ splat_i = matches.index [:key1, :key1a, 3, :findme]
285
+ assert_equal [:key1, :key1a, 3], matches[splat_i].splat[0][1]
286
+
287
+ splat_i = matches.index ["findme"]
288
+ assert_equal [], matches[splat_i].splat[0][1]
289
+
290
+ splat_i = matches.index ["findme", 2, :findme]
291
+ assert_equal ["findme", 2], matches[splat_i].splat[0][1]
292
+ end
293
+
294
+
295
+ def test_find_in_match_splat_value
296
+ matcher = Kronk::Path::Matcher.new :value => "foobar",
297
+ :recursive => true
298
+
299
+ matches = matcher.find_in @data
300
+
301
+ assert(matches.any?{|m|
302
+ m == [:key1, :key1a, 2] && assert_equal([:key1, :key1a, 2], m.splat[0][1])
303
+ true
304
+ })
305
+
306
+ assert(matches.any?{|m|
307
+ m == [:key2] && assert_equal([:key2], m.splat[0][1])
308
+ true
309
+ })
310
+ end
311
+
312
+
272
313
  def test_parse_node_range
273
314
  assert_equal 1..4, @matcher.parse_node("1..4")
274
315
  assert_equal 1...4, @matcher.parse_node("1...4")