Gim/internal/syntax/treesitter_fuzz_test.go
Hayden Hargreaves 16d1318c22 feat: start TS impl
This is so vibe coded, but in the interest of time, its a bit
necessary. Plus this is a complex problem that I don't have the mental
bandwidth to invest right now.
2026-04-07 10:23:25 -07:00

36 lines
801 B
Go

package syntax
import "testing"
func FuzzByteColToRuneIndexInvariants(f *testing.F) {
f.Add("abc", 0)
f.Add("aéb", 1)
f.Add("こんにちは", 5)
f.Add("", 0)
f.Fuzz(func(t *testing.T, s string, col int) {
line := []byte(s)
idx := byteColToRuneIndex(line, col)
runes := []rune(s)
if idx < 0 || idx > len(runes) {
t.Fatalf("rune index out of bounds: idx=%d len=%d", idx, len(runes))
}
if col <= 0 && idx != 0 {
t.Fatalf("expected idx 0 for non-positive col, got %d", idx)
}
if col >= len(line) && idx != len(runes) {
t.Fatalf("expected idx len(runes) for col>=len(bytes), got %d", idx)
}
if col > 0 && col < len(line) {
expected := len([]rune(string(line[:col])))
if idx != expected {
t.Fatalf("expected idx %d got %d", expected, idx)
}
}
})
}