Skip to content

Commit

Permalink
Improve parse test library failure messages (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
liamawhite authored Dec 24, 2024
1 parent d6f30e3 commit 3c42270
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions test/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,20 @@ func RunTests[T any](t *testing.T, tests []ParserTest[T]) {
t.Run(test.Name, func(t *testing.T) {
in := NewInput(test.Input)
match, ok, err := test.Parser(in)
assert.Equal(t, test.ExpectedOK, ok)
assert.Equal(t, test.ExpectedMatch, match)
if test.ExpectedOK {
assert.True(t, ok, "Expected match")
} else {
assert.False(t, ok, "Expected no match")
}
assert.Equal(t, test.ExpectedMatch, match, "Expected result doesn't match")
if test.WantErr {
assert.Error(t, err)
assert.Error(t, err, "Expected error")
} else {
assert.NoError(t, err)
assert.NoError(t, err, "Expected no error")
}

remaining, _, _ := StringWhileNot(EOF[string]())(in)
assert.Equal(t, test.RemainingInput, remaining)
assert.Equal(t, test.RemainingInput, remaining, "Remaining input doesn't match")
})
}
}
Expand Down

0 comments on commit 3c42270

Please sign in to comment.