aboutsummaryrefslogtreecommitdiff
path: root/internal/norm/fuzz_test.go
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-09-14 20:10:01 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-09-14 20:10:01 +0200
commitaa24cfb344b1b3eaef7217d996359023cd72ba28 (patch)
treeee0d981d3add58451a83de13ac56be4a8b165eea /internal/norm/fuzz_test.go
parent00aae60378982902b871a87850e0ed427b28a347 (diff)
downloadkrino-aa24cfb344b1b3eaef7217d996359023cd72ba28.tar.gz
krino-aa24cfb344b1b3eaef7217d996359023cd72ba28.zip
plan 8: fuzz decoders; fold ẞ and invalid UTF-8 correctly, refuse non-UTF-8 paths in krino new
Diffstat (limited to 'internal/norm/fuzz_test.go')
-rw-r--r--internal/norm/fuzz_test.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/internal/norm/fuzz_test.go b/internal/norm/fuzz_test.go
new file mode 100644
index 0000000..fde62a0
--- /dev/null
+++ b/internal/norm/fuzz_test.go
@@ -0,0 +1,30 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+package norm
+
+import "testing"
+
+// FuzzTextIdempotent: normalising text twice changes nothing more than
+// normalising it once, under every case and fold setting, and so for names.
+// Keywords are normalised at load and text at match time by the same
+// functions; a second pass that still changed something would mean the two
+// could disagree about what one normalised string is.
+func FuzzTextIdempotent(f *testing.F) {
+ for _, s := range []string{"Spółka Z O.O.", "ẞ straße", "a\u0301", " tabs\tand\nlines ", "\xff", "İstanbul", "Dž", "Æsir Œuvre"} {
+ f.Add(s)
+ }
+ f.Fuzz(func(t *testing.T, s string) {
+ for _, opt := range [][2]bool{{false, false}, {true, false}, {false, true}, {true, true}} {
+ once := Text(s, opt[0], opt[1])
+ if twice := Text(once, opt[0], opt[1]); twice != once {
+ t.Fatalf("Text(%q, %v, %v) = %q, again %q", s, opt[0], opt[1], once, twice)
+ }
+ }
+ for _, fold := range []bool{false, true} {
+ once := Name(s, fold)
+ if twice := Name(once, fold); twice != once {
+ t.Fatalf("Name(%q, %v) = %q, again %q", s, fold, once, twice)
+ }
+ }
+ })
+}