1
1
mirror of https://github.com/walles/moar.git synced 2024-11-30 12:42:26 +03:00

Fix a crash

This commit is contained in:
Johan Walles 2019-11-06 21:38:39 +01:00
parent fb3b6abbe7
commit ea3dcf3ca5
2 changed files with 17 additions and 0 deletions

View File

@ -24,6 +24,11 @@ func _ToRunePositions(byteIndices [][]int, matchedString *string) [][2]int {
var returnMe [][2]int
if len(byteIndices) == 0 {
// Nothing to see here, move along
return returnMe
}
fromByte := byteIndices[len(returnMe)][0]
toByte := byteIndices[len(returnMe)][1]
fromRune := -1

View File

@ -51,3 +51,15 @@ func TestUtf8(t *testing.T) {
assert.Assert(t, matchRanges.InRange(3)) // ä
assert.Assert(t, !matchRanges.InRange(4)) // -
}
func TestNoMatch(t *testing.T) {
// This test verifies that the match ranges are by rune rather than by byte
unicodes := "gris"
matchRanges := GetMatchRanges(&unicodes, regexp.MustCompile("apa"))
assert.Assert(t, !matchRanges.InRange(0))
assert.Assert(t, !matchRanges.InRange(1))
assert.Assert(t, !matchRanges.InRange(2))
assert.Assert(t, !matchRanges.InRange(3))
assert.Assert(t, !matchRanges.InRange(4))
}