summaryrefslogtreecommitdiff
path: root/internal/norm/fuzz_test.go
blob: fde62a0a062ee8820f3096c25fe561265a87428a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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)
			}
		}
	})
}