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:
parent
fb3b6abbe7
commit
ea3dcf3ca5
@ -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
|
||||
|
@ -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))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user