groonga-command-parser 1.0.9 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 190336c6a64a7054fbb00bbf82d4045a9c58c542
4
- data.tar.gz: a442b60917501ed808c47995a76c309f7865550a
3
+ metadata.gz: b2f5dd8bb9f225dd59a1441b1ee4ba18fc7b1d74
4
+ data.tar.gz: f202a12f7824fbdfd1bdf7dd31fc1542464d5868
5
5
  SHA512:
6
- metadata.gz: bf253d6c39b154349389257e7974eb76662467d6546017baa8d0e80d21c26776efb5d4cd697def2675488d23850c43714b1a319f5f03a42b82d906f717fc1a89
7
- data.tar.gz: d2ea221931922fd68c8c20d442161a4197ca67329a48f6c43407197ee6eea7803a78bfec8b712751c3d6fabbed92656319a1d21bf60d1a03eedd9ba5d1dae2a7
6
+ metadata.gz: b056beeb0f6dd1971ba3e2688d0a623e57f88c7d9389df817b81e09583626adf3d596c98434f21e88b6d28c1aded38125dd8e08ba1550eb41a0e818d6ec80050
7
+ data.tar.gz: 66c6b6d7739e3889f1e205054ed600f830dcd9ecb1816f33a72af916fadd46d5a8037200e31b8536c4405d94d48804aa3ac56df0a3130fae5e014184dcecc01d
@@ -1,5 +1,17 @@
1
1
  # News
2
2
 
3
+ ## 1.1.0: 2017-10-30
4
+
5
+ ### Improvements
6
+
7
+ * `groonga-command-convert-format`: Stopped to require the last
8
+ newline.
9
+
10
+ ### Fixes
11
+
12
+ * Fixed a bug that commands after `load` are ignored on `String`
13
+ parse mode.
14
+
3
15
  ## 1.0.9: 2017-01-18
4
16
 
5
17
  ### Improvements
@@ -1,6 +1,4 @@
1
- # -*- coding: utf-8 -*-
2
- #
3
- # Copyright (C) 2011-2015 Kouhei Sutou <kou@clear-code.com>
1
+ # Copyright (C) 2011-2017 Kouhei Sutou <kou@clear-code.com>
4
2
  #
5
3
  # This library is free software; you can redistribute it and/or
6
4
  # modify it under the terms of the GNU Lesser General Public
@@ -59,8 +57,8 @@ module Groonga
59
57
  parser.on_load_start do |command|
60
58
  yield(:on_load_start, command)
61
59
  end
62
- parser.on_load_columns do |command, header|
63
- yield(:on_load_columns, command, header)
60
+ parser.on_load_columns do |command, columns|
61
+ yield(:on_load_columns, command, columns)
64
62
  end
65
63
  parser.on_load_value do |command, value|
66
64
  yield(:on_load_value, command, value)
@@ -221,9 +219,7 @@ module Groonga
221
219
 
222
220
  def consume_load_values(tag)
223
221
  throw(tag) if @buffer.empty?
224
- @command.original_source << @buffer
225
222
  @load_values_parser << @buffer
226
- @buffer.clear
227
223
  end
228
224
 
229
225
  def consume_line(tag)
@@ -361,14 +357,14 @@ module Groonga
361
357
  on_load_value(@command, value)
362
358
  end
363
359
  end
360
+ @load_values_parser.on_consumed = lambda do |consumed|
361
+ @command.original_source << consumed if @loading
362
+ end
364
363
  @load_values_parser.on_end = lambda do |rest|
365
- if rest
366
- original_source_size = @command.original_source.size
367
- @command.original_source.slice!(original_source_size - rest.size,
368
- rest.size)
369
- end
364
+ loading = @loading
370
365
  on_load_complete(@command)
371
366
  reset
367
+ @buffer << rest if loading and rest
372
368
  end
373
369
  end
374
370
  end
@@ -89,6 +89,7 @@ module Groonga
89
89
  input.each_line do |line|
90
90
  parser << line
91
91
  end
92
+ parser.finish
92
93
  end
93
94
 
94
95
  def convert_format(command)
@@ -21,10 +21,12 @@ module Groonga
21
21
  class Parser
22
22
  class LoadValuesParser
23
23
  attr_writer :on_value
24
+ attr_writer :on_consumed
24
25
  attr_writer :on_end
25
26
  def initialize
26
27
  initialize_parser
27
28
  @on_value = nil
29
+ @on_consumed = nil
28
30
  @on_end = nil
29
31
  @containers = []
30
32
  @keys = []
@@ -49,9 +51,16 @@ module Groonga
49
51
  :continue
50
52
  end
51
53
 
54
+ pos = @parser.pos
55
+ consumed = pos - before_pos
56
+ if consumed > 0
57
+ if consumed < data_size
58
+ @on_consumed.call(data[0, consumed])
59
+ else
60
+ @on_consumed.call(data)
61
+ end
62
+ end
52
63
  if status == :done
53
- pos = @parser.pos
54
- consumed = pos - before_pos
55
64
  if consumed < data_size
56
65
  @on_end.call(data[consumed..-1])
57
66
  else
@@ -17,7 +17,7 @@
17
17
  module Groonga
18
18
  module Command
19
19
  class Parser
20
- VERSION = "1.0.9"
20
+ VERSION = "1.1.0"
21
21
  end
22
22
  end
23
23
  end
@@ -21,7 +21,12 @@ class LoadValuesParserTest < Test::Unit::TestCase
21
21
  @parser.on_value = lambda do |value|
22
22
  @values << value
23
23
  end
24
+ @parse_consumed = []
25
+ @parser.on_consumed = lambda do |consumed|
26
+ @parse_consumed << consumed
27
+ end
24
28
  @parse_done = false
29
+ @parse_rest = nil
25
30
  @parser.on_end = lambda do |rest|
26
31
  @parse_done = true
27
32
  @parse_rest = rest
@@ -186,8 +191,17 @@ class LoadValuesParserTest < Test::Unit::TestCase
186
191
  }
187
192
  ]garbage
188
193
  JSON
189
- assert_equal([true, "garbage\n"],
190
- [@parse_done, @parse_rest])
194
+ consumed = [
195
+ "[\n",
196
+ " {\n",
197
+ " \"object\": {\n",
198
+ " \"string\": \"abc\"\n",
199
+ " }\n",
200
+ " }\n",
201
+ "]",
202
+ ]
203
+ assert_equal([true, consumed, "garbage\n"],
204
+ [@parse_done, @parse_consumed, @parse_rest])
191
205
  end
192
206
  end
193
207
  end
@@ -253,108 +253,138 @@ status
253
253
  class MultiLineTest < self
254
254
  class BracketTest < self
255
255
  def test_have_columns
256
- @parser << <<-EOC
256
+ @parser << <<-COMMAND
257
257
  load --table Users --columns "_key, name"
258
258
  [
259
259
  ["alice", "Alice"]
260
260
  ]
261
- EOC
261
+ COMMAND
262
+
262
263
  expected_events = []
263
- expected_events << [:load_start, <<-EOC.chomp]
264
+ expected_events << [:load_start, <<-COMMAND.chomp]
264
265
  load --table Users --columns "_key, name"
265
- EOC
266
- expected_events << [:load_columns, <<-EOC.chomp, ["_key", "name"]]
266
+ COMMAND
267
+ expected_events << [:load_columns, <<-COMMAND.chomp, ["_key", "name"]]
267
268
  load --table Users --columns "_key, name"
268
- EOC
269
- expected_events << [:load_value, <<-EOC, ["alice", "Alice"]]
269
+ COMMAND
270
+ expected_events << [:load_value, <<-COMMAND, ["alice", "Alice"]]
270
271
  load --table Users --columns "_key, name"
271
- [
272
- ["alice", "Alice"]
273
- ]
274
- EOC
275
- expected_events << [:load_complete, <<-EOC.chomp]
272
+ COMMAND
273
+ expected_events << [:load_complete, <<-COMMAND.chomp]
276
274
  load --table Users --columns "_key, name"
277
275
  [
278
276
  ["alice", "Alice"]
279
277
  ]
280
- EOC
278
+ COMMAND
281
279
  assert_equal(expected_events, @events)
282
280
  end
283
281
 
284
282
  def test_no_columns
285
- @parser << <<-EOC
283
+ @parser << <<-COMMAND
286
284
  load --table Users
287
285
  [
288
286
  ["_key", "name"],
289
287
  ["alice", "Alice"]
290
288
  ]
291
- EOC
289
+ COMMAND
290
+
292
291
  expected_events = []
293
- expected_events << [:load_start, <<-EOC.chomp]
292
+ expected_events << [:load_start, <<-COMMAND.chomp]
294
293
  load --table Users
295
- EOC
296
- expected_events << [:load_columns, <<-EOC, ["_key", "name"]]
294
+ COMMAND
295
+ expected_events << [:load_columns, <<-COMMAND, ["_key", "name"]]
297
296
  load --table Users
298
- [
299
- ["_key", "name"],
300
- ["alice", "Alice"]
301
- ]
302
- EOC
303
- expected_events << [:load_value, <<-EOC, ["alice", "Alice"]]
297
+ COMMAND
298
+ expected_events << [:load_value, <<-COMMAND, ["alice", "Alice"]]
304
299
  load --table Users
305
- [
306
- ["_key", "name"],
307
- ["alice", "Alice"]
308
- ]
309
- EOC
310
- expected_events << [:load_complete, <<-EOC.chomp]
300
+ COMMAND
301
+ expected_events << [:load_complete, <<-COMMAND.chomp]
311
302
  load --table Users
312
303
  [
313
304
  ["_key", "name"],
314
305
  ["alice", "Alice"]
315
306
  ]
316
- EOC
307
+ COMMAND
317
308
  assert_equal(expected_events, @events)
318
309
  end
319
310
  end
320
311
 
321
312
  def test_brace
322
- @parser << <<-EOC
313
+ @parser << <<-COMMAND
323
314
  load --table Users
324
315
  [
325
316
  {"_key": "alice", "name": "Alice"},
326
317
  {"_key": "bob", "name": "Bob"}
327
318
  ]
328
- EOC
319
+ COMMAND
320
+
329
321
  expected_events = []
330
- expected_events << [:load_start, <<-EOC.chomp]
322
+ expected_events << [:load_start, <<-COMMAND.chomp]
331
323
  load --table Users
332
- EOC
324
+ COMMAND
333
325
  value = {"_key" => "alice", "name" => "Alice"}
334
- expected_events << [:load_value, <<-EOC, value]
326
+ expected_events << [:load_value, <<-COMMAND, value]
327
+ load --table Users
328
+ COMMAND
329
+ value = {"_key" => "bob", "name" => "Bob"}
330
+ expected_events << [:load_value, <<-COMMAND, value]
331
+ load --table Users
332
+ COMMAND
333
+ expected_events << [:load_complete, <<-COMMAND.chomp]
335
334
  load --table Users
336
335
  [
337
336
  {"_key": "alice", "name": "Alice"},
338
337
  {"_key": "bob", "name": "Bob"}
339
338
  ]
340
- EOC
341
- value = {"_key" => "bob", "name" => "Bob"}
342
- expected_events << [:load_value, <<-EOC, value]
339
+ COMMAND
340
+ assert_equal(expected_events, @events)
341
+ end
342
+ end
343
+
344
+ def test_multiple
345
+ @parser << <<-COMMANDS
346
+ load --table Users
347
+ [
348
+ {"_key": "alice", "name": "Alice"}
349
+ ]
350
+
343
351
  load --table Users
344
352
  [
345
- {"_key": "alice", "name": "Alice"},
346
353
  {"_key": "bob", "name": "Bob"}
347
354
  ]
348
- EOC
349
- expected_events << [:load_complete, <<-EOC.chomp]
355
+ COMMANDS
356
+
357
+ expected_events = []
358
+
359
+ expected_events << [:load_start, <<-SOURCE.chomp]
360
+ load --table Users
361
+ SOURCE
362
+ value = {"_key" => "alice", "name" => "Alice"}
363
+ expected_events << [:load_value, <<-SOURCE, value]
364
+ load --table Users
365
+ SOURCE
366
+ expected_events << [:load_complete, <<-SOURCE.chomp]
367
+ load --table Users
368
+ [
369
+ {"_key": "alice", "name": "Alice"}
370
+ ]
371
+ SOURCE
372
+
373
+ expected_events << [:load_start, <<-SOURCE.chomp]
374
+ load --table Users
375
+ SOURCE
376
+ value = {"_key" => "bob", "name" => "Bob"}
377
+ expected_events << [:load_value, <<-SOURCE, value]
378
+ load --table Users
379
+ SOURCE
380
+ expected_events << [:load_complete, <<-SOURCE.chomp]
350
381
  load --table Users
351
382
  [
352
- {"_key": "alice", "name": "Alice"},
353
383
  {"_key": "bob", "name": "Bob"}
354
384
  ]
355
- EOC
356
- assert_equal(expected_events, @events)
357
- end
385
+ SOURCE
386
+
387
+ assert_equal(expected_events, @events)
358
388
  end
359
389
 
360
390
  class ErrorTest < self
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: groonga-command-parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.9
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kouhei Sutou
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-18 00:00:00.000000000 Z
11
+ date: 2017-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: groonga-command
@@ -186,7 +186,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
186
186
  version: '0'
187
187
  requirements: []
188
188
  rubyforge_project:
189
- rubygems_version: 2.5.2
189
+ rubygems_version: 2.5.2.1
190
190
  signing_key:
191
191
  specification_version: 4
192
192
  summary: Groonga-command-parser is a Ruby library to parses [groonga](http://groonga.org/)'s