forked from goccy/go-zetasqlite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Date] Implement
%y
year without century parser / formatter; handle…
… incomplete digits (#8) * [Date] Implement `%y` year without century parser / formatter * Change digit parsing to not require the maximum length of digits * remove comment * test rename / fix * comments
- Loading branch information
Showing
3 changed files
with
271 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package internal | ||
|
||
import "testing" | ||
|
||
func TestTimeParser(t *testing.T) { | ||
for _, test := range []struct { | ||
name string | ||
text []rune | ||
minValue int64 | ||
maxValue int64 | ||
expectedProgress int | ||
expectedResult int | ||
expectedErr string | ||
}{ | ||
{ | ||
name: "single digit but multiple allowed; non-digit character terminates", | ||
text: []rune{'2', '/'}, | ||
minValue: 1, | ||
maxValue: 12, | ||
expectedResult: 2, | ||
expectedProgress: 1, | ||
}, | ||
{ | ||
name: "multiple digits; non-digit character terminates", | ||
text: []rune{'1', '2', '/'}, | ||
minValue: 1, | ||
maxValue: 12, | ||
expectedResult: 12, | ||
expectedProgress: 2, | ||
}, | ||
{ | ||
name: "leading zero digit but multiple allowed; non-digit character terminates", | ||
text: []rune{'0', '2', '/'}, | ||
minValue: 1, | ||
maxValue: 12, | ||
expectedResult: 2, | ||
expectedProgress: 2, | ||
}, | ||
|
||
{ | ||
name: "leading zero digit but multiple allowed; non-digit character terminates", | ||
text: []rune{'0', '0', '2', '/'}, | ||
minValue: 1, | ||
maxValue: 9999, | ||
expectedResult: 2, | ||
expectedProgress: 3, | ||
}, | ||
{ | ||
name: "multiple digits but exceeds limit; non-digit character terminates", | ||
text: []rune{'2', '2', '/'}, | ||
minValue: 1, | ||
maxValue: 12, | ||
expectedErr: "part [22] is greater than maximum value [12]", | ||
}, | ||
{ | ||
name: "multiple digits but lower than start bound; non-digit character terminates", | ||
text: []rune{'0', '0', '/'}, | ||
minValue: 1, | ||
maxValue: 12, | ||
expectedErr: "part [0] is less than minimum value [1]", | ||
}, | ||
{ | ||
name: "multiple digits but lower than start bound; non-digit character terminates", | ||
text: []rune{'4', '-'}, | ||
minValue: 1, | ||
maxValue: 12, | ||
expectedResult: 4, | ||
expectedProgress: 1, | ||
}, | ||
} { | ||
|
||
t.Run(test.name, func(t *testing.T) { | ||
progress, result, err := parseDigitRespectingOptionalPlaces(test.text, test.minValue, test.maxValue) | ||
if err != nil { | ||
if test.expectedErr != err.Error() { | ||
t.Fatalf("unexpected error message: expected [%s] but got [%s]", test.expectedErr, err.Error()) | ||
} else { | ||
// expected error occurred, consider test successful | ||
return | ||
} | ||
} | ||
|
||
if progress != test.expectedProgress { | ||
t.Fatalf("unexpected progress: expected [%d] but got [%d]", test.expectedProgress, progress) | ||
} | ||
|
||
if result != int64(test.expectedResult) { | ||
t.Fatalf("unexpected result: expected [%d] but got [%d]", test.expectedResult, result) | ||
} | ||
|
||
}) | ||
} | ||
} |
Oops, something went wrong.