diff --git a/test/toon/encode/objects_test.exs b/test/toon/encode/objects_test.exs index 6cf1259..d16a325 100644 --- a/test/toon/encode/objects_test.exs +++ b/test/toon/encode/objects_test.exs @@ -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 diff --git a/test/toon/utils_test.exs b/test/toon/utils_test.exs index 641d2f3..f1c3e51 100644 --- a/test/toon/utils_test.exs +++ b/test/toon/utils_test.exs @@ -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