initial commits

master
Charles Iliya Krempeaux 2023-11-28 08:05:15 -08:00
parent 9d5e4af6b2
commit 62d9ff57b4
2 changed files with 42 additions and 22 deletions

View File

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

View File

@ -5,6 +5,8 @@ import (
"io" "io"
"strings" "strings"
"sourcecode.social/reiver/go-opt"
"sourcecode.social/reiver/go-utf8" "sourcecode.social/reiver/go-utf8"
) )
@ -81,8 +83,9 @@ 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)
const runeNumber = 999 const characterNumber = 999
actualSize, err := readthisrune(runescanner, test.Rune, runeNumber) circumstance := specifyCircumstance(opt.Something("UNIT-TEST"), characterNumber)
actualSize, err := readthisrune(circumstance, runescanner, test.Rune)
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,32 +116,37 @@ func TestReadThisRune_fail(t *testing.T) {
tests := []struct{ tests := []struct{
Value string Value string
Rune rune Rune rune
EOLSequence opt.Optional[string]
RuneNumber uint64 RuneNumber uint64
ExpectedError string ExpectedError string
}{ }{
{ {
Value: "", Value: "",
Rune: '\n', Rune: '\n',
EOLSequence: opt.Something(LF),
RuneNumber: 7, RuneNumber: 7,
ExpectedError: `eol: problem reading character №7 of end-of-line sequence: EOF`, ExpectedError: `eol: problem reading character №7 of end-of-line sequence "\n": EOF`,
}, },
{ {
Value: "", Value: "",
Rune: '\r', Rune: '\r',
EOLSequence: opt.Something(CR),
RuneNumber: 8, RuneNumber: 8,
ExpectedError: `eol: problem reading character №8 of end-of-line sequence: EOF`, ExpectedError: `eol: problem reading character №8 of end-of-line sequence "\r": EOF`,
}, },
{ {
Value: "", Value: "",
Rune: '\u0085', Rune: '\u0085',
EOLSequence: opt.Something(NEL),
RuneNumber: 9, RuneNumber: 9,
ExpectedError: `eol: problem reading character №9 of end-of-line sequence: EOF`, ExpectedError: `eol: problem reading character №9 of end-of-line sequence "\u0085": EOF`,
}, },
{ {
Value: "", Value: "",
Rune: '\u2028', Rune: '\u2028',
EOLSequence: opt.Something(LS),
RuneNumber: 10, RuneNumber: 10,
ExpectedError: `eol: problem reading character №10 of end-of-line sequence: EOF`, ExpectedError: `eol: problem reading character №10 of end-of-line sequence "\u2028": EOF`,
}, },
@ -146,8 +154,9 @@ func TestReadThisRune_fail(t *testing.T) {
{ {
Value: "", Value: "",
Rune: '😈', Rune: '😈',
EOLSequence: opt.Something("😈"),
RuneNumber: 11, RuneNumber: 11,
ExpectedError: `eol: problem reading character №11 of end-of-line sequence: EOF`, ExpectedError: `eol: problem reading character №11 of end-of-line sequence "😈": EOF`,
}, },
@ -155,26 +164,30 @@ func TestReadThisRune_fail(t *testing.T) {
{ {
Value: " \n", Value: " \n",
Rune: '\n', Rune: '\n',
EOLSequence: opt.Something(LF),
RuneNumber: 12, RuneNumber: 12,
ExpectedError: `eol: line-feed (LF) character ('\n') (U+000A) not found for end-of-line character №12 — instead found ' ' (U+0020)`, ExpectedError: `eol: line-feed (LF) character ('\n') (U+000A) not found for end-of-line sequence "\n" character №12 — instead found ' ' (U+0020)`,
}, },
{ {
Value: " \r", Value: " \r",
Rune: '\r', Rune: '\r',
EOLSequence: opt.Something(CR),
RuneNumber: 13, RuneNumber: 13,
ExpectedError: `eol: carriage-return (CR) character ('\r') (U+000D) not found for end-of-line character №13 — instead found ' ' (U+0020)`, ExpectedError: `eol: carriage-return (CR) character ('\r') (U+000D) not found for end-of-line sequence "\r" character №13 — instead found ' ' (U+0020)`,
}, },
{ {
Value: " \u0085", Value: " \u0085",
Rune: '\u0085', Rune: '\u0085',
EOLSequence: opt.Something(NEL),
RuneNumber: 14, RuneNumber: 14,
ExpectedError: `eol: next-line (NEL) character (U+0085) not found for end-of-line character №14 — instead found ' ' (U+0020)`, ExpectedError: `eol: next-line (NEL) character (U+0085) not found for end-of-line sequence "\u0085" character №14 — instead found ' ' (U+0020)`,
}, },
{ {
Value: " \u2028", Value: " \u2028",
Rune: '\u2028', Rune: '\u2028',
EOLSequence: opt.Something(LS),
RuneNumber: 15, RuneNumber: 15,
ExpectedError: `eol: line-separator (LS) character (U+2028) not found for end-of-line character №15 — instead found ' ' (U+0020)`, ExpectedError: `eol: line-separator (LS) character (U+2028) not found for end-of-line sequence "\u2028" character №15 — instead found ' ' (U+0020)`,
}, },
@ -182,8 +195,9 @@ func TestReadThisRune_fail(t *testing.T) {
{ {
Value: " 😈", Value: " 😈",
Rune: '😈', Rune: '😈',
EOLSequence: opt.Something("😈"),
RuneNumber: 16, RuneNumber: 16,
ExpectedError: `eol: '😈' character (U+1F608) not found for character №16 — instead found ' ' (U+0020)`, ExpectedError: `eol: '😈' character (U+1F608) not found for sequence "😈" character №16 — instead found ' ' (U+0020)`,
}, },
@ -191,26 +205,30 @@ func TestReadThisRune_fail(t *testing.T) {
{ {
Value: ".\n", Value: ".\n",
Rune: '\n', Rune: '\n',
EOLSequence: opt.Something("\n"),
RuneNumber: 17, RuneNumber: 17,
ExpectedError: `eol: line-feed (LF) character ('\n') (U+000A) not found for end-of-line character №17 — instead found '.' (U+002E)`, ExpectedError: `eol: line-feed (LF) character ('\n') (U+000A) not found for end-of-line sequence "\n" character №17 — instead found '.' (U+002E)`,
}, },
{ {
Value: ".\r", Value: ".\r",
Rune: '\r', Rune: '\r',
EOLSequence: opt.Something("\r"),
RuneNumber: 18, RuneNumber: 18,
ExpectedError: `eol: carriage-return (CR) character ('\r') (U+000D) not found for end-of-line character №18 — instead found '.' (U+002E)`, ExpectedError: `eol: carriage-return (CR) character ('\r') (U+000D) not found for end-of-line sequence "\r" character №18 — instead found '.' (U+002E)`,
}, },
{ {
Value: ".\u0085", Value: ".\u0085",
Rune: '\u0085', Rune: '\u0085',
EOLSequence: opt.Something("\u0085"),
RuneNumber: 19, RuneNumber: 19,
ExpectedError: `eol: next-line (NEL) character (U+0085) not found for end-of-line character №19 — instead found '.' (U+002E)`, ExpectedError: `eol: next-line (NEL) character (U+0085) not found for end-of-line sequence "\u0085" character №19 — instead found '.' (U+002E)`,
}, },
{ {
Value: ".\u2028", Value: ".\u2028",
Rune: '\u2028', Rune: '\u2028',
EOLSequence: opt.Something("\u2028"),
RuneNumber: 20, RuneNumber: 20,
ExpectedError: `eol: line-separator (LS) character (U+2028) not found for end-of-line character №20 — instead found '.' (U+002E)`, ExpectedError: `eol: line-separator (LS) character (U+2028) not found for end-of-line sequence "\u2028" character №20 — instead found '.' (U+002E)`,
}, },
@ -218,8 +236,9 @@ func TestReadThisRune_fail(t *testing.T) {
{ {
Value: ".😈", Value: ".😈",
Rune: '😈', Rune: '😈',
EOLSequence: opt.Something("😈"),
RuneNumber: 21, RuneNumber: 21,
ExpectedError: `eol: '😈' character (U+1F608) not found for character №21 — instead found '.' (U+002E)`, ExpectedError: `eol: '😈' character (U+1F608) not found for sequence "😈" character №21 — instead found '.' (U+002E)`,
}, },
} }
@ -228,7 +247,8 @@ 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, test.RuneNumber) var circumstance internalCircumstance = specifyCircumstance(test.EOLSequence, test.RuneNumber)
actualSize, err := readthisrune(circumstance, runescanner, test.Rune)
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)