norikra 0.0.23-java → 0.0.24-java

Sign up to get free protection for your applications and to get access to all the features.
@@ -38,6 +38,11 @@ module Norikra
38
38
  end
39
39
 
40
40
  def self.leaves(container)
41
+ unless container.is_a?(Array) || container.is_a?(Hash)
42
+ raise ::ArgumentError, "FieldSet#leaves accepts Array or Hash only"
43
+ end
44
+ return [] if container.empty?
45
+
41
46
  # returns list of [ [key-chain-items-flatten-list, value] ]
42
47
  dig = Proc.new do |obj|
43
48
  if obj.is_a?(Array)
@@ -1,3 +1,3 @@
1
1
  module Norikra
2
- VERSION = "0.0.23"
2
+ VERSION = "0.0.24"
3
3
  end
@@ -50,6 +50,17 @@ describe Norikra::FieldSet do
50
50
  end
51
51
 
52
52
  describe '.leaves' do
53
+ it 'raises ArgumentError for non-container values' do
54
+ expect { Norikra::FieldSet.leaves('value') }.to raise_error(ArgumentError)
55
+ expect { Norikra::FieldSet.leaves('') }.to raise_error(ArgumentError)
56
+ expect { Norikra::FieldSet.leaves(1024) }.to raise_error(ArgumentError)
57
+ expect { Norikra::FieldSet.leaves(nil) }.to raise_error(ArgumentError)
58
+ end
59
+ it 'returns blank array for empty container' do
60
+ expect( Norikra::FieldSet.leaves({}) ).to eql([])
61
+ expect( Norikra::FieldSet.leaves([]) ).to eql([])
62
+ end
63
+
53
64
  it 'returns field access chains to all keys of 1-depth Hash container' do
54
65
  leaves = Norikra::FieldSet.leaves({'field1' => 1, 'field2' => 2})
55
66
  expect(leaves.size).to eql(2)
data/spec/typedef_spec.rb CHANGED
@@ -378,6 +378,24 @@ describe Norikra::Typedef do
378
378
  expect(r['key4$f2$$0']).to eql('long')
379
379
  expect(r['key5']).to eql('string')
380
380
  end
381
+
382
+ it 'ignores empty container fieldss' do
383
+ typedef = Norikra::Typedef.new({'key1' => 'boolean', 'key2' => 'long', 'key3.$0.key4' => 'string'})
384
+ typedef.waiting_fields = ['key4.f1', 'key4.f2.$0', 'key5']
385
+
386
+ t = typedef.simple_guess({
387
+ 'key1' => true,
388
+ 'key2' => 10,
389
+ 'key3' => [],
390
+ 'key4' => {},
391
+ 'key5' => 'foobar'
392
+ }, true, true)
393
+ r = t.definition
394
+ expect(r.size).to eql(3)
395
+ expect(r['key1']).to eql('boolean')
396
+ expect(r['key2']).to eql('long')
397
+ expect(r['key5']).to eql('string')
398
+ end
381
399
  end
382
400
 
383
401
  describe '#refer' do
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: norikra
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.23
5
+ version: 0.0.24
6
6
  platform: java
7
7
  authors:
8
8
  - TAGOMORI Satoshi