Skip to content

Commit

Permalink
Fix check_remaining_shortcuts tests
Browse files Browse the repository at this point in the history
Simplify regex
  • Loading branch information
gwehrle committed Dec 4, 2024
1 parent 61b856f commit 9360657
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/shortcuts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,11 @@ Checks for unreplaced Overpass shortcuts in the query and throws errors if found
function check_remaining_shortcuts(query::AbstractString)::Nothing

# This regex matches placeholders in double curly braces ({{...}}), with special handling for "date":
# - Case-insensitive (`(?i)`), supporting variations like "{{DATE}}" or "{{Date:+1day}}".
# - (`(?is)`): case-insensitive (`i`) and dot matches all characters including new line (`s`)
# supporting variations like "{{DATE}}" or "{{Date:+1day}}".
# - Captures:
# - Group 1: Entire placeholder.
# - Group 2: The "date" keyword (if present).
# - Group 3: The content after "date" (e.g., "3 days"), excluding colons and spaces.
# - Group 4: Other placeholders (e.g., "bbox", "center").
pattern = r"(?i)\{\{\s*((date)\s*[:+]{1,2}\s*([^:{}\s][^{}]*?)|(.+?))\s*\}\}"
# - `shortcut`: whole shortcut without brackets
pattern = r"(?is)\{\{\s*(?<shortcut>.+?)\s*\}\}"

for match in eachmatch(pattern, query)
if match[:shortcut] == "bbox"
Expand All @@ -186,7 +184,10 @@ function check_remaining_shortcuts(query::AbstractString)::Nothing
elseif match[:shortcut] == "center"
throw(MissingException("""{{center}} found in query, but no value specified.
Use keywordargument "center": Overpass.query(…, center = (48.22, 16.36))"""))
elseif match[:shortcut] == "date"
elseif occursin("date", match[:shortcut])
throw(DomainError(query,
"""Unsupported date shortcut {{""" * match[:shortcut] *
"""}}. Check spelling or file an bug report if you think this should work."""))
println("date shortcut misspelled")
println(match)
else
Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ configure!(;
@test_throws MissingException Overpass.check_remaining_shortcuts("{{bbox}}")
@test_throws MissingException Overpass.check_remaining_shortcuts("{{center}}")
@test_throws DomainError Overpass.check_remaining_shortcuts("{{ custom }}")
@test_throws DomainError Overpass.check_remaining_shortcuts("{{date: 1decade}}")
end
end

Expand Down

0 comments on commit 9360657

Please sign in to comment.