Skip to content

Commit

Permalink
Deal with '' tokens.
Browse files Browse the repository at this point in the history
  • Loading branch information
orenbenkiki committed Jun 8, 2024
1 parent fb0dbe9 commit ebc52d6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/v0.1.0/.documenter-siteinfo.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"documenter":{"julia_version":"1.10.0","generation_timestamp":"2024-06-08T11:10:42","documenter_version":"1.4.1"}}
{"documenter":{"julia_version":"1.10.0","generation_timestamp":"2024-06-08T17:04:59","documenter_version":"1.4.1"}}
12 changes: 10 additions & 2 deletions src/tokens.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ inject a value. Often this happens when using `\$(...)` to embed values into a q
instead write something like `/ \$(escape_value(axis)) @ \$(escape_value(property))`.
"""
function escape_value(value::AbstractString)::String
return replace(value, (character -> !is_value_char(character)) => s"\\\0") # NOJET
if value == ""
return "''"
else
return replace(value, (character -> !is_value_char(character)) => s"\\\0") # NOJET
end
end

"""
Expand All @@ -59,7 +63,11 @@ Undo [`escape_value`](@ref), that is, given an `escaped` value with a `\\` chara
the `\\` to get back the original string value.
"""
function unescape_value(escaped::AbstractString)::String
return replace(escaped, r"\\(.)" => s"\1")
if escaped == "''"
return ""
else
return replace(escaped, r"\\(.)" => s"\1")
end
end

"""
Expand Down
4 changes: 4 additions & 0 deletions test/queries.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ end
nested_test("queries") do
daf = MemoryDaf(; name = "memory!")

nested_test("empty") do
@test string(Query("/ metacell != ''")) == "/ metacell != ''"
end

nested_test("combine") do
nested_test("one") do
@test string(Lookup("score")) == ": score"
Expand Down
8 changes: 7 additions & 1 deletion test/tokens.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@ end

nested_test("tokens") do
nested_test("escape") do
nested_test("empty") do
test_escape_value("", "''")
return nothing
end

nested_test("unicode") do
test_escape_value("א", "א")
return test_escape_value("ת", "ת")
test_escape_value("ת", "ת")
return nothing
end

nested_test("alpha") do
Expand Down

0 comments on commit ebc52d6

Please sign in to comment.