edn-abnf 0.5.13 → 0.5.15

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/edn-abnf +30 -16
  3. data/edn-abnf.gemspec +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 69b5019bb0f6f80ce030b7af41a9a354c5a73caa653a151618766444d293fea1
4
- data.tar.gz: '09c8ac9b5f3fffba27602bf2ecfdcf21d85ac00e26298fedf829c403a09a6c31'
3
+ metadata.gz: e0cfa7f5a3324396126a17a2530147bff309fec468d512ede0ca8c436591f44c
4
+ data.tar.gz: 6850c6fa052ba8b687ac8a0332ed05f27a32781e5132c76754dfd24ad2928e55
5
5
  SHA512:
6
- metadata.gz: bc5fbfc1624358d1308ec3d42de5738558eef3c7601c67a6e32a1a4008423fb865506c6c9a5272f0e8288d25899d7f4dd5cda106ec727c0301837b85f1af5a7b
7
- data.tar.gz: 1cdee66c10564ec2b0633bdd3d02ad25711a5c81e6de5cef7bb2042cb30c912d5a72d55b3444e066ac42f1690209397049868cdbdce75088193dac019452d1e6
6
+ metadata.gz: dd717eab5c11238c954e70ecf9575524aa1826fccbe7d885c9ac9e5946783314181443ddd17c6af22e5b18a841f472252871e14a3d480e701cdba8c996142658
7
+ data.tar.gz: ae2f0a9e57e9d4cb64cf3ea2f00f7f5d3e8e47141c2ec1e05276f6c4c3d859661d76003617c9b22c7773cbf067603bdf883c788ad670335e97c4757a25ff1b15
data/bin/edn-abnf CHANGED
@@ -41,7 +41,7 @@ require 'ostruct'
41
41
 
42
42
  $error = 0
43
43
 
44
- output_formats = [:basic, :neat, :json, :yaml, :edn, :diag, :pretty, :hex, :cbor, :"decoder-test"]
44
+ output_formats = [:basic, :neat, :json, :yaml, :edn, :diag, :pretty, :hex, :cbor, :"test-vector"]
45
45
 
46
46
  $options = OpenStruct.new
47
47
  begin
@@ -65,6 +65,9 @@ begin
65
65
  opts.on("-eEDN", "--e=EDN", "supply EDN on command line") do |v|
66
66
  $options.edn = v
67
67
  end
68
+ opts.on("-c", "--[no-]cbor", "input is encoded CBOR data item, not EDN") do |v|
69
+ $options.cbor = v
70
+ end
68
71
  opts.on("-tFMT", "--to=FMT",
69
72
  output_formats,
70
73
  "Target format (#{output_formats.join("/")}, default: diag)") do |v|
@@ -90,12 +93,8 @@ rescue Exception => e
90
93
  exit 1
91
94
  end
92
95
 
93
-
94
96
  if !$options.edn
95
- if ARGV == []
96
- warn op
97
- exit 1
98
- end
97
+ ARGF.binmode if $options.cbor
99
98
  $options.edn = ARGF.read
100
99
  else
101
100
  if ARGV != []
@@ -106,6 +105,10 @@ end
106
105
  edn_file = $options.edn
107
106
 
108
107
  if $options.lines
108
+ if $options.cbor
109
+ warn "*** -l and -c don't combine"
110
+ exit 1
111
+ end
109
112
  CSV.parse(edn_file) do |ok, ednin, out|
110
113
  if ok[0] == "#"
111
114
  puts "# #{ok}, #{ednin.inspect}, #{out}" if $options.verbose
@@ -165,11 +168,18 @@ if $options.lines
165
168
  end
166
169
 
167
170
  begin
168
- edn = EDN.from_edn(edn_file)
169
- result = edn.tree # XXX .tree?
171
+ if $options.cbor
172
+ result = CBOR.decode(edn_file)
173
+ else
174
+ edn = EDN.from_edn(edn_file)
175
+ result = edn.tree # XXX .tree?
176
+ end
170
177
  rescue CBOR_DIAG::AppParseError, ArgumentError => e
171
178
  puts "** #{e}"
172
179
  exit 1
180
+ rescue CBOR::OutOfBytesError, RuntimeError, JSON::GeneratorError => e
181
+ puts "** (encoded CBOR input:) #{e}"
182
+ exit 1
173
183
  end
174
184
 
175
185
  case $options.target
@@ -200,12 +210,13 @@ when :pretty, :hex, :cbor
200
210
  else
201
211
  fail "Cannot happen"
202
212
  end
203
- when :"decoder-test"
213
+ when :"test-vector"
204
214
  fail "Not a map" unless Hash === result
205
215
  tests = result.delete("tests")
206
216
  fail "tests not an array" unless Array === tests
207
- if result.delete("fail")
208
- p result
217
+ failing_tests = result.delete("fail")
218
+ puts result.inspect << ", #{tests.size} tests"
219
+ if failing_tests
209
220
  tests.each do |t|
210
221
  encoded = t.delete("encoded")
211
222
  fail t unless encoded
@@ -220,23 +231,26 @@ when :"decoder-test"
220
231
  end
221
232
  end
222
233
  else
223
- p result
224
234
  tests.each do |t|
225
235
  encoded = t.delete("encoded")
226
236
  fail t unless encoded
227
- roundtrip = t.delete("roundtrip")
228
- fail "not implemented: roundtrip is #{roundtrip.inspect} in #{t.inspect}" if roundtrip
229
- # p t
237
+ roundtrip = t.delete("roundtrip") { true } # default is true
230
238
  decoded = t.delete("decoded") { :"no-decoded"}
231
239
  fail "no decoded" if decoded == :"no-decoded"
232
240
  begin
233
241
  r = CBOR.decode(encoded)
234
242
  if !r.cbor_same?(decoded)
235
- puts "*** unexpected: #{r.inspect} for #{decoded.inspect} in #{t.inspect}"
243
+ puts "*** unexpected: decoding #{r.inspect}, expected #{decoded.inspect} in #{t.inspect}"
236
244
  end
237
245
  rescue => e
238
246
  puts "*** decode failure: #{e}"
239
247
  end
248
+ if roundtrip
249
+ rt = CBOR.encode(decoded)
250
+ if rt != encoded
251
+ puts "*** unexpected: encoding #{rt.inspect}, expected #{encoded.inspect} in #{t.inspect}"
252
+ end
253
+ end
240
254
  end
241
255
  end
242
256
  else
data/edn-abnf.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "edn-abnf"
3
- s.version = "0.5.13"
3
+ s.version = "0.5.15"
4
4
  s.summary = "CBOR Extended Diagnostic Notation (EDN) implemented in ABNF"
5
5
  s.description = %q{edn-abnf implements converters and miscellaneous tools for CBOR EDN's ABNF}
6
6
  s.author = "Carsten Bormann"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: edn-abnf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.13
4
+ version: 0.5.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carsten Bormann