From 61b26d3aa7fe768e8b7cb1d5cd4c9fdfa52b3d15 Mon Sep 17 00:00:00 2001 From: Charles Iliya Krempeaux Date: Tue, 28 Nov 2023 06:26:36 -0800 Subject: [PATCH] initial commits --- errors.go | 8 ------- notfound.go | 13 +++++++---- problemreadingrune.go | 30 ++++++++++++++++++++++++ problemunreadingrune.go | 33 ++++++++++++++++++++++++++ readcr.go | 3 ++- readcr_test.go | 38 +++++++++++++++--------------- readlf.go | 3 ++- readlf_test.go | 38 +++++++++++++++--------------- readls.go | 3 ++- readls_test.go | 38 +++++++++++++++--------------- readnel.go | 3 ++- readnel_test.go | 38 +++++++++++++++--------------- readthisrune.go | 10 ++++---- readthisrune_test.go | 52 +++++++++++++++++++++++++++-------------- 14 files changed, 193 insertions(+), 117 deletions(-) create mode 100644 problemreadingrune.go create mode 100644 problemunreadingrune.go diff --git a/errors.go b/errors.go index e6741c7..48847fb 100644 --- a/errors.go +++ b/errors.go @@ -11,11 +11,3 @@ const ( func errNotEOL(r rune) error { 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) -} diff --git a/notfound.go b/notfound.go index 8bfffa9..3950c35 100644 --- a/notfound.go +++ b/notfound.go @@ -9,6 +9,7 @@ var _ error = internalNotFoundError{} type internalNotFoundError struct{ expected rune actual rune + characterNumber uint64 } func (receiver internalNotFoundError) Error() string { @@ -20,21 +21,23 @@ func (receiver internalNotFoundError) Error() string { var expected rune = receiver.expected var actual rune = receiver.actual + var characterNumber uint64 = receiver.characterNumber + switch expected { 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...) 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...) 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...) 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...) 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...) } diff --git a/problemreadingrune.go b/problemreadingrune.go new file mode 100644 index 0000000..aebf498 --- /dev/null +++ b/problemreadingrune.go @@ -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 +} diff --git a/problemunreadingrune.go b/problemunreadingrune.go new file mode 100644 index 0000000..12a2354 --- /dev/null +++ b/problemunreadingrune.go @@ -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 +} diff --git a/readcr.go b/readcr.go index 764f4a7..f3c5907 100644 --- a/readcr.go +++ b/readcr.go @@ -5,5 +5,6 @@ import ( ) func ReadCR(runescanner io.RuneScanner) (size int, err error) { - return readthisrune(runescanner, cr) + const runeNumber = 1 + return readthisrune(runescanner, cr, runeNumber) } diff --git a/readcr_test.go b/readcr_test.go index 1d548c2..61667c7 100644 --- a/readcr_test.go +++ b/readcr_test.go @@ -67,103 +67,103 @@ func TestReadCR_fail(t *testing.T) { }{ { 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", - 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", - 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", - 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: "😈", - 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", - 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", - 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", - 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", - 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", - 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", - 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", - 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", - 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: " 😈", - 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", - 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", - 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", - 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", - 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: ".😈", - 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)`, }, } diff --git a/readlf.go b/readlf.go index 1244aa9..04cc933 100644 --- a/readlf.go +++ b/readlf.go @@ -5,5 +5,6 @@ import ( ) func ReadLF(runescanner io.RuneScanner) (size int, err error) { - return readthisrune(runescanner, lf) + const runeNumber = 1 + return readthisrune(runescanner, lf, runeNumber) } diff --git a/readlf_test.go b/readlf_test.go index b9727ee..5fc4cdb 100644 --- a/readlf_test.go +++ b/readlf_test.go @@ -67,103 +67,103 @@ func TestReadLF_fail(t *testing.T) { }{ { 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", - 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", - 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", - 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: "😈", - 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", - 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", - 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", - 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", - 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", - 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", - 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", - 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", - 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: " 😈", - 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", - 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", - 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", - 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", - 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: ".😈", - 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)`, }, } diff --git a/readls.go b/readls.go index 20dbeb2..28dd06d 100644 --- a/readls.go +++ b/readls.go @@ -5,5 +5,6 @@ import ( ) func ReadLS(runescanner io.RuneScanner) (size int, err error) { - return readthisrune(runescanner, ls) + const runeNumber = 1 + return readthisrune(runescanner, ls, runeNumber) } diff --git a/readls_test.go b/readls_test.go index aca26ad..4060afc 100644 --- a/readls_test.go +++ b/readls_test.go @@ -67,103 +67,103 @@ func TestReadLS_fail(t *testing.T) { }{ { 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", - 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", - 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", - 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: "😈", - 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", - 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", - 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", - 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", - 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", - 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", - 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", - 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", - 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: " 😈", - 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", - 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", - 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", - 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", - 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: ".😈", - 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)`, }, } diff --git a/readnel.go b/readnel.go index 5c412a0..0abe771 100644 --- a/readnel.go +++ b/readnel.go @@ -5,5 +5,6 @@ import ( ) func ReadNEL(runescanner io.RuneScanner) (size int, err error) { - return readthisrune(runescanner, nel) + const runeNumber = 1 + return readthisrune(runescanner, nel, runeNumber) } diff --git a/readnel_test.go b/readnel_test.go index b501cca..c290603 100644 --- a/readnel_test.go +++ b/readnel_test.go @@ -67,103 +67,103 @@ func TestReadNEL_fail(t *testing.T) { }{ { 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", - 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", - 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", - 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: "😈", - 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", - 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", - 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", - 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", - 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", - 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", - 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", - 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", - 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: " 😈", - 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", - 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", - 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", - 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", - 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: ".😈", - 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)`, }, } diff --git a/readthisrune.go b/readthisrune.go index 976b00a..890bd9d 100644 --- a/readthisrune.go +++ b/readthisrune.go @@ -4,7 +4,7 @@ import ( "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 { return 0, errNilRuneScanner } @@ -15,8 +15,7 @@ func readthisrune(runescanner io.RuneScanner, expected rune) (size int, err erro r, size, err = runescanner.ReadRune() if nil != err { - const runeNumber = 1 - return size, errProblemReadingRune(err, runeNumber) + return size, errProblemReadingRune(err, characterNumber) } } @@ -26,11 +25,10 @@ func readthisrune(runescanner io.RuneScanner, expected rune) (size int, err erro if expected != actual { err := runescanner.UnreadRune() if nil != err { - const runeNumber = 1 - return size, errProblemUnreadingRune(err, runeNumber, r) + return size, errProblemUnreadingRune(err, characterNumber, r) } - return 0, internalNotFoundError{expected: expected, actual: r} + return 0, internalNotFoundError{expected: expected, actual: r, characterNumber:characterNumber} } } diff --git a/readthisrune_test.go b/readthisrune_test.go index d300bfe..87fe9d6 100644 --- a/readthisrune_test.go +++ b/readthisrune_test.go @@ -5,7 +5,6 @@ import ( "io" "strings" - "sourcecode.social/reiver/go-utf8" ) @@ -82,7 +81,8 @@ func TestReadThisRune(t *testing.T) { var reader io.Reader = strings.NewReader(test.Value) 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 { t.Errorf("For test #%d, did not expect an error but actually got one.", testNumber) t.Logf("ERROR: (%T) %s", err, err) @@ -113,27 +113,32 @@ func TestReadThisRune_fail(t *testing.T) { tests := []struct{ Value string Rune rune + RuneNumber uint64 ExpectedError string }{ { Value: "", 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: "", 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: "", 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: "", 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: "", 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", 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", 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", 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", 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: " 😈", 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", 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", 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", 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", 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: ".😈", 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 runescanner io.RuneScanner = utf8.NewRuneScanner(reader) - actualSize, err := readthisrune(runescanner, test.Rune) + actualSize, err := readthisrune(runescanner, test.Rune, test.RuneNumber) if nil == err { t.Errorf("For test #%d, expected an error but did not actually get one.", testNumber) t.Logf("EXPECTED-ERROR: %q", test.ExpectedError)