diff --git a/spec/cbor/from_cbor_spec.cr b/spec/cbor/from_cbor_spec.cr index 413d68f..81710b8 100644 --- a/spec/cbor/from_cbor_spec.cr +++ b/spec/cbor/from_cbor_spec.cr @@ -16,9 +16,7 @@ describe "CBOR helpers on basic types" do {Bool, Bytes[0xf4], false}, {Bool, Bytes[0xf5], true}, {Bytes, Bytes[0x44, 0x01, 0x02, 0x03, 0x04], Bytes[0x01, 0x02, 0x03, 0x04]}, - {Time, - Bytes[0xc0, 0x74, 0x32, 0x30, 0x31, 0x33, 0x2d, 0x30, 0x33, 0x2d, 0x32, 0x31, 0x54, 0x32, 0x30, 0x3a, 0x30, 0x34, 0x3a, 0x30, 0x30, 0x5a], - Time::Format::RFC_3339.parse("2013-03-21T20:04:00Z")}, + {Time, Bytes[0xc0, 0x74, 0x32, 0x30, 0x31, 0x33, 0x2d, 0x30, 0x33, 0x2d, 0x32, 0x31, 0x54, 0x32, 0x30, 0x3a, 0x30, 0x34, 0x3a, 0x30, 0x30, 0x5a], Time::Format::RFC_3339.parse("2013-03-21T20:04:00Z")}, {Time, Bytes[0xc1, 0x1a, 0x51, 0x4b, 0x67, 0xb0], Time.unix(1363896240)}, {Time, Bytes[0xc1, 0xfb, 0x41, 0xd4, 0x52, 0xd9, 0xec, 0x20, 0x00, 0x00], Time.unix_ms((BigFloat.new(1363896240.5) * 1000).to_u64)}, {Nil, Bytes[0xf6], nil}, @@ -27,17 +25,11 @@ describe "CBOR helpers on basic types" do {Float64, Bytes[0xfa, 0x47, 0xc3, 0x50, 0x00], 100000.0_f64}, {Set(Int8), Bytes[0x83, 0x01, 0x02, 0x03], Set(Int8){1, 2, 3}}, {Array(Int8), Bytes[0x83, 0x01, 0x02, 0x03], [1_i8, 2_i8, 3_i8]}, - {Array(Array(Int8) | Int8), - Bytes[0x83, 0x01, 0x82, 0x02, 0x03, 0x82, 0x04, 0x05], - [1_i8, [2_i8, 3_i8], [4_i8, 5_i8]]}, + {Array(Array(Int8) | Int8), Bytes[0x83, 0x01, 0x82, 0x02, 0x03, 0x82, 0x04, 0x05], [1_i8, [2_i8, 3_i8], [4_i8, 5_i8]]}, {Array(UInt8), Bytes[0x9f, 0xff], [] of UInt8}, {Array(UInt8), Bytes[0x9f, 0x01, 0xff], [1_u8] of UInt8}, - {Array(Int32), - Bytes[0x9f, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x18, 0x18, 0x19, 0xff], - [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]}, - {Array(Array(Int8) | Int8), - Bytes[0x9f, 0x01, 0x82, 0x02, 0x03, 0x9f, 0x04, 0x05, 0xff, 0xff], - [1_i8, [2_i8, 3_i8], [4_i8, 5_i8]]}, + {Array(Int32), Bytes[0x9f, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x18, 0x18, 0x19, 0xff], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]}, + {Array(Array(Int8) | Int8), Bytes[0x9f, 0x01, 0x82, 0x02, 0x03, 0x9f, 0x04, 0x05, 0xff, 0xff], [1_i8, [2_i8, 3_i8], [4_i8, 5_i8]]}, {Hash(UInt8, UInt8), Bytes[0xa0], {} of UInt8 => UInt8}, {Hash(UInt8, UInt8), Bytes[0xa2, 0x01, 0x02, 0x03, 0x04], Hash(UInt8, UInt8){1 => 2, 3 => 4}}, {TestEnum, Bytes[0x1a, 0x00, 0x00, 0x00, 0x01], TestEnum::Foo}, @@ -47,6 +39,9 @@ describe "CBOR helpers on basic types" do {BigInt, Bytes[0x18, 0x18], BigInt.new(24)}, # BigInt from int {BigDecimal, Bytes[0xc4, 0x82, 0x21, 0x19, 0x6a, 0xb3], BigDecimal.new(273.15)}, {BigDecimal, Bytes[0xc5, 0x82, 0x20, 0x03], BigDecimal.new(1.5)}, + {Hash(String, Int32 | Array(Int32)), Bytes[0xbf, 0x61, 0x61, 0x01, 0x61, 0x62, 0x9f, 0x02, 0x03, 0xff, 0xff], {"a" => 1, "b" => [2, 3]}}, + {Array(String | Hash(String, String)), Bytes[0x82, 0x61, 0x61, 0xbf, 0x61, 0x62, 0x61, 0x63, 0xff], ["a", {"b" => "c"}]}, + {Hash(String, Bool | Int32), Bytes[0xbf, 0x63, 0x46, 0x75, 0x6e, 0xf5, 0x63, 0x41, 0x6d, 0x74, 0x21, 0xff], {"Fun" => true, "Amt" => -2}}, ] tests.each do |tt| diff --git a/src/cbor/from_cbor.cr b/src/cbor/from_cbor.cr index f54dbb1..72a09b8 100644 --- a/src/cbor/from_cbor.cr +++ b/src/cbor/from_cbor.cr @@ -213,7 +213,7 @@ def Union.new(decoder : CBOR::Decoder) return decoder.read_nil {% end %} {% if T.includes? Bool %} - when CBOR::Token::BoolT + when CBOR::Token::SimpleValueT return decoder.read_bool {% end %} {% if T.includes? String %}