|
1 | 1 | %% coding: latin-1 |
2 | 2 | %%%------------------------------------------------------------------- |
3 | | -%%% Copyright (c) 2013-2018 Klarna AB |
| 3 | +%%% Copyright (c) 2013-2024 Klarna AB |
4 | 4 | %%% |
5 | 5 | %%% This file is provided to you under the Apache License, |
6 | 6 | %%% Version 2.0 (the "License"); you may not use this file |
@@ -235,10 +235,24 @@ parse_fixed_type_test() -> |
235 | 235 | ?assertEqual(ExpectedType, Fixed). |
236 | 236 |
|
237 | 237 | parse_bytes_value_test() -> |
238 | | - Json = <<"\\u0010\\u0000\\u00FF">>, |
239 | | - Value = parse_value(Json, avro_primitive:bytes_type(), none), |
| 238 | + RawJson = <<"{\"a\":\"\\u0010\\u0000\\u00FF\"}">>, |
| 239 | + #{<<"a">> := Bytes} = jsone:decode(RawJson), |
| 240 | + ?assertEqual([16,0,255], unicode:characters_to_list(Bytes, utf8)), |
| 241 | + Value = parse_value(Bytes, avro_primitive:bytes_type(), none), |
240 | 242 | ?assertEqual(avro_primitive:bytes(<<16,0,255>>), Value). |
241 | 243 |
|
| 244 | +bytes_value_encode_decode_test() -> |
| 245 | + Fields = [avro_record:define_field("a", bytes)], |
| 246 | + Schema = avro_record:type("Test", Fields, [{namespace, "name.space"}]), |
| 247 | + Bytes = iolist_to_binary(lists:seq(0, 255)), |
| 248 | + Record = avro_record:new(Schema, [{"a", Bytes}]), |
| 249 | + Json = avro_json_encoder:encode_value(Record), |
| 250 | + Lkup = fun(_) -> Schema end, |
| 251 | + Opts = avro:make_decoder_options([{is_wrapped, false}]), |
| 252 | + Decoded = avro_json_decoder:decode_value(Json, Schema, Lkup, Opts), |
| 253 | + ?assertEqual([{<<"a">>, Bytes}], Decoded), |
| 254 | + ok. |
| 255 | + |
242 | 256 | parse_record_value_test() -> |
243 | 257 | %% This test also tests parsing other types inside the record |
244 | 258 | TestRecord = get_test_record(), |
@@ -337,11 +351,13 @@ parse_map_value_test() -> |
337 | 351 |
|
338 | 352 | parse_fixed_value_test() -> |
339 | 353 | Type = avro_fixed:type("FooBar", 2), |
340 | | - Json = <<"\\u0001\\u007f">>, |
| 354 | + RawJson = <<"{\"a\":\"\\u0001\\u007f\"}">>, |
| 355 | + #{<<"a">> := Bytes} = jsone:decode(RawJson), |
| 356 | + ?assertEqual([1,127], unicode:characters_to_list(Bytes, utf8)), |
341 | 357 | ExpectedValue = avro_fixed:new(Type, <<1,127>>), |
342 | | - ?assertEqual(ExpectedValue, parse_value(Json, Type, none)), |
| 358 | + ?assertEqual(ExpectedValue, parse_value(Bytes, Type, none)), |
343 | 359 | ?assertEqual(<<1,127>>, |
344 | | - parse(Json, Type, none, |
| 360 | + parse(Bytes, Type, none, |
345 | 361 | avro:make_decoder_options([{is_wrapped, false}]))). |
346 | 362 |
|
347 | 363 | parse_value_with_lkup_fun_test() -> |
|
0 commit comments