Skip to content

Commit

Permalink
Test encoding/decoding many documents in a row (#854)
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Cruz Viotti <[email protected]>
  • Loading branch information
jviotti authored Oct 9, 2024
1 parent 63a3a1e commit 3046d0b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
16 changes: 16 additions & 0 deletions test/runtime/decode_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,19 @@ TEST(JSONBinPack_Decoder, generic_decode_BOUNDED_MULTIPLE_8BITS_ENUM_FIXED) {
const sourcemeta::jsontoolkit::JSON expected{-5};
EXPECT_EQ(result, expected);
}

TEST(JSONBinPack_Decoder, ANY_PACKED_TYPE_TAG_BYTE_PREFIX_many) {
using namespace sourcemeta::jsonbinpack;
InputByteStream stream{0x15, 0x1d, 0x25};
Decoder decoder{stream};
ANY_PACKED_TYPE_TAG_BYTE_PREFIX options;
const auto result_1 = decoder.read(options);
const auto result_2 = decoder.read(options);
const auto result_3 = decoder.read(options);
const sourcemeta::jsontoolkit::JSON expected_1{1};
const sourcemeta::jsontoolkit::JSON expected_2{2};
const sourcemeta::jsontoolkit::JSON expected_3{3};
EXPECT_EQ(result_1, expected_1);
EXPECT_EQ(result_2, expected_2);
EXPECT_EQ(result_3, expected_3);
}
11 changes: 11 additions & 0 deletions test/runtime/encode_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,14 @@ TEST(JSONBinPack_Encoder, generic_encode_BOUNDED_MULTIPLE_8BITS_ENUM_FIXED) {
encoder.write(document, options);
EXPECT_BYTES(stream, {0x00});
}

TEST(JSONBinPack_Encoder, ANY_PACKED_TYPE_TAG_BYTE_PREFIX_many) {
using namespace sourcemeta::jsonbinpack;
OutputByteStream stream{};
Encoder encoder{stream};
ANY_PACKED_TYPE_TAG_BYTE_PREFIX options;
encoder.write(sourcemeta::jsontoolkit::JSON{1}, options);
encoder.write(sourcemeta::jsontoolkit::JSON{2}, options);
encoder.write(sourcemeta::jsontoolkit::JSON{3}, options);
EXPECT_BYTES(stream, {0x15, 0x1d, 0x25});
}

0 comments on commit 3046d0b

Please sign in to comment.