Skip to content

Commit b6e14c7

Browse files
committed
Test suite audit: fix names, remove vacuous property, add coverage
1 parent 0bc63ea commit b6e14c7

4 files changed

Lines changed: 20 additions & 13 deletions

File tree

test/decode_test.exs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,5 @@ defmodule Torque.DecodeTest do
108108
Torque.decode!("{invalid}")
109109
end
110110
end
111-
112111
end
113112
end

test/encode_test.exs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ defmodule Torque.EncodeTest do
9696
assert [%{"id" => 1}, %{"id" => 2}] = Jason.decode!(json)
9797
end
9898

99-
test "atom values encoded as strings" do
99+
test "atom map values encoded as strings" do
100100
assert {:ok, json} = Torque.encode(%{status: :active})
101101
assert %{"status" => "active"} = Jason.decode!(json)
102102
end
@@ -120,6 +120,12 @@ defmodule Torque.EncodeTest do
120120
Torque.encode!(self())
121121
end
122122
end
123+
124+
test "invalid UTF-8 binary raises" do
125+
assert_raise ArgumentError, ~r/invalid_utf8/, fn ->
126+
Torque.encode!(<<0x80>>)
127+
end
128+
end
123129
end
124130

125131
describe "encode_to_iodata/1" do
@@ -138,5 +144,11 @@ defmodule Torque.EncodeTest do
138144
Torque.encode_to_iodata(self())
139145
end
140146
end
147+
148+
test "invalid UTF-8 binary raises ArgumentError" do
149+
assert_raise ArgumentError, ~r/invalid_utf8/, fn ->
150+
Torque.encode_to_iodata(<<0x80>>)
151+
end
152+
end
141153
end
142154
end

test/property_test.exs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,13 @@ defmodule Torque.PropertyTest do
541541
assert {:error, :malformed_proplist} = Torque.encode({[{:a, :b, :c}]})
542542
end
543543

544+
# BEAM rejects non-finite floats (both arithmetic overflow and binary_to_term
545+
# validation), so this NIF code path is not reachable from Elixir.
546+
@tag :skip
547+
test "non-finite float returns non_finite_float" do
548+
assert {:error, :non_finite_float} = Torque.encode(:infinity)
549+
end
550+
544551
test "encode_to_iodata raises with unsupported_type message" do
545552
assert_raise ArgumentError, ~r/unsupported_type/, fn ->
546553
Torque.encode_to_iodata(self())
@@ -589,17 +596,6 @@ defmodule Torque.PropertyTest do
589596
end
590597
end
591598

592-
property "numeric-looking string keys work alongside integer array indexes" do
593-
check all(n <- integer(0..100)) do
594-
# Object key that looks like an integer — should be treated as a string key
595-
json = ~s({"#{n}": "string_val"})
596-
{:ok, doc} = Torque.parse(json)
597-
# Accessing "/N" on an object should still find the string key "N"
598-
result = Torque.get(doc, "/#{n}")
599-
assert match?({:ok, _}, result) or match?({:error, :no_such_field}, result)
600-
end
601-
end
602-
603599
test "path without leading slash returns no_such_field" do
604600
{:ok, doc} = Torque.parse(~s({"a":1}))
605601
assert {:error, :no_such_field} = Torque.get(doc, "a")

0 commit comments

Comments
 (0)