~arestifo/crystal-cbor

e05b209ed39a40a9da183b503dc44aa041d9edfc — Alberto Restifo 1 year, 10 months ago 2e76c0b
Pass io to the encoder in to_cbor + regression test
2 files changed, 10 insertions(+), 1 deletions(-)

M spec/cbor/to_cbor_spec.cr
M src/cbor/to_cbor.cr
M spec/cbor/to_cbor_spec.cr => spec/cbor/to_cbor_spec.cr +9 -0
@@ 58,4 58,13 @@ describe "to_cbor" do
      encoder.to_slice.hexdump.should eq(Bytes[0xc1, 0x1a, 0x51, 0x4b, 0x67, 0xb0].hexdump)
    end
  end

  describe "encodes to an IO" do
    it "encodes a string" do
      io = IO::Memory.new
      "a".to_cbor(io)

      io.to_slice.should eq(Bytes[0x61, 0x61])
    end
  end
end

M src/cbor/to_cbor.cr => src/cbor/to_cbor.cr +1 -1
@@ 6,7 6,7 @@ class Object
  end

  def to_cbor(io : IO)
    encoder = CBOR::Encoder.new
    encoder = CBOR::Encoder.new(io)
    to_cbor(encoder)
    self
  end