mirror of
https://github.com/odin-lang/Odin.git
synced 2026-07-11 10:29:32 +00:00
Merge pull request #6861 from BradLewis/fix/parse-multiline-ternary
Correct divergence with expr levels causing failures with the odin parser
This commit is contained in:
@@ -94,3 +94,40 @@ test_parse_stb_image :: proc(t: ^testing.T) {
|
||||
testing.expectf(t, value.syntax_error_count == 0, "%v should contain zero errors", key)
|
||||
}
|
||||
}
|
||||
|
||||
@test
|
||||
test_parse_multiline_ternary :: proc(t: ^testing.T) {
|
||||
context.allocator = context.temp_allocator
|
||||
runtime.DEFAULT_TEMP_ALLOCATOR_TEMP_GUARD()
|
||||
file := ast.File{
|
||||
fullpath = "test.odin",
|
||||
src = `
|
||||
package main
|
||||
|
||||
my_func :: proc (cond: bool, a: string, b: string) -> string {
|
||||
out := (
|
||||
cond
|
||||
? a
|
||||
: b
|
||||
)
|
||||
return out
|
||||
}
|
||||
`,
|
||||
}
|
||||
|
||||
p := parser.default_parser()
|
||||
|
||||
p.err = proc(pos: tokenizer.Pos, format: string, args: ..any) {
|
||||
message := fmt.tprintf(format, ..args)
|
||||
log.errorf("%s(%d:%d): %s", pos.file, pos.line, pos.column, message)
|
||||
}
|
||||
|
||||
p.warn = proc(pos: tokenizer.Pos, format: string, args: ..any) {
|
||||
message := fmt.tprintf(format, ..args)
|
||||
log.warnf("%s(%d:%d): %s", pos.file, pos.line, pos.column, message)
|
||||
}
|
||||
|
||||
ok := parser.parse_file(&p, &file)
|
||||
testing.expect(t, ok, "bad parse")
|
||||
testing.expect(t, file.syntax_error_count == 0, "should contain zero errors")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user