initial commits

master
Charles Iliya Krempeaux 2023-11-28 06:26:36 -08:00
parent 6463d8503e
commit 61b26d3aa7
14 changed files with 193 additions and 117 deletions

View File

@ -11,11 +11,3 @@ const (
func errNotEOL(r rune) error { func errNotEOL(r rune) error {
return erorr.Errorf("eol: %q (%U) is not an end-of-line character", r, r) return erorr.Errorf("eol: %q (%U) is not an end-of-line character", r, r)
} }
func errProblemReadingRune(err error, runeNumber uint64) error {
return erorr.Errorf("eol: problem reading rune №%d of end-of-line sequence: %w", runeNumber, err)
}
func errProblemUnreadingRune(err error, runeNumber uint64, r rune) error {
return erorr.Errorf("eol: problem unreading rune №%d (%q (%U)) of end-of-line sequence: %w", runeNumber, r, r, err)
}

View File

@ -9,6 +9,7 @@ var _ error = internalNotFoundError{}
type internalNotFoundError struct{ type internalNotFoundError struct{
expected rune expected rune
actual rune actual rune
characterNumber uint64
} }
func (receiver internalNotFoundError) Error() string { func (receiver internalNotFoundError) Error() string {
@ -20,21 +21,23 @@ func (receiver internalNotFoundError) Error() string {
var expected rune = receiver.expected var expected rune = receiver.expected
var actual rune = receiver.actual var actual rune = receiver.actual
var characterNumber uint64 = receiver.characterNumber
switch expected { switch expected {
case lf: case lf:
var s string = fmt.Sprintf(`eol: line-feed (LF) character ('\n') (U+000A) not found — instead found %q (%U)`, actual, actual) var s string = fmt.Sprintf(`eol: line-feed (LF) character ('\n') (U+000A) not found for end-of-line character №%d — instead found %q (%U)`, characterNumber, actual, actual)
p = append(p, s...) p = append(p, s...)
case cr: case cr:
var s string = fmt.Sprintf(`eol: carriage-return (CR) character ('\r') (U+000D) not found — instead found %q (%U)`, actual, actual) var s string = fmt.Sprintf(`eol: carriage-return (CR) character ('\r') (U+000D) not found for end-of-line character №%d — instead found %q (%U)`, characterNumber, actual, actual)
p = append(p, s...) p = append(p, s...)
case nel: case nel:
var s string = fmt.Sprintf(`eol: next-line (NEL) character (U+0085) not found — instead found %q (%U)`, actual, actual) var s string = fmt.Sprintf(`eol: next-line (NEL) character (U+0085) not found for end-of-line character №%d — instead found %q (%U)`, characterNumber, actual, actual)
p = append(p, s...) p = append(p, s...)
case ls: case ls:
var s string = fmt.Sprintf(`eol: line-separator (LS) character (U+2028) not found — instead found %q (%U)`, actual, actual) var s string = fmt.Sprintf(`eol: line-separator (LS) character (U+2028) not found for end-of-line character №%d — instead found %q (%U)`, characterNumber, actual, actual)
p = append(p, s...) p = append(p, s...)
default: default:
var s string = fmt.Sprintf(`eol: %q character (%U) not found — instead found %q (%U)`, expected, expected, actual, actual) var s string = fmt.Sprintf(`eol: %q character (%U) not found for character №%d — instead found %q (%U)`, expected, expected, characterNumber, actual, actual)
p = append(p, s...) p = append(p, s...)
} }

View File

@ -0,0 +1,30 @@
package eol
import (
"fmt"
)
var _ error = internalProblemReadingRuneError{}
func errProblemReadingRune(err error, runeNumber uint64) error {
return internalProblemReadingRuneError{
err:err,
runeNumber:runeNumber,
}
}
type internalProblemReadingRuneError struct {
err error
runeNumber uint64
}
func (receiver internalProblemReadingRuneError) Error() string {
err := receiver.err
runeNumber := receiver.runeNumber
return fmt.Sprintf("eol: problem reading character №%d of end-of-line sequence: %s", runeNumber, err)
}
func (receiver internalProblemReadingRuneError) Unwrap() error {
return receiver.err
}

View File

@ -0,0 +1,33 @@
package eol
import (
"fmt"
)
var _ error = internalProblemUnreadingRuneError{}
func errProblemUnreadingRune(err error, runeNumber uint64, r rune) error {
return internalProblemUnreadingRuneError{
err:err,
runeNumber:runeNumber,
r:r,
}
}
type internalProblemUnreadingRuneError struct {
err error
runeNumber uint64
r rune
}
func (receiver internalProblemUnreadingRuneError) Error() string {
err := receiver.err
runeNumber := receiver.runeNumber
r := receiver.r
return fmt.Sprintf("eol: problem unreading character №%d (%q (%U)) of end-of-line sequence: %s", runeNumber, r, r, err)
}
func (receiver internalProblemUnreadingRuneError) Unwrap() error {
return receiver.err
}

View File

@ -5,5 +5,6 @@ import (
) )
func ReadCR(runescanner io.RuneScanner) (size int, err error) { func ReadCR(runescanner io.RuneScanner) (size int, err error) {
return readthisrune(runescanner, cr) const runeNumber = 1
return readthisrune(runescanner, cr, runeNumber)
} }

View File

@ -67,103 +67,103 @@ func TestReadCR_fail(t *testing.T) {
}{ }{
{ {
Value: "", Value: "",
ExpectedError: `eol: problem reading rune №1 of end-of-line sequence: EOF`, ExpectedError: `eol: problem reading character №1 of end-of-line sequence: EOF`,
}, },
{ {
Value: "\n", Value: "\n",
ExpectedError: `eol: carriage-return (CR) character ('\r') (U+000D) not found — instead found '\n' (U+000A)`, ExpectedError: `eol: carriage-return (CR) character ('\r') (U+000D) not found for end-of-line character №1 — instead found '\n' (U+000A)`,
}, },
{ {
Value: "\u0085", Value: "\u0085",
ExpectedError: `eol: carriage-return (CR) character ('\r') (U+000D) not found — instead found '\u0085' (U+0085)`, ExpectedError: `eol: carriage-return (CR) character ('\r') (U+000D) not found for end-of-line character №1 — instead found '\u0085' (U+0085)`,
}, },
{ {
Value: "\u2028", Value: "\u2028",
ExpectedError: `eol: carriage-return (CR) character ('\r') (U+000D) not found — instead found '\u2028' (U+2028)`, ExpectedError: `eol: carriage-return (CR) character ('\r') (U+000D) not found for end-of-line character №1 — instead found '\u2028' (U+2028)`,
}, },
{ {
Value: "😈", Value: "😈",
ExpectedError: `eol: carriage-return (CR) character ('\r') (U+000D) not found — instead found '😈' (U+1F608)`, ExpectedError: `eol: carriage-return (CR) character ('\r') (U+000D) not found for end-of-line character №1 — instead found '😈' (U+1F608)`,
}, },
{ {
Value: "\napple banana cherry", Value: "\napple banana cherry",
ExpectedError: `eol: carriage-return (CR) character ('\r') (U+000D) not found — instead found '\n' (U+000A)`, ExpectedError: `eol: carriage-return (CR) character ('\r') (U+000D) not found for end-of-line character №1 — instead found '\n' (U+000A)`,
}, },
{ {
Value: "\u0085apple banana cherry", Value: "\u0085apple banana cherry",
ExpectedError: `eol: carriage-return (CR) character ('\r') (U+000D) not found — instead found '\u0085' (U+0085)`, ExpectedError: `eol: carriage-return (CR) character ('\r') (U+000D) not found for end-of-line character №1 — instead found '\u0085' (U+0085)`,
}, },
{ {
Value: "\u2028apple banana cherry", Value: "\u2028apple banana cherry",
ExpectedError: `eol: carriage-return (CR) character ('\r') (U+000D) not found — instead found '\u2028' (U+2028)`, ExpectedError: `eol: carriage-return (CR) character ('\r') (U+000D) not found for end-of-line character №1 — instead found '\u2028' (U+2028)`,
}, },
{ {
Value: "😈apple banana cherry", Value: "😈apple banana cherry",
ExpectedError: `eol: carriage-return (CR) character ('\r') (U+000D) not found — instead found '😈' (U+1F608)`, ExpectedError: `eol: carriage-return (CR) character ('\r') (U+000D) not found for end-of-line character №1 — instead found '😈' (U+1F608)`,
}, },
{ {
Value: " \n", Value: " \n",
ExpectedError: `eol: carriage-return (CR) character ('\r') (U+000D) not found — instead found ' ' (U+0020)`, ExpectedError: `eol: carriage-return (CR) character ('\r') (U+000D) not found for end-of-line character №1 — instead found ' ' (U+0020)`,
}, },
{ {
Value: " \r", Value: " \r",
ExpectedError: `eol: carriage-return (CR) character ('\r') (U+000D) not found — instead found ' ' (U+0020)`, ExpectedError: `eol: carriage-return (CR) character ('\r') (U+000D) not found for end-of-line character №1 — instead found ' ' (U+0020)`,
}, },
{ {
Value: " \u0085", Value: " \u0085",
ExpectedError: `eol: carriage-return (CR) character ('\r') (U+000D) not found — instead found ' ' (U+0020)`, ExpectedError: `eol: carriage-return (CR) character ('\r') (U+000D) not found for end-of-line character №1 — instead found ' ' (U+0020)`,
}, },
{ {
Value: " \u2028", Value: " \u2028",
ExpectedError: `eol: carriage-return (CR) character ('\r') (U+000D) not found — instead found ' ' (U+0020)`, ExpectedError: `eol: carriage-return (CR) character ('\r') (U+000D) not found for end-of-line character №1 — instead found ' ' (U+0020)`,
}, },
{ {
Value: " 😈", Value: " 😈",
ExpectedError: `eol: carriage-return (CR) character ('\r') (U+000D) not found — instead found ' ' (U+0020)`, ExpectedError: `eol: carriage-return (CR) character ('\r') (U+000D) not found for end-of-line character №1 — instead found ' ' (U+0020)`,
}, },
{ {
Value: ".\n", Value: ".\n",
ExpectedError: `eol: carriage-return (CR) character ('\r') (U+000D) not found — instead found '.' (U+002E)`, ExpectedError: `eol: carriage-return (CR) character ('\r') (U+000D) not found for end-of-line character №1 — instead found '.' (U+002E)`,
}, },
{ {
Value: ".\r", Value: ".\r",
ExpectedError: `eol: carriage-return (CR) character ('\r') (U+000D) not found — instead found '.' (U+002E)`, ExpectedError: `eol: carriage-return (CR) character ('\r') (U+000D) not found for end-of-line character №1 — instead found '.' (U+002E)`,
}, },
{ {
Value: ".\u0085", Value: ".\u0085",
ExpectedError: `eol: carriage-return (CR) character ('\r') (U+000D) not found — instead found '.' (U+002E)`, ExpectedError: `eol: carriage-return (CR) character ('\r') (U+000D) not found for end-of-line character №1 — instead found '.' (U+002E)`,
}, },
{ {
Value: ".\u2028", Value: ".\u2028",
ExpectedError: `eol: carriage-return (CR) character ('\r') (U+000D) not found — instead found '.' (U+002E)`, ExpectedError: `eol: carriage-return (CR) character ('\r') (U+000D) not found for end-of-line character №1 — instead found '.' (U+002E)`,
}, },
{ {
Value: ".😈", Value: ".😈",
ExpectedError: `eol: carriage-return (CR) character ('\r') (U+000D) not found — instead found '.' (U+002E)`, ExpectedError: `eol: carriage-return (CR) character ('\r') (U+000D) not found for end-of-line character №1 — instead found '.' (U+002E)`,
}, },
} }

View File

@ -5,5 +5,6 @@ import (
) )
func ReadLF(runescanner io.RuneScanner) (size int, err error) { func ReadLF(runescanner io.RuneScanner) (size int, err error) {
return readthisrune(runescanner, lf) const runeNumber = 1
return readthisrune(runescanner, lf, runeNumber)
} }

View File

@ -67,103 +67,103 @@ func TestReadLF_fail(t *testing.T) {
}{ }{
{ {
Value: "", Value: "",
ExpectedError: `eol: problem reading rune №1 of end-of-line sequence: EOF`, ExpectedError: `eol: problem reading character №1 of end-of-line sequence: EOF`,
}, },
{ {
Value: "\r", Value: "\r",
ExpectedError: `eol: line-feed (LF) character ('\n') (U+000A) not found — instead found '\r' (U+000D)`, ExpectedError: `eol: line-feed (LF) character ('\n') (U+000A) not found for end-of-line character №1 — instead found '\r' (U+000D)`,
}, },
{ {
Value: "\u0085", Value: "\u0085",
ExpectedError: `eol: line-feed (LF) character ('\n') (U+000A) not found — instead found '\u0085' (U+0085)`, ExpectedError: `eol: line-feed (LF) character ('\n') (U+000A) not found for end-of-line character №1 — instead found '\u0085' (U+0085)`,
}, },
{ {
Value: "\u2028", Value: "\u2028",
ExpectedError: `eol: line-feed (LF) character ('\n') (U+000A) not found — instead found '\u2028' (U+2028)`, ExpectedError: `eol: line-feed (LF) character ('\n') (U+000A) not found for end-of-line character №1 — instead found '\u2028' (U+2028)`,
}, },
{ {
Value: "😈", Value: "😈",
ExpectedError: `eol: line-feed (LF) character ('\n') (U+000A) not found — instead found '😈' (U+1F608)`, ExpectedError: `eol: line-feed (LF) character ('\n') (U+000A) not found for end-of-line character №1 — instead found '😈' (U+1F608)`,
}, },
{ {
Value: "\rapple banana cherry", Value: "\rapple banana cherry",
ExpectedError: `eol: line-feed (LF) character ('\n') (U+000A) not found — instead found '\r' (U+000D)`, ExpectedError: `eol: line-feed (LF) character ('\n') (U+000A) not found for end-of-line character №1 — instead found '\r' (U+000D)`,
}, },
{ {
Value: "\u0085apple banana cherry", Value: "\u0085apple banana cherry",
ExpectedError: `eol: line-feed (LF) character ('\n') (U+000A) not found — instead found '\u0085' (U+0085)`, ExpectedError: `eol: line-feed (LF) character ('\n') (U+000A) not found for end-of-line character №1 — instead found '\u0085' (U+0085)`,
}, },
{ {
Value: "\u2028apple banana cherry", Value: "\u2028apple banana cherry",
ExpectedError: `eol: line-feed (LF) character ('\n') (U+000A) not found — instead found '\u2028' (U+2028)`, ExpectedError: `eol: line-feed (LF) character ('\n') (U+000A) not found for end-of-line character №1 — instead found '\u2028' (U+2028)`,
}, },
{ {
Value: "😈apple banana cherry", Value: "😈apple banana cherry",
ExpectedError: `eol: line-feed (LF) character ('\n') (U+000A) not found — instead found '😈' (U+1F608)`, ExpectedError: `eol: line-feed (LF) character ('\n') (U+000A) not found for end-of-line character №1 — instead found '😈' (U+1F608)`,
}, },
{ {
Value: " \n", Value: " \n",
ExpectedError: `eol: line-feed (LF) character ('\n') (U+000A) not found — instead found ' ' (U+0020)`, ExpectedError: `eol: line-feed (LF) character ('\n') (U+000A) not found for end-of-line character №1 — instead found ' ' (U+0020)`,
}, },
{ {
Value: " \r", Value: " \r",
ExpectedError: `eol: line-feed (LF) character ('\n') (U+000A) not found — instead found ' ' (U+0020)`, ExpectedError: `eol: line-feed (LF) character ('\n') (U+000A) not found for end-of-line character №1 — instead found ' ' (U+0020)`,
}, },
{ {
Value: " \u0085", Value: " \u0085",
ExpectedError: `eol: line-feed (LF) character ('\n') (U+000A) not found — instead found ' ' (U+0020)`, ExpectedError: `eol: line-feed (LF) character ('\n') (U+000A) not found for end-of-line character №1 — instead found ' ' (U+0020)`,
}, },
{ {
Value: " \u2028", Value: " \u2028",
ExpectedError: `eol: line-feed (LF) character ('\n') (U+000A) not found — instead found ' ' (U+0020)`, ExpectedError: `eol: line-feed (LF) character ('\n') (U+000A) not found for end-of-line character №1 — instead found ' ' (U+0020)`,
}, },
{ {
Value: " 😈", Value: " 😈",
ExpectedError: `eol: line-feed (LF) character ('\n') (U+000A) not found — instead found ' ' (U+0020)`, ExpectedError: `eol: line-feed (LF) character ('\n') (U+000A) not found for end-of-line character №1 — instead found ' ' (U+0020)`,
}, },
{ {
Value: ".\n", Value: ".\n",
ExpectedError: `eol: line-feed (LF) character ('\n') (U+000A) not found — instead found '.' (U+002E)`, ExpectedError: `eol: line-feed (LF) character ('\n') (U+000A) not found for end-of-line character №1 — instead found '.' (U+002E)`,
}, },
{ {
Value: ".\r", Value: ".\r",
ExpectedError: `eol: line-feed (LF) character ('\n') (U+000A) not found — instead found '.' (U+002E)`, ExpectedError: `eol: line-feed (LF) character ('\n') (U+000A) not found for end-of-line character №1 — instead found '.' (U+002E)`,
}, },
{ {
Value: ".\u0085", Value: ".\u0085",
ExpectedError: `eol: line-feed (LF) character ('\n') (U+000A) not found — instead found '.' (U+002E)`, ExpectedError: `eol: line-feed (LF) character ('\n') (U+000A) not found for end-of-line character №1 — instead found '.' (U+002E)`,
}, },
{ {
Value: ".\u2028", Value: ".\u2028",
ExpectedError: `eol: line-feed (LF) character ('\n') (U+000A) not found — instead found '.' (U+002E)`, ExpectedError: `eol: line-feed (LF) character ('\n') (U+000A) not found for end-of-line character №1 — instead found '.' (U+002E)`,
}, },
{ {
Value: ".😈", Value: ".😈",
ExpectedError: `eol: line-feed (LF) character ('\n') (U+000A) not found — instead found '.' (U+002E)`, ExpectedError: `eol: line-feed (LF) character ('\n') (U+000A) not found for end-of-line character №1 — instead found '.' (U+002E)`,
}, },
} }

View File

@ -5,5 +5,6 @@ import (
) )
func ReadLS(runescanner io.RuneScanner) (size int, err error) { func ReadLS(runescanner io.RuneScanner) (size int, err error) {
return readthisrune(runescanner, ls) const runeNumber = 1
return readthisrune(runescanner, ls, runeNumber)
} }

View File

@ -67,103 +67,103 @@ func TestReadLS_fail(t *testing.T) {
}{ }{
{ {
Value: "", Value: "",
ExpectedError: `eol: problem reading rune №1 of end-of-line sequence: EOF`, ExpectedError: `eol: problem reading character №1 of end-of-line sequence: EOF`,
}, },
{ {
Value: "\n", Value: "\n",
ExpectedError: `eol: line-separator (LS) character (U+2028) not found — instead found '\n' (U+000A)`, ExpectedError: `eol: line-separator (LS) character (U+2028) not found for end-of-line character №1 — instead found '\n' (U+000A)`,
}, },
{ {
Value: "\r", Value: "\r",
ExpectedError: `eol: line-separator (LS) character (U+2028) not found — instead found '\r' (U+000D)`, ExpectedError: `eol: line-separator (LS) character (U+2028) not found for end-of-line character №1 — instead found '\r' (U+000D)`,
}, },
{ {
Value: "\u0085", Value: "\u0085",
ExpectedError: `eol: line-separator (LS) character (U+2028) not found — instead found '\u0085' (U+0085)`, ExpectedError: `eol: line-separator (LS) character (U+2028) not found for end-of-line character №1 — instead found '\u0085' (U+0085)`,
}, },
{ {
Value: "😈", Value: "😈",
ExpectedError: `eol: line-separator (LS) character (U+2028) not found — instead found '😈' (U+1F608)`, ExpectedError: `eol: line-separator (LS) character (U+2028) not found for end-of-line character №1 — instead found '😈' (U+1F608)`,
}, },
{ {
Value: "\napple banana cherry", Value: "\napple banana cherry",
ExpectedError: `eol: line-separator (LS) character (U+2028) not found — instead found '\n' (U+000A)`, ExpectedError: `eol: line-separator (LS) character (U+2028) not found for end-of-line character №1 — instead found '\n' (U+000A)`,
}, },
{ {
Value: "\rapple banana cherry", Value: "\rapple banana cherry",
ExpectedError: `eol: line-separator (LS) character (U+2028) not found — instead found '\r' (U+000D)`, ExpectedError: `eol: line-separator (LS) character (U+2028) not found for end-of-line character №1 — instead found '\r' (U+000D)`,
}, },
{ {
Value: "\u0085apple banana cherry", Value: "\u0085apple banana cherry",
ExpectedError: `eol: line-separator (LS) character (U+2028) not found — instead found '\u0085' (U+0085)`, ExpectedError: `eol: line-separator (LS) character (U+2028) not found for end-of-line character №1 — instead found '\u0085' (U+0085)`,
}, },
{ {
Value: "😈apple banana cherry", Value: "😈apple banana cherry",
ExpectedError: `eol: line-separator (LS) character (U+2028) not found — instead found '😈' (U+1F608)`, ExpectedError: `eol: line-separator (LS) character (U+2028) not found for end-of-line character №1 — instead found '😈' (U+1F608)`,
}, },
{ {
Value: " \n", Value: " \n",
ExpectedError: `eol: line-separator (LS) character (U+2028) not found — instead found ' ' (U+0020)`, ExpectedError: `eol: line-separator (LS) character (U+2028) not found for end-of-line character №1 — instead found ' ' (U+0020)`,
}, },
{ {
Value: " \r", Value: " \r",
ExpectedError: `eol: line-separator (LS) character (U+2028) not found — instead found ' ' (U+0020)`, ExpectedError: `eol: line-separator (LS) character (U+2028) not found for end-of-line character №1 — instead found ' ' (U+0020)`,
}, },
{ {
Value: " \u0085", Value: " \u0085",
ExpectedError: `eol: line-separator (LS) character (U+2028) not found — instead found ' ' (U+0020)`, ExpectedError: `eol: line-separator (LS) character (U+2028) not found for end-of-line character №1 — instead found ' ' (U+0020)`,
}, },
{ {
Value: " \u2028", Value: " \u2028",
ExpectedError: `eol: line-separator (LS) character (U+2028) not found — instead found ' ' (U+0020)`, ExpectedError: `eol: line-separator (LS) character (U+2028) not found for end-of-line character №1 — instead found ' ' (U+0020)`,
}, },
{ {
Value: " 😈", Value: " 😈",
ExpectedError: `eol: line-separator (LS) character (U+2028) not found — instead found ' ' (U+0020)`, ExpectedError: `eol: line-separator (LS) character (U+2028) not found for end-of-line character №1 — instead found ' ' (U+0020)`,
}, },
{ {
Value: ".\n", Value: ".\n",
ExpectedError: `eol: line-separator (LS) character (U+2028) not found — instead found '.' (U+002E)`, ExpectedError: `eol: line-separator (LS) character (U+2028) not found for end-of-line character №1 — instead found '.' (U+002E)`,
}, },
{ {
Value: ".\r", Value: ".\r",
ExpectedError: `eol: line-separator (LS) character (U+2028) not found — instead found '.' (U+002E)`, ExpectedError: `eol: line-separator (LS) character (U+2028) not found for end-of-line character №1 — instead found '.' (U+002E)`,
}, },
{ {
Value: ".\u0085", Value: ".\u0085",
ExpectedError: `eol: line-separator (LS) character (U+2028) not found — instead found '.' (U+002E)`, ExpectedError: `eol: line-separator (LS) character (U+2028) not found for end-of-line character №1 — instead found '.' (U+002E)`,
}, },
{ {
Value: ".\u2028", Value: ".\u2028",
ExpectedError: `eol: line-separator (LS) character (U+2028) not found — instead found '.' (U+002E)`, ExpectedError: `eol: line-separator (LS) character (U+2028) not found for end-of-line character №1 — instead found '.' (U+002E)`,
}, },
{ {
Value: ".😈", Value: ".😈",
ExpectedError: `eol: line-separator (LS) character (U+2028) not found — instead found '.' (U+002E)`, ExpectedError: `eol: line-separator (LS) character (U+2028) not found for end-of-line character №1 — instead found '.' (U+002E)`,
}, },
} }

View File

@ -5,5 +5,6 @@ import (
) )
func ReadNEL(runescanner io.RuneScanner) (size int, err error) { func ReadNEL(runescanner io.RuneScanner) (size int, err error) {
return readthisrune(runescanner, nel) const runeNumber = 1
return readthisrune(runescanner, nel, runeNumber)
} }

View File

@ -67,103 +67,103 @@ func TestReadNEL_fail(t *testing.T) {
}{ }{
{ {
Value: "", Value: "",
ExpectedError: `eol: problem reading rune №1 of end-of-line sequence: EOF`, ExpectedError: `eol: problem reading character №1 of end-of-line sequence: EOF`,
}, },
{ {
Value: "\n", Value: "\n",
ExpectedError: `eol: next-line (NEL) character (U+0085) not found — instead found '\n' (U+000A)`, ExpectedError: `eol: next-line (NEL) character (U+0085) not found for end-of-line character №1 — instead found '\n' (U+000A)`,
}, },
{ {
Value: "\r", Value: "\r",
ExpectedError: `eol: next-line (NEL) character (U+0085) not found — instead found '\r' (U+000D)`, ExpectedError: `eol: next-line (NEL) character (U+0085) not found for end-of-line character №1 — instead found '\r' (U+000D)`,
}, },
{ {
Value: "\u2028", Value: "\u2028",
ExpectedError: `eol: next-line (NEL) character (U+0085) not found — instead found '\u2028' (U+2028)`, ExpectedError: `eol: next-line (NEL) character (U+0085) not found for end-of-line character №1 — instead found '\u2028' (U+2028)`,
}, },
{ {
Value: "😈", Value: "😈",
ExpectedError: `eol: next-line (NEL) character (U+0085) not found — instead found '😈' (U+1F608)`, ExpectedError: `eol: next-line (NEL) character (U+0085) not found for end-of-line character №1 — instead found '😈' (U+1F608)`,
}, },
{ {
Value: "\napple banana cherry", Value: "\napple banana cherry",
ExpectedError: `eol: next-line (NEL) character (U+0085) not found — instead found '\n' (U+000A)`, ExpectedError: `eol: next-line (NEL) character (U+0085) not found for end-of-line character №1 — instead found '\n' (U+000A)`,
}, },
{ {
Value: "\rapple banana cherry", Value: "\rapple banana cherry",
ExpectedError: `eol: next-line (NEL) character (U+0085) not found — instead found '\r' (U+000D)`, ExpectedError: `eol: next-line (NEL) character (U+0085) not found for end-of-line character №1 — instead found '\r' (U+000D)`,
}, },
{ {
Value: "\u2028apple banana cherry", Value: "\u2028apple banana cherry",
ExpectedError: `eol: next-line (NEL) character (U+0085) not found — instead found '\u2028' (U+2028)`, ExpectedError: `eol: next-line (NEL) character (U+0085) not found for end-of-line character №1 — instead found '\u2028' (U+2028)`,
}, },
{ {
Value: "😈apple banana cherry", Value: "😈apple banana cherry",
ExpectedError: `eol: next-line (NEL) character (U+0085) not found — instead found '😈' (U+1F608)`, ExpectedError: `eol: next-line (NEL) character (U+0085) not found for end-of-line character №1 — instead found '😈' (U+1F608)`,
}, },
{ {
Value: " \n", Value: " \n",
ExpectedError: `eol: next-line (NEL) character (U+0085) not found — instead found ' ' (U+0020)`, ExpectedError: `eol: next-line (NEL) character (U+0085) not found for end-of-line character №1 — instead found ' ' (U+0020)`,
}, },
{ {
Value: " \r", Value: " \r",
ExpectedError: `eol: next-line (NEL) character (U+0085) not found — instead found ' ' (U+0020)`, ExpectedError: `eol: next-line (NEL) character (U+0085) not found for end-of-line character №1 — instead found ' ' (U+0020)`,
}, },
{ {
Value: " \u0085", Value: " \u0085",
ExpectedError: `eol: next-line (NEL) character (U+0085) not found — instead found ' ' (U+0020)`, ExpectedError: `eol: next-line (NEL) character (U+0085) not found for end-of-line character №1 — instead found ' ' (U+0020)`,
}, },
{ {
Value: " \u2028", Value: " \u2028",
ExpectedError: `eol: next-line (NEL) character (U+0085) not found — instead found ' ' (U+0020)`, ExpectedError: `eol: next-line (NEL) character (U+0085) not found for end-of-line character №1 — instead found ' ' (U+0020)`,
}, },
{ {
Value: " 😈", Value: " 😈",
ExpectedError: `eol: next-line (NEL) character (U+0085) not found — instead found ' ' (U+0020)`, ExpectedError: `eol: next-line (NEL) character (U+0085) not found for end-of-line character №1 — instead found ' ' (U+0020)`,
}, },
{ {
Value: ".\n", Value: ".\n",
ExpectedError: `eol: next-line (NEL) character (U+0085) not found — instead found '.' (U+002E)`, ExpectedError: `eol: next-line (NEL) character (U+0085) not found for end-of-line character №1 — instead found '.' (U+002E)`,
}, },
{ {
Value: ".\r", Value: ".\r",
ExpectedError: `eol: next-line (NEL) character (U+0085) not found — instead found '.' (U+002E)`, ExpectedError: `eol: next-line (NEL) character (U+0085) not found for end-of-line character №1 — instead found '.' (U+002E)`,
}, },
{ {
Value: ".\u0085", Value: ".\u0085",
ExpectedError: `eol: next-line (NEL) character (U+0085) not found — instead found '.' (U+002E)`, ExpectedError: `eol: next-line (NEL) character (U+0085) not found for end-of-line character №1 — instead found '.' (U+002E)`,
}, },
{ {
Value: ".\u2028", Value: ".\u2028",
ExpectedError: `eol: next-line (NEL) character (U+0085) not found — instead found '.' (U+002E)`, ExpectedError: `eol: next-line (NEL) character (U+0085) not found for end-of-line character №1 — instead found '.' (U+002E)`,
}, },
{ {
Value: ".😈", Value: ".😈",
ExpectedError: `eol: next-line (NEL) character (U+0085) not found — instead found '.' (U+002E)`, ExpectedError: `eol: next-line (NEL) character (U+0085) not found for end-of-line character №1 — instead found '.' (U+002E)`,
}, },
} }

View File

@ -4,7 +4,7 @@ import (
"io" "io"
) )
func readthisrune(runescanner io.RuneScanner, expected rune) (size int, err error) { func readthisrune(runescanner io.RuneScanner, expected rune, characterNumber uint64) (size int, err error) {
if nil == runescanner { if nil == runescanner {
return 0, errNilRuneScanner return 0, errNilRuneScanner
} }
@ -15,8 +15,7 @@ func readthisrune(runescanner io.RuneScanner, expected rune) (size int, err erro
r, size, err = runescanner.ReadRune() r, size, err = runescanner.ReadRune()
if nil != err { if nil != err {
const runeNumber = 1 return size, errProblemReadingRune(err, characterNumber)
return size, errProblemReadingRune(err, runeNumber)
} }
} }
@ -26,11 +25,10 @@ func readthisrune(runescanner io.RuneScanner, expected rune) (size int, err erro
if expected != actual { if expected != actual {
err := runescanner.UnreadRune() err := runescanner.UnreadRune()
if nil != err { if nil != err {
const runeNumber = 1 return size, errProblemUnreadingRune(err, characterNumber, r)
return size, errProblemUnreadingRune(err, runeNumber, r)
} }
return 0, internalNotFoundError{expected: expected, actual: r} return 0, internalNotFoundError{expected: expected, actual: r, characterNumber:characterNumber}
} }
} }

View File

@ -5,7 +5,6 @@ import (
"io" "io"
"strings" "strings"
"sourcecode.social/reiver/go-utf8" "sourcecode.social/reiver/go-utf8"
) )
@ -82,7 +81,8 @@ func TestReadThisRune(t *testing.T) {
var reader io.Reader = strings.NewReader(test.Value) var reader io.Reader = strings.NewReader(test.Value)
var runescanner io.RuneScanner = utf8.NewRuneScanner(reader) var runescanner io.RuneScanner = utf8.NewRuneScanner(reader)
actualSize, err := readthisrune(runescanner, test.Rune) const runeNumber = 999
actualSize, err := readthisrune(runescanner, test.Rune, runeNumber)
if nil != err { if nil != err {
t.Errorf("For test #%d, did not expect an error but actually got one.", testNumber) t.Errorf("For test #%d, did not expect an error but actually got one.", testNumber)
t.Logf("ERROR: (%T) %s", err, err) t.Logf("ERROR: (%T) %s", err, err)
@ -113,27 +113,32 @@ func TestReadThisRune_fail(t *testing.T) {
tests := []struct{ tests := []struct{
Value string Value string
Rune rune Rune rune
RuneNumber uint64
ExpectedError string ExpectedError string
}{ }{
{ {
Value: "", Value: "",
Rune: '\n', Rune: '\n',
ExpectedError: `eol: problem reading rune №1 of end-of-line sequence: EOF`, RuneNumber: 7,
ExpectedError: `eol: problem reading character №7 of end-of-line sequence: EOF`,
}, },
{ {
Value: "", Value: "",
Rune: '\r', Rune: '\r',
ExpectedError: `eol: problem reading rune №1 of end-of-line sequence: EOF`, RuneNumber: 8,
ExpectedError: `eol: problem reading character №8 of end-of-line sequence: EOF`,
}, },
{ {
Value: "", Value: "",
Rune: '\u0085', Rune: '\u0085',
ExpectedError: `eol: problem reading rune №1 of end-of-line sequence: EOF`, RuneNumber: 9,
ExpectedError: `eol: problem reading character №9 of end-of-line sequence: EOF`,
}, },
{ {
Value: "", Value: "",
Rune: '\u2028', Rune: '\u2028',
ExpectedError: `eol: problem reading rune №1 of end-of-line sequence: EOF`, RuneNumber: 10,
ExpectedError: `eol: problem reading character №10 of end-of-line sequence: EOF`,
}, },
@ -141,7 +146,8 @@ func TestReadThisRune_fail(t *testing.T) {
{ {
Value: "", Value: "",
Rune: '😈', Rune: '😈',
ExpectedError: `eol: problem reading rune №1 of end-of-line sequence: EOF`, RuneNumber: 11,
ExpectedError: `eol: problem reading character №11 of end-of-line sequence: EOF`,
}, },
@ -149,22 +155,26 @@ func TestReadThisRune_fail(t *testing.T) {
{ {
Value: " \n", Value: " \n",
Rune: '\n', Rune: '\n',
ExpectedError: `eol: line-feed (LF) character ('\n') (U+000A) not found — instead found ' ' (U+0020)`, RuneNumber: 12,
ExpectedError: `eol: line-feed (LF) character ('\n') (U+000A) not found for end-of-line character №12 — instead found ' ' (U+0020)`,
}, },
{ {
Value: " \r", Value: " \r",
Rune: '\r', Rune: '\r',
ExpectedError: `eol: carriage-return (CR) character ('\r') (U+000D) not found — instead found ' ' (U+0020)`, RuneNumber: 13,
ExpectedError: `eol: carriage-return (CR) character ('\r') (U+000D) not found for end-of-line character №13 — instead found ' ' (U+0020)`,
}, },
{ {
Value: " \u0085", Value: " \u0085",
Rune: '\u0085', Rune: '\u0085',
ExpectedError: `eol: next-line (NEL) character (U+0085) not found — instead found ' ' (U+0020)`, RuneNumber: 14,
ExpectedError: `eol: next-line (NEL) character (U+0085) not found for end-of-line character №14 — instead found ' ' (U+0020)`,
}, },
{ {
Value: " \u2028", Value: " \u2028",
Rune: '\u2028', Rune: '\u2028',
ExpectedError: `eol: line-separator (LS) character (U+2028) not found — instead found ' ' (U+0020)`, RuneNumber: 15,
ExpectedError: `eol: line-separator (LS) character (U+2028) not found for end-of-line character №15 — instead found ' ' (U+0020)`,
}, },
@ -172,7 +182,8 @@ func TestReadThisRune_fail(t *testing.T) {
{ {
Value: " 😈", Value: " 😈",
Rune: '😈', Rune: '😈',
ExpectedError: `eol: '😈' character (U+1F608) not found — instead found ' ' (U+0020)`, RuneNumber: 16,
ExpectedError: `eol: '😈' character (U+1F608) not found for character №16 — instead found ' ' (U+0020)`,
}, },
@ -180,22 +191,26 @@ func TestReadThisRune_fail(t *testing.T) {
{ {
Value: ".\n", Value: ".\n",
Rune: '\n', Rune: '\n',
ExpectedError: `eol: line-feed (LF) character ('\n') (U+000A) not found — instead found '.' (U+002E)`, RuneNumber: 17,
ExpectedError: `eol: line-feed (LF) character ('\n') (U+000A) not found for end-of-line character №17 — instead found '.' (U+002E)`,
}, },
{ {
Value: ".\r", Value: ".\r",
Rune: '\r', Rune: '\r',
ExpectedError: `eol: carriage-return (CR) character ('\r') (U+000D) not found — instead found '.' (U+002E)`, RuneNumber: 18,
ExpectedError: `eol: carriage-return (CR) character ('\r') (U+000D) not found for end-of-line character №18 — instead found '.' (U+002E)`,
}, },
{ {
Value: ".\u0085", Value: ".\u0085",
Rune: '\u0085', Rune: '\u0085',
ExpectedError: `eol: next-line (NEL) character (U+0085) not found — instead found '.' (U+002E)`, RuneNumber: 19,
ExpectedError: `eol: next-line (NEL) character (U+0085) not found for end-of-line character №19 — instead found '.' (U+002E)`,
}, },
{ {
Value: ".\u2028", Value: ".\u2028",
Rune: '\u2028', Rune: '\u2028',
ExpectedError: `eol: line-separator (LS) character (U+2028) not found — instead found '.' (U+002E)`, RuneNumber: 20,
ExpectedError: `eol: line-separator (LS) character (U+2028) not found for end-of-line character №20 — instead found '.' (U+002E)`,
}, },
@ -203,7 +218,8 @@ func TestReadThisRune_fail(t *testing.T) {
{ {
Value: ".😈", Value: ".😈",
Rune: '😈', Rune: '😈',
ExpectedError: `eol: '😈' character (U+1F608) not found — instead found '.' (U+002E)`, RuneNumber: 21,
ExpectedError: `eol: '😈' character (U+1F608) not found for character №21 — instead found '.' (U+002E)`,
}, },
} }
@ -212,7 +228,7 @@ func TestReadThisRune_fail(t *testing.T) {
var reader io.Reader = strings.NewReader(test.Value) var reader io.Reader = strings.NewReader(test.Value)
var runescanner io.RuneScanner = utf8.NewRuneScanner(reader) var runescanner io.RuneScanner = utf8.NewRuneScanner(reader)
actualSize, err := readthisrune(runescanner, test.Rune) actualSize, err := readthisrune(runescanner, test.Rune, test.RuneNumber)
if nil == err { if nil == err {
t.Errorf("For test #%d, expected an error but did not actually get one.", testNumber) t.Errorf("For test #%d, expected an error but did not actually get one.", testNumber)
t.Logf("EXPECTED-ERROR: %q", test.ExpectedError) t.Logf("EXPECTED-ERROR: %q", test.ExpectedError)