Skip to content

Commit 9b44ef4

Browse files
committed
add tests for public interface
1 parent 15d339b commit 9b44ef4

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

test/msgpack_test.exs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,38 @@ defmodule MsgpackTest do
323323
end
324324
end
325325

326+
describe "Streaming" do
327+
test "provides a lossless round trip for streaming encode and decode" do
328+
terms = [1, "elixir", true, %{"key" => "value"}]
329+
330+
result =
331+
terms
332+
|> Msgpack.encode_stream()
333+
|> Stream.map(fn {:ok, binary} -> binary end)
334+
|> Msgpack.decode_stream()
335+
|> Enum.to_list()
336+
337+
assert result == terms
338+
end
339+
340+
test "encode_stream handles unencodable terms gracefully" do
341+
terms = [1, :elixir, 4]
342+
343+
expected = [
344+
{:ok, <<1>>},
345+
{:ok, <<166, 101, 108, 105, 120, 105, 114>>},
346+
{:ok, <<4>>},
347+
]
348+
349+
result =
350+
terms
351+
|> Msgpack.encode_stream()
352+
|> Enum.to_list()
353+
354+
assert result == expected
355+
end
356+
end
357+
326358
# ==== Helpers ====
327359

328360
defp assert_encode(input, expected_binary) do

0 commit comments

Comments
 (0)