native test framework
This commit is contained in:
@@ -3002,7 +3002,7 @@ decode_multiline_string :: proc(parser: ^Parser, tok: token.Token) -> string {
|
||||
return fmt.aprintf("%s", strings.to_string(builder), allocator=parser.module.allocator)
|
||||
}
|
||||
|
||||
parse_import :: proc(parser: ^Parser, alias: token.Token, start: token.Token) {
|
||||
parse_import :: proc(parser: ^Parser, alias: token.Token, start: token.Token, test_only := false) {
|
||||
skip_newlines(parser)
|
||||
path_token := current(parser)
|
||||
if path_token.kind != .String {
|
||||
@@ -3018,6 +3018,7 @@ parse_import :: proc(parser: ^Parser, alias: token.Token, start: token.Token) {
|
||||
file=parser.file,
|
||||
target=ast.INVALID_PACKAGE,
|
||||
valid=false,
|
||||
test_only=test_only,
|
||||
diagnostic=source.INVALID_DIAGNOSTIC,
|
||||
})
|
||||
_ = finish_statement(parser)
|
||||
@@ -3033,13 +3034,45 @@ parse_import :: proc(parser: ^Parser, alias: token.Token, start: token.Token) {
|
||||
file=parser.file,
|
||||
target=ast.INVALID_PACKAGE,
|
||||
valid=true,
|
||||
test_only=test_only,
|
||||
diagnostic=source.INVALID_DIAGNOSTIC,
|
||||
})
|
||||
_ = finish_statement(parser)
|
||||
}
|
||||
|
||||
parse_test :: proc(parser: ^Parser, name: token.Token) {
|
||||
advance(parser) // consume 'test'
|
||||
skip_newlines(parser)
|
||||
if current(parser).kind != .Left_Brace {
|
||||
source.add(parser.diagnostics, current(parser).span, "expected '{' after test name")
|
||||
_ = finish_statement(parser)
|
||||
return
|
||||
}
|
||||
body := parse_block(parser)
|
||||
append(&parser.module.functions, ast.Function{
|
||||
span=span_from(name.span, previous(parser).span),
|
||||
name=name.symbol,
|
||||
pkg=parser.pkg,
|
||||
file=parser.file,
|
||||
test=true,
|
||||
has_body=true,
|
||||
result=types.VOID,
|
||||
body=body,
|
||||
diagnostic=source.INVALID_DIAGNOSTIC,
|
||||
})
|
||||
}
|
||||
|
||||
parse_top_level :: proc(parser: ^Parser) {
|
||||
hide_token, file_hidden := allow(parser, .Keyword_Hide)
|
||||
if current(parser).kind == .Keyword_Test && peek(parser).kind == .Keyword_Import {
|
||||
if file_hidden {
|
||||
source.add(parser.diagnostics, hide_token.span, "test imports cannot use 'hide'")
|
||||
}
|
||||
start := advance(parser)
|
||||
advance(parser) // consume 'import'
|
||||
parse_import(parser, token.Token{}, start, test_only=true)
|
||||
return
|
||||
}
|
||||
if current(parser).kind == .Keyword_Import {
|
||||
if file_hidden {
|
||||
source.add(parser.diagnostics, hide_token.span, "imports are already file-local and cannot use 'hide'")
|
||||
@@ -3058,6 +3091,13 @@ parse_top_level :: proc(parser: ^Parser) {
|
||||
return
|
||||
}
|
||||
name := advance(parser)
|
||||
if current(parser).kind == .Keyword_Test {
|
||||
if file_hidden {
|
||||
source.add(parser.diagnostics, hide_token.span, "test declarations cannot use 'hide'")
|
||||
}
|
||||
parse_test(parser, name)
|
||||
return
|
||||
}
|
||||
if current(parser).kind == .Colon_Colon {
|
||||
saved := parser.cursor
|
||||
advance(parser)
|
||||
|
||||
Reference in New Issue
Block a user