Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsing of booleanLiterals in cql2-text #96

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pygeofilter/parsers/cql2_text/grammar.lark
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func.2: attribute "(" expression ("," expression)* ")" -> function

envelope: "ENVELOPE"i "(" number number number number ")"

BOOLEAN: ( "TRUE" | "FALSE" )
BOOLEAN.2: ( "TRUE"i | "FALSE"i)

DOUBLE_QUOTED: "\"" /.*?/ "\""
SINGLE_QUOTED: "'" /.*?/ "'"
Expand Down
4 changes: 2 additions & 2 deletions pygeofilter/parsers/cql2_text/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ def INT(self, value):
def FLOAT(self, value):
return float(value)

def boolean(self, value):
return value in ("TRUE", "true", "T", "t", "1")
def BOOLEAN(self, value):
return value.lower() == "true"

def DOUBLE_QUOTED(self, token):
return token[1:-1]
Expand Down
33 changes: 33 additions & 0 deletions tests/parsers/cql2_text/test_parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from pygeofilter import ast
from pygeofilter.parsers.cql2_text import parse


def test_attribute_eq_true_uppercase():
result = parse("attr = TRUE")
assert result == ast.Equal(
ast.Attribute("attr"),
True,
)

def test_attribute_eq_true_lowercase():
result = parse("attr = true")
assert result == ast.Equal(
ast.Attribute("attr"),
True,
)


def test_attribute_eq_false_uppercase():
result = parse("attr = FALSE")
assert result == ast.Equal(
ast.Attribute("attr"),
False,
)


def test_attribute_eq_false_lowercase():
result = parse("attr = false")
assert result == ast.Equal(
ast.Attribute("attr"),
False,
)