Skip to content

Commit f1e2dd1

Browse files
committed
Improve test coverage for numeric string object key fix
1 parent a00290a commit f1e2dd1

3 files changed

Lines changed: 16 additions & 10 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ jobs:
3737
strategy:
3838
matrix:
3939
include:
40+
- otp: "28"
41+
elixir: "1.18"
4042
- otp: "27"
4143
elixir: "1.18"
4244
- otp: "26"

test/property_test.exs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -613,15 +613,6 @@ defmodule Torque.PropertyTest do
613613
{:ok, doc2} = Torque.parse(~s({"a":[1,2,3]}))
614614
assert {:error, :no_such_field} = Torque.get(doc2, "/a/0/x")
615615
end
616-
617-
property "numeric string keys on objects always return no_such_field" do
618-
check all(n <- integer(0..100)) do
619-
json = ~s({"#{n}": "val"})
620-
{:ok, doc} = Torque.parse(json)
621-
# A purely numeric segment on an object (not an array) never matches
622-
assert {:error, :no_such_field} = Torque.get(doc, "/#{n}")
623-
end
624-
end
625616
end
626617

627618
# ---- get/3 raises on nesting_too_deep ----

test/torque_test.exs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,21 @@ defmodule Torque.PointerTest do
139139
assert {:ok, "ten"} = Torque.get(doc, "/10")
140140
end
141141

142-
test "nested numeric string object key id reachable via JSON Pointer" do
142+
test "nested numeric string object key is reachable via JSON Pointer" do
143143
{:ok, doc} = Torque.parse(~s({"k1":"v1","k2":{"10":"ten","n1":"nv1"}}))
144144
assert {:ok, "v1"} = Torque.get(doc, "/k1")
145145
assert {:ok, %{"10" => "ten", "n1" => "nv1"}} = Torque.get(doc, "/k2")
146146
assert {:ok, "ten"} = Torque.get(doc, "/k2/10")
147147
assert {:ok, "nv1"} = Torque.get(doc, "/k2/n1")
148148
end
149+
150+
test "numeric segment dispatches on node type" do
151+
{:ok, obj_doc} = Torque.parse(~s({"0":"from-object"}))
152+
{:ok, arr_doc} = Torque.parse(~s(["from-array"]))
153+
154+
assert {:ok, "from-object"} = Torque.get(obj_doc, "/0")
155+
assert {:ok, "from-array"} = Torque.get(arr_doc, "/0")
156+
end
149157
end
150158

151159
describe "get_many/2" do
@@ -164,6 +172,11 @@ defmodule Torque.PointerTest do
164172
assert [] = Torque.get_many(doc, [])
165173
end
166174

175+
test "numeric string object keys" do
176+
{:ok, doc} = Torque.parse(~s({"1":"one","2":"two"}))
177+
assert [{:ok, "one"}, {:ok, "two"}] = Torque.get_many(doc, ["/1", "/2"])
178+
end
179+
167180
test "all fields", %{doc: doc} do
168181
paths = [
169182
"/id",

0 commit comments

Comments
 (0)