diff options
Diffstat (limited to 'internal/norm/norm_test.go')
| -rw-r--r-- | internal/norm/norm_test.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/internal/norm/norm_test.go b/internal/norm/norm_test.go index 885c6f7..a165b32 100644 --- a/internal/norm/norm_test.go +++ b/internal/norm/norm_test.go @@ -73,3 +73,33 @@ func TestFoldASCIINoAlloc(t *testing.T) { t.Errorf("Fold allocates %v times on ASCII input", n) } } + +// TestFoldMappedSource: a part of the folded text leads back to the original +// characters it came from, widened to whole characters - so a capture can be +// written with its diacritics. +func TestFoldMappedSource(t *testing.T) { + cases := []struct { + in, folded string + a, b int + want string + }{ + {"Łódź-faktura.pdf", "Lodz-faktura.pdf", 0, 4, "Łódź"}, + {"Łódź-faktura.pdf", "Lodz-faktura.pdf", 5, 12, "faktura"}, + {"straße", "strasse", 4, 5, "ß"}, + {"áb", "ab", 0, 1, "a"}, + {"áb", "ab", 1, 2, "b"}, + {"\xff\xfeé", "�e", 0, 3, "\xff\xfe"}, + {"plain.txt", "plain.txt", 0, 5, "plain"}, + {"Łódź", "Lodz", 2, 2, ""}, + } + for _, c := range cases { + f := FoldMapped(c.in) + if f.Text != c.folded || f.Text != Fold(c.in) { + t.Errorf("FoldMapped(%q).Text = %q, want %q (Fold)", c.in, f.Text, c.folded) + continue + } + if got := f.Source(c.a, c.b); got != c.want { + t.Errorf("FoldMapped(%q).Source(%d, %d) = %q, want %q", c.in, c.a, c.b, got, c.want) + } + } +} |
