52a96915f0
Fuzz targets covering all input-processing functions: - terminalstate: FuzzTrackerFeed, FuzzTrackerFeedIncremental - normalize: FuzzNormalizeC1Controls, FuzzFilterDASequences - slugify: FuzzSlugify (with unit tests) - identity: FuzzGenerateID (with unit tests) - replay: FuzzReplayBuffer, FuzzReplayBufferRapid - svg_exporter: FuzzColorToHex, FuzzIsHex, FuzzRenderTerminalSVG - shellsplit: FuzzShlexSplit (with unit test) - twoway: FuzzTwoWayMap (with unit test) - config: FuzzExtractLabel All 14 targets validated with -fuzztime=3s, no panics found. All unit tests pass with -race. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
61 lines
1.3 KiB
Go
61 lines
1.3 KiB
Go
package webterm
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestGenerateIDLength(t *testing.T) {
|
|
for _, size := range []int{1, 5, 12, 50} {
|
|
id := GenerateID(size)
|
|
if len(id) != size {
|
|
t.Errorf("GenerateID(%d) length = %d", size, len(id))
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestGenerateIDDefaultSize(t *testing.T) {
|
|
id := GenerateID(0)
|
|
if len(id) != identitySize {
|
|
t.Errorf("GenerateID(0) length = %d, want %d", len(id), identitySize)
|
|
}
|
|
}
|
|
|
|
func TestGenerateIDAlphabet(t *testing.T) {
|
|
id := GenerateID(1000)
|
|
for _, ch := range id {
|
|
if !strings.ContainsRune(identityAlphabet, ch) {
|
|
t.Errorf("GenerateID produced char %q not in alphabet", string(ch))
|
|
}
|
|
}
|
|
}
|
|
|
|
func FuzzGenerateID(f *testing.F) {
|
|
f.Add(0)
|
|
f.Add(1)
|
|
f.Add(12)
|
|
f.Add(100)
|
|
f.Add(-5)
|
|
f.Add(500)
|
|
|
|
f.Fuzz(func(t *testing.T, size int) {
|
|
// Cap size to avoid excessive allocation
|
|
if size > 10000 {
|
|
size = 10000
|
|
}
|
|
id := GenerateID(size)
|
|
expectedLen := size
|
|
if size <= 0 {
|
|
expectedLen = identitySize
|
|
}
|
|
if len(id) != expectedLen {
|
|
t.Errorf("GenerateID(%d) length = %d, want %d", size, len(id), expectedLen)
|
|
}
|
|
for _, ch := range id {
|
|
if !strings.ContainsRune(identityAlphabet, ch) {
|
|
t.Errorf("GenerateID(%d) produced char %q not in alphabet %q", size, string(ch), identityAlphabet)
|
|
}
|
|
}
|
|
})
|
|
}
|