cddl 0.8.5 → 0.8.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 7338cde62dc12f53d0ebdef50710108d03570241
4
- data.tar.gz: 6ab3c6679a1553bd36ad614dcd406855be6d3bd5
2
+ SHA256:
3
+ metadata.gz: 8ba44459ee2f7bf888218b60e75e52c6dbf90b38cb498b3de091ae7e5e525213
4
+ data.tar.gz: 8fcb86e2209fb4264f55663a47a37a9b150347f32704af94f0be27357d012d18
5
5
  SHA512:
6
- metadata.gz: 2d87a121c7ad9489dc74de6e6a09d05b4d303a1e6739ad887dcf142f03857079ddac3442add743916ffc580558aac800ef13f52685c68a28c54bc17206f65c93
7
- data.tar.gz: 2ddc22986f4f623dff1d5bc793654a2c1f3482172fd1a4f90d30c172160d89cbc21c497ec5c48014968060e09f5ac378aaf58d24628aec7d1d8aea12a4cedd6c
6
+ metadata.gz: 65f7adeb64757a58a0b548a5c33fcf78ca0e3bb9ae442032d40ddc45c098de7471657437772f1fed07716bcb829467b75d8eaf4982ed04be78ce2abbca780684
7
+ data.tar.gz: 6274c24c143aed5cba8d35f17e0beab84fe6af515fd4e44c11133bf3296c68f84cbd8f526616ad6cc2b8ff397f56d60ea2cf16e1d09990dc7f9aec50be5929ef
@@ -1,6 +1,6 @@
1
1
  spec = Gem::Specification.new do |s|
2
2
  s.name = 'cddl'
3
- s.version = '0.8.5'
3
+ s.version = '0.8.6'
4
4
  s.summary = "CDDL generator and validator."
5
5
  s.description = %{A parser, generator, and validator for CDDL}
6
6
  s.add_dependency('cbor-diag')
@@ -50,7 +50,9 @@ occur = [uint] "*" [uint]
50
50
  / "?"
51
51
 
52
52
  uint = ["0x" / "0b"] "0"
53
- / ["0x" / "0b"] DIGIT1 *DIGIT
53
+ / DIGIT1 *DIGIT
54
+ / "0x" 1*HEXDIG
55
+ / "0b" 1*BINDIG
54
56
 
55
57
  value = number
56
58
  / text
@@ -77,6 +79,9 @@ ALPHA = %x41-5A / %x61-7A
77
79
  EALPHA = %x41-5A / %x61-7A / "@" / "_" / "$"
78
80
  DIGIT = %x30-39
79
81
  DIGIT1 = %x31-39
82
+ HEXDIG = DIGIT / "A" / "B" / "C" / "D" / "E" / "F"
83
+ BINDIG = %x30-31
84
+
80
85
  S = *WS
81
86
  WS = SP / NL
82
87
  SP = %x20
@@ -320,7 +320,8 @@ module CDDL
320
320
  end
321
321
  when :member
322
322
  st = where[1]
323
- en = [where[2], [st, 4].max].min # truncate to 4 unless must be more
323
+ fudge = 4 * (1 - (@recursion / MAX_RECURSE.to_f))**3 # get less generate-happy with more recursion
324
+ en = [where[2], [st, fudge].max].min # truncate to fudge unless must be more
324
325
  st += rand(en + 1 - st) if en != st
325
326
  kr = where[3]
326
327
  vr = where[4]
@@ -526,7 +527,7 @@ module CDDL
526
527
  [:prim, 7, 23] => [true, :undefined, :undefined],
527
528
  }
528
529
 
529
- def extract_value(t)
530
+ def extract_value(t) # []
530
531
  if vt = VALUE_TYPE[t[0]]
531
532
  [true, t[1], vt]
532
533
  elsif v = SIMPLE_VALUE[t]
@@ -661,7 +662,7 @@ module CDDL
661
662
  # this is mostly quadratic; let's do the linear thing if possible
662
663
  simple, simpleval = extract_value(k)
663
664
  if simple
664
- # puts "SIMPLE: #{d_check.inspect} #{simpleval}"
665
+ puts "SIMPLE: #{d_check.inspect} #{simpleval}" if ENV["CDDL_TRACE"]
665
666
  # add occurrence check; check that val is present in the first place
666
667
  actual = d.fetch(simpleval, :not_found)
667
668
  if actual == :not_found
@@ -673,7 +674,7 @@ module CDDL
673
674
  end
674
675
  end
675
676
  else
676
- # puts "COMPLEX: #{k.inspect} #{simple.inspect} #{simpleval.inspect}"
677
+ puts "COMPLEX: #{k.inspect} #{simple.inspect} #{simpleval.inspect}" if ENV["CDDL_TRACE"]
677
678
  keys = d_check.keys
678
679
  ta, keys = keys.partition{ |key| validate1(key, k)}
679
680
  # XXX check ta.size against s/e
@@ -964,12 +965,12 @@ module CDDL
964
965
  else
965
966
  val = eval(n.to_s)
966
967
  # warn val
967
- [case val
968
- when Integer; :int
969
- when Numeric; :float
970
- when String; :text
968
+ case val
969
+ when Integer; [:int, val]
970
+ when Numeric; [:float, val]
971
+ when String; [:text, val.force_encoding(Encoding::UTF_8)]
971
972
  else fail "huh? value #{val.inspect}"
972
- end, val]
973
+ end
973
974
  end
974
975
  end
975
976
 
@@ -1009,7 +1010,7 @@ module CDDL
1009
1010
  fail [n, n.children, mk, mk.children].inspect
1010
1011
  end
1011
1012
  name = bw.to_s
1012
- [[:member, *occ, [:text, name], type(nt)]]
1013
+ [[:member, *occ, [:text, name.force_encoding(Encoding::UTF_8)], type(nt)]]
1013
1014
  end
1014
1015
  else
1015
1016
  t = if nbw = nt.bareword
@@ -1021,8 +1022,8 @@ module CDDL
1021
1022
  else
1022
1023
  type(nt, true) # type can actually be a group here!
1023
1024
  end
1024
- # pp ["t is", t]
1025
- if t[0] == :grpent && (@insides.last != :array || occ == [1, 1])
1025
+ pp ["t is", t] if ENV["CDDL_TRACE"]
1026
+ if t[0] == :grpent && (occ == [1, 1])
1026
1027
  # go through the members here and multiply the occs
1027
1028
  t1 = t[1..-1].flatten(1)
1028
1029
  if t1[0] == :recurse_grpent
@@ -0,0 +1,2 @@
1
+ b = [ a ]
2
+ a = uint
@@ -0,0 +1,5 @@
1
+ top = { topgroup }
2
+
3
+ topgroup = ( first: tstr, second: tstr,
4
+ (option1: uint //
5
+ option2: uint) )
@@ -0,0 +1,13 @@
1
+ map = {
2
+ first_group,
3
+ ? second_group,
4
+ }
5
+
6
+ first_group = ( e1, e2,)
7
+ second_group = (e3, e4, e5)
8
+
9
+ e1 = (1: uint)
10
+ e2 = (2: tstr)
11
+ e3 = (3: tdate)
12
+ e4 = (4: tstr)
13
+ e5 = (5: uint)
@@ -0,0 +1,2 @@
1
+ foo = { foo: bool, "foob" => bar, * tstr => uint }
2
+ bar = "blba"
@@ -0,0 +1,14 @@
1
+
2
+ foo = { 1*relement }
3
+
4
+ context-element = 4711
5
+
6
+ relement = $$relement .within relement-generic
7
+
8
+ relement-generic = ( relement-codepoint => relement-value ) ; [1]
9
+ relement-codepoint = uint ; [1]
10
+ relement-value = any ; [1]
11
+
12
+ $$relement //= ( &(sender-loop-count:1) => 1..255 ) ; [2]
13
+ $$relement //= ( &(srv-element:2) => context-element ) ; [2]
14
+
@@ -0,0 +1,11 @@
1
+ foo = foo-specific .within foo-generic
2
+ foo-specific = { 1*$$relement }
3
+ foo-generic = { 1*relement-generic }
4
+
5
+ relement-generic = ( relement-codepoint => relement-value ) ; [1]
6
+ relement-codepoint = uint ; [1]
7
+ relement-value = any ; [1]
8
+
9
+ $$relement //= ( &(sender-loop-count:1) => 1..255 ) ; [2]
10
+ $$relement //= ( &(srv-element:2) => context-element ) ; [2]
11
+ context-element = "and so on"
@@ -59,9 +59,9 @@ class TestABNF < Test::Unit::TestCase
59
59
 
60
60
  def test_generate_hex_bin
61
61
  parser = CDDL::Parser.new <<HERE
62
- test = [0x4711, 0b1011001110001111000]
62
+ test = [0x4711, 0xabcDEF, 0b1011001110001111000]
63
63
  HERE
64
- assert_equal [0x4711, 0b1011001110001111000], parser.generate
64
+ assert_equal [0x4711, 0xabcDEF, 0b1011001110001111000], parser.generate
65
65
  end
66
66
 
67
67
  def test_generate_le
@@ -202,6 +202,54 @@ HERE
202
202
  assert parser.validate_for_test({"one" => 1, "two" => 1}, false)
203
203
  end
204
204
 
205
+ def test_validate_a_nontrivial_group_map
206
+ parser = CDDL::Parser.new <<HERE
207
+ test = {* (text => 1, text => 2)}
208
+ HERE
209
+ assert parser.validate_for_test({})
210
+ assert parser.validate_for_test({"one" => 2, "two" => 1})
211
+ assert parser.validate_for_test({"one" => 1, "two" => 2})
212
+ refute parser.validate_for_test({"one" => 1}, false)
213
+ assert parser.validate_for_test({"one" => 1, "two" => 2, "uno" => 1, "due" => 2})
214
+ end
215
+
216
+
217
+ def test_murray
218
+ parser = CDDL::Parser.new <<HERE
219
+ a = {
220
+ b
221
+ }
222
+
223
+ b = (
224
+ (x: int // y: int), z: int
225
+ )
226
+ HERE
227
+ assert parser.validate_for_test({})
228
+ assert parser.validate_for_test({"x" => 2, "z" => 1})
229
+ assert parser.validate_for_test({"y" => 1, "z" => 2})
230
+ refute parser.validate_for_test({"z" => 1}, false)
231
+ assert parser.validate_for_test({"one" => 1, "two" => 2, "uno" => 1, "due" => 2})
232
+ end
233
+
234
+
235
+ def test_murray_workaround
236
+ parser = CDDL::Parser.new <<HERE
237
+ a = {
238
+ b
239
+ }
240
+
241
+ b = ( z: int
242
+ (x: int // y: int)
243
+ )
244
+ HERE
245
+ assert parser.validate_for_test({})
246
+ assert parser.validate_for_test({"x" => 2, "z" => 1})
247
+ assert parser.validate_for_test({"y" => 1, "z" => 2})
248
+ refute parser.validate_for_test({"z" => 1}, false)
249
+ assert parser.validate_for_test({"one" => 1, "two" => 2, "uno" => 1, "due" => 2})
250
+ end
251
+
252
+
205
253
  def test_validate_a_string
206
254
  parser = CDDL::Parser.new <<HERE
207
255
  test = [* one: "one"]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cddl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.5
4
+ version: 0.8.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carsten Bormann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-23 00:00:00.000000000 Z
11
+ date: 2018-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cbor-diag
@@ -98,6 +98,7 @@ files:
98
98
  - test-data/7071-concise.cddl
99
99
  - test-data/7071-verbose.cddl
100
100
  - test-data/a.cddl
101
+ - test-data/ambig.cddl
101
102
  - test-data/b.cddl
102
103
  - test-data/badaddr.cddl
103
104
  - test-data/basic_syntax_example.cddl
@@ -117,10 +118,15 @@ files:
117
118
  - test-data/ifmap-metadata-2.2v9_fh-cabo.cddl
118
119
  - test-data/ifmap2.cddl
119
120
  - test-data/jcr-ex.cddl
121
+ - test-data/kevin5.cddl
122
+ - test-data/map-group.cddl
123
+ - test-data/mapkey.cddl
120
124
  - test-data/minimal.cddl
121
125
  - test-data/patch1.cddl
122
126
  - test-data/reused_named_group.cddl
123
127
  - test-data/structure.cddl
128
+ - test-data/toerless0.cddl
129
+ - test-data/toerless1.cddl
124
130
  - test-data/two_anonymous_groups.cddl
125
131
  - test-data/wrong1.cddl
126
132
  - test-data/wrong1a.cddl
@@ -148,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
154
  version: '0'
149
155
  requirements: []
150
156
  rubyforge_project:
151
- rubygems_version: 2.6.8
157
+ rubygems_version: 2.7.6
152
158
  signing_key:
153
159
  specification_version: 4
154
160
  summary: CDDL generator and validator.