Skip to content

Commit

Permalink
compiler: Add test covering a newly found bug
Browse files Browse the repository at this point in the history
DCO-1.1-Signed-off-by: Ellie <[email protected]>
  • Loading branch information
ell1e committed Nov 18, 2023
1 parent e750f10 commit f5de6a6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
11 changes: 11 additions & 0 deletions src/compiler/ast/test_expr.h64
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ func test_parse_expression {
assert(v1.kind == ast.N_EXPR_LIT)
assert(v1.value == 5)

tokens = token.token_list_from_str_list([
"blu", ".", "A", "+", "blu", ".", "B"])
var v1 = expr.parse_expression(
tokens, 1, msgs, project_file=none, debug=no
) later:
await v1
assert(msgs.len == 0)
assert(v1 != none)
assert(v1.token_len == 7)
assert(v1.kind == ast.N_EXPR_BINOP)

tokens = token.token_list_from_str_list([
"not", "5", "*", "3", "+", "-", "(",
"23", ")", "ignored_10th_token"])
Expand Down
26 changes: 20 additions & 6 deletions src/compiler/ast/test_stmt.h64
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,37 @@ func test_parse_func_stmt {
}

func test_parse_complex {
var msgs

msgs = []
var v1 = ast.parse_str_to_ast(
"if bla != (not bla.attr) {"
" throw new ValueError('oop')"
"}", debug=no
) later:

await v1
if msgs.len > 0 {
for msg in msgs {
if v1.msgs.len > 0 {
for msg in v1.msgs {
print("Test got invalid error: " + msg.as_terminal_str())
}
}
assert(v1 != none)
assert(msgs.len == 0)
assert(v1.msgs.len == 0)
assert(v1.stmts.len == 1)
assert(v1.stmts[1].kind == ast.N_STMT_IF)

v1 = ast.parse_str_to_ast(
"var v = blu.A + blu.B", debug=no
) later:

await v1
if v1.msgs.len > 0 {
for msg in v1.msgs {
print("Test got invalid error: " + msg.as_terminal_str())
}
}
assert(v1 != none)
assert(v1.msgs.len == 0)
assert(v1.stmts.len == 1)
assert(v1.stmts[1].kind == ast.N_STMT_VAR)
}

func test_parse_inline_if {
Expand Down

0 comments on commit f5de6a6

Please sign in to comment.