Skip to content

Commit

Permalink
More specs and simple values
Browse files Browse the repository at this point in the history
  • Loading branch information
PJK committed May 12, 2015
1 parent c8ee77c commit 110c923
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/libcbor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
require 'libcbor/inner/lib_c'
require 'libcbor/cache'
require 'libcbor/tag'
require 'libcbor/simple_value'
require 'libcbor/byte_string'
require 'libcbor/helpers'
require 'libcbor/item'
Expand Down
5 changes: 5 additions & 0 deletions lib/libcbor/simple_value.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module CBOR
class SimpleValue < Fixnum

end
end
17 changes: 17 additions & 0 deletions spec/decoding_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,23 @@
end
end

context 'for "false" simple value' do
subject { CBOR.decode("\xF4") }

it 'provides translation' do
expect(subject).to eq false
end
end

context 'for "0" simple value' do
subject { CBOR.decode("\xE8\xFF") }

#TODO: enable this after libcbor is fixed
xit 'provides translation' do
expect(subject).to eq SimpleValue.new(255)
end
end

context 'for 3.14 float' do
subject { CBOR.decode([250, 64, 72, 245, 195].pack('c*')) }

Expand Down
14 changes: 14 additions & 0 deletions spec/item_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'spec_helper'

module CBOR
describe Item do
context 'upon invalid FFI return value' do
it 'fails predictably' do
expect(LibCBOR).to receive(:cbor_typeof).and_return(:foo)
expect {
Item.new(double).value
}.to raise_exception /Unknown type/
end
end
end
end
10 changes: 8 additions & 2 deletions spec/streaming/buffered_decoder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@ module CBOR
module Streaming
describe BufferedDecoder do
let(:counter) { double }
let(:data) { "\x81\x2" }
let(:data) { "\x81\x2\x60\x40" }

it 'works for nested data' do
it 'decodes nested data' do
expect(counter).to receive(:tick).exactly(1)
BufferedDecoder.new(
integer: -> (val) { expect(val).to eq 2; counter.tick }
) << data
end

it 'raises for invalid input' do
expect {
BufferedDecoder.new << "\x1F" # Reserved
}.to raise_exception DecodingError
end
end
end
end

0 comments on commit 110c923

Please sign in to comment.