More documentation example testing.

This commit is contained in:
Maurice Makaay 2019-05-24 21:34:54 +00:00
parent 3e87e010fb
commit 070a215ac3
2 changed files with 34 additions and 6 deletions

View File

@ -18,15 +18,44 @@ func ExampleItemType() {
}
func ExampleError() {
error := parsekit.Error{
err := &parsekit.Error{
Message: "it broke down",
Line: 10,
Column: 42}
Column: 42,
}
fmt.Println(error.Error())
fmt.Println(error.ErrorFull())
fmt.Println(err.Error())
fmt.Printf("%s\n", err)
fmt.Println(err.ErrorFull())
// Output:
// it broke down
// it broke down
// it broke down after line 10, column 42
}
func ExampleError_Error() {
err := &parsekit.Error{
Message: "it broke down",
Line: 10,
Column: 42,
}
fmt.Println(err.Error())
fmt.Printf("%s\n", err)
// Output:
// it broke down
// it broke down
}
func ExampleError_ErrorFull() {
err := &parsekit.Error{
Message: "it broke down",
Line: 10,
Column: 42,
}
fmt.Println(err.ErrorFull())
// Output:
// it broke down after line 10, column 42
}

View File

@ -74,8 +74,7 @@ func (err *Error) Error() string {
// ErrorFull returns the current error message, including information about
// the position in the input where the error occurred.
func (err *Error) ErrorFull() string {
message := err.Error()
return fmt.Sprintf("%s after line %d, column %d", message, err.Line, err.Column)
return fmt.Sprintf("%s after line %d, column %d", err, err.Line, err.Column)
}
// EmitError emits a Parser error item to the client.