Skip to content

Commit

Permalink
feat: handle parsing of list arguments in func testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
scgkiran committed Nov 11, 2024
1 parent 5b70acd commit 3d6abbf
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
52 changes: 52 additions & 0 deletions tests/coverage/test_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,58 @@ def test_parse_decimal_example_with_nan():
assert test_file.testcases[0].args[1] == CaseLiteral("0.5", "dec<38,1>")


def test_parse_string_example():
header = make_header("v1.0", "extensions/functions_string.yaml")
tests = """# basic
concat('abc'::str, 'def'::str) = 'abcdef'::str
regexp_string_split('HHHelloooo'::str, 'Hel+'::str) = ['HH', 'oooo']::List<str>
octet_length('à'::str) = 2::i64
octet_length('😄'::str) = 4::i64
"""
test_file = parse_string(header + tests)
assert len(test_file.testcases) == 4
assert test_file.testcases[0].func_name == "concat"
assert test_file.testcases[0].base_uri == "extensions/functions_string.yaml"
assert test_file.testcases[0].group.name == "basic"
assert test_file.testcases[0].result == CaseLiteral("'abcdef'", "str")

assert test_file.testcases[1].func_name == "regexp_string_split"
assert test_file.testcases[1].base_uri == "extensions/functions_string.yaml"
assert test_file.testcases[1].group.name == "basic"
assert test_file.testcases[1].result == CaseLiteral(["'HH'", "'oooo'"], "List<str>")
assert test_file.testcases[1].args[0] == CaseLiteral("'HHHelloooo'", "str")
assert test_file.testcases[1].args[1] == CaseLiteral("'Hel+'", "str")

assert test_file.testcases[2].func_name == "octet_length"
assert test_file.testcases[2].base_uri == "extensions/functions_string.yaml"
assert test_file.testcases[2].group.name == "basic"
assert test_file.testcases[2].result == CaseLiteral("2", "i64")
assert test_file.testcases[2].args[0] == CaseLiteral("'à'", "str")

assert test_file.testcases[3].func_name == "octet_length"
assert test_file.testcases[3].base_uri == "extensions/functions_string.yaml"
assert test_file.testcases[3].group.name == "basic"
assert test_file.testcases[3].result == CaseLiteral("4", "i64")
assert test_file.testcases[3].args[0] == CaseLiteral("'😄'", "str")


def test_parse_string_list_example():
header = make_header("v1.0", "extensions/functions_string.yaml")
tests = """# basic
some_func('abc'::str, 'def'::str) = [1, 2, 3, 4, 5, 6]::List<i8>
"""
test_file = parse_string(header + tests)
assert len(test_file.testcases) == 1
assert test_file.testcases[0].func_name == "some_func"
assert test_file.testcases[0].base_uri == "extensions/functions_string.yaml"
assert test_file.testcases[0].group.name == "basic"
assert test_file.testcases[0].result == CaseLiteral(
["1", "2", "3", "4", "5", "6"], "List<i8>"
)
assert test_file.testcases[0].args[0] == CaseLiteral("'abc'", "str")
assert test_file.testcases[0].args[1] == CaseLiteral("'def'", "str")


def test_parse_aggregate_func_test():
header = make_aggregate_test_header("v1.0", "extensions/functions_arithmetic.yaml")
tests = """# basic
Expand Down
15 changes: 15 additions & 0 deletions tests/coverage/visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ def visitArgument(self, ctx: FuncTestCaseParser.ArgumentContext):
return self.visitIntervalYearArg(ctx.intervalYearArg())
if ctx.nullArg() is not None:
return self.visitNullArg(ctx.nullArg())
if ctx.listArg() is not None:
return self.visitListArg(ctx.listArg())

return CaseLiteral(value="unknown_value", type="unknown_type")

Expand Down Expand Up @@ -352,6 +354,19 @@ def visitIntervalYearArg(self, ctx: FuncTestCaseParser.IntervalYearArgContext):
value=ctx.IntervalYearLiteral().getText().strip("'"), type="iyear"
)

def visitListArg(self, ctx: FuncTestCaseParser.ListArgContext):
return CaseLiteral(
value=self.visitLiteralList(ctx.literalList()),
type=ctx.listType().getText(),
)

def visitLiteralList(self, ctx: FuncTestCaseParser.LiteralListContext):
values = []
for literal in ctx.literal():
value, _ = self.visitLiteral(literal)
values.append(value)
return values

def visitResult(self, ctx: FuncTestCaseParser.ResultContext):
if ctx.argument() is not None:
return self.visitArgument(ctx.argument())
Expand Down

0 comments on commit 3d6abbf

Please sign in to comment.