Skip to content

Commit

Permalink
Coverts dot wild selector with property tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vrcca committed May 12, 2024
1 parent e0fe91d commit 50f1a2c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/parser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ defmodule JsonPathAccess.Parser do
alpha = [?A..?Z, ?a..?z]
digit = ?0..?9
name_first = utf8_string([?_, unicode | alpha], min: 1)
name_char = choice([ascii_string([digit], min: 1), name_first])
name_char = choice([utf8_string([digit], min: 1), name_first])

dot_member_name =
name_first
Expand Down
20 changes: 20 additions & 0 deletions test/json_path_access_property_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@ defmodule JsonPathAccessPropertyTest do
end
end

property "all dot wildcards selectors are returned as Access.all/1" do
check all fields <- list_of(one_of([dot_member_name(), dot_wild_selector()]), min_length: 1) do
dotted_fields = Enum.join(fields, ".")
path = "$.#{dotted_fields}"

expected_fields =
Enum.map(fields, fn
"*" -> Access.all()
field -> field
end)

assert expected_fields == JsonPathAccess.to_access(path)
end
end

# dot-selector = "." dot-member-name
# dot-member-name = name-first *name-char
# name-first =
Expand Down Expand Up @@ -47,4 +62,9 @@ defmodule JsonPathAccessPropertyTest do
defp digit do
string(?0..?9)
end

# dot-wild-selector = "." "*" ; dot followed by asterisk
defp dot_wild_selector do
constant("*")
end
end

0 comments on commit 50f1a2c

Please sign in to comment.