Skip to content

Commit

Permalink
Refactor diagnostic tests parsing logic a bit
Browse files Browse the repository at this point in the history
This should make it easier to refactor the file types in a future
commit, such as by removing the path field.
  • Loading branch information
yorickpeterse committed Jan 27, 2025
1 parent 70447a9 commit 09eeb48
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions std/test/compiler/test_diagnostics.inko
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,19 @@ let LPAREN = 40
let RPAREN = 41
let COLON = 58

fn parse_test(file: ReadOnlyFile) -> Result[Array[Diagnostic], String] {
let reader = BufferedReader.new(mut file)
fn parse_test(path: ref Path) -> Result[Array[Diagnostic], String] {
let reader = try ReadOnlyFile
.new(path.clone)
.map(fn (f) { BufferedReader.new(f) })
.map_error(fn (e) { e.to_string })
let buffer = ByteArray.new
let diags = []

loop {
match reader.read_line(buffer, inclusive: true) {
case Ok(0) -> break
case Ok(_) -> {}
case Error(e) -> throw 'failed to read a line from ${file.path}: ${e}'
case Error(e) -> throw 'failed reading a new line: ${e}'
}

match buffer.opt(0) {
Expand Down Expand Up @@ -283,11 +286,7 @@ fn pub tests(t: mut Tests) {
let name = test_file.tail.strip_suffix('.inko').get

t.test('inko check ${name}', fn move (t) {
let file = ReadOnlyFile.new(test_file.clone).or_panic(
'the test file ${test_file} must exist',
)

match parse_test(file) {
match parse_test(test_file) {
case Ok(exp) -> t.equal(check(compiler, name, test_file.clone), exp)
case Error(e) -> panic('failed to parse ${test_file}: ${e}')
}
Expand Down

0 comments on commit 09eeb48

Please sign in to comment.