@@ -6,16 +6,9 @@ defmodule Torque.PropertyTest do
66
77 # ---- Generators ----
88
9- # Non-empty alphanumeric key, guaranteed to not be purely numeric.
10- # Purely numeric keys (e.g. "2") are mis-routed through array-index lookup in
11- # pointer_lookup, so they can't be reached via JSON Pointer on objects.
9+ # Non-empty alphanumeric key.
1210 defp json_key do
13- filter ( string ( :alphanumeric , min_length: 1 , max_length: 15 ) , fn s ->
14- case Integer . parse ( s ) do
15- { _ , "" } -> false
16- _ -> true
17- end
18- end )
11+ string ( :alphanumeric , min_length: 1 , max_length: 15 )
1912 end
2013
2114 # Scalars that roundtrip exactly through Jason → Torque (no float precision issues)
@@ -286,6 +279,17 @@ defmodule Torque.PropertyTest do
286279 assert { :error , :no_such_field } == Torque . get ( doc , "/#{ missing_key } " )
287280 end
288281 end
282+
283+ property "get works for numeric top-level object keys" do
284+ check all (
285+ k <- integer ( 0 .. 99_999_999 ) |> map ( & Integer . to_string / 1 ) ,
286+ v <- json_scalar_exact ( )
287+ ) do
288+ json = Jason . encode! ( % { k => v } )
289+ { :ok , doc } = Torque . parse ( json )
290+ assert { :ok , v } == Torque . get ( doc , "/#{ k } " )
291+ end
292+ end
289293 end
290294
291295 describe "get_many consistency" do
@@ -609,15 +613,6 @@ defmodule Torque.PropertyTest do
609613 { :ok , doc2 } = Torque . parse ( ~s( {"a":[1,2,3]}) )
610614 assert { :error , :no_such_field } = Torque . get ( doc2 , "/a/0/x" )
611615 end
612-
613- property "numeric string keys on objects always return no_such_field" do
614- check all ( n <- integer ( 0 .. 100 ) ) do
615- json = ~s( {"#{ n } ": "val"})
616- { :ok , doc } = Torque . parse ( json )
617- # A purely numeric segment on an object (not an array) never matches
618- assert { :error , :no_such_field } = Torque . get ( doc , "/#{ n } " )
619- end
620- end
621616 end
622617
623618 # ---- get/3 raises on nesting_too_deep ----
0 commit comments