Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions test/toon/encode/objects_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,27 @@ defmodule Toon.Encode.ObjectsTest do

assert result == "age: 30\nname: Alice"
end

test "uses nested path key_order for nested objects" do
opts = %{
delimiter: ",",
length_marker: nil,
indent: 2,
indent_string: " ",
key_order: %{["user"] => ["first", "last"]},
key_folding: "off"
}

data = %{"user" => %{"last" => "Smith", "first" => "John"}}
result = Objects.encode(data, 0, opts) |> IO.iodata_to_binary()

# Nested "user" object should use specified order: first, last
assert result =~ "first: John"
assert result =~ "last: Smith"
# Verify "first" appears before "last" in the output
first_pos = :binary.match(result, "first")
last_pos = :binary.match(result, "last")
assert elem(first_pos, 0) < elem(last_pos, 0)
end
end
end
8 changes: 7 additions & 1 deletion test/toon/utils_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,15 @@ defmodule Toon.UtilsTest do
assert Utils.same_keys?(42) == false
end

test "returns false for list containing non-maps" do
test "returns false for list starting with non-map" do
# Exercises the fallback clause: def same_keys?(_), do: false
assert Utils.same_keys?([1, 2, 3]) == false
end

test "returns false for list with map followed by non-maps" do
# Exercises the Enum.all? logic with is_map check inside
assert Utils.same_keys?([%{"a" => 1}, 2, 3]) == false
end
end

describe "all_primitives?/1" do
Expand Down
Loading