github.com/seeker-insurance/kit@v0.0.13/str/normalize_unicode_test.go (about) 1 package str 2 3 import ( 4 "testing" 5 ) 6 7 func TestRemoveDiacriticsNFC(t *testing.T) { 8 tests := []struct { 9 name string 10 arg string 11 want string 12 }{ 13 14 { 15 name: "ok", 16 arg: "Finé", 17 want: "Fine", 18 }, 19 { 20 name: "accented letters", 21 arg: "áéíóúüñ", 22 want: "aeiouun", 23 }, 24 } 25 for _, tt := range tests { 26 t.Run(tt.name, func(t *testing.T) { 27 if got := RemoveDiacriticsNFC(tt.arg); got != tt.want { 28 t.Errorf("RemoveDiacriticsNFC() = %v, want %v", got, tt.want) 29 } 30 }) 31 } 32 } 33 34 func TestRemoveASCIIPunctuation(t *testing.T) { 35 t.Run("ascii punctuation", func(t *testing.T) { 36 if got := RemoveASCIIPunctuation(ASCIIPunct + "foo"); got != "foo" { 37 t.Errorf("RemovePunctuation() = %v, want %v", got, "foo") 38 } 39 }) 40 } 41 42 func TestExtremeNormalization(t *testing.T) { 43 44 tests := []struct { 45 name string 46 s string 47 want string 48 }{ 49 { 50 name: "no whitespace", 51 s: ASCIIWhitespace, 52 want: "", 53 }, { 54 name: "lowercase capitals", 55 s: "FOO", 56 want: "foo", 57 }, 58 { 59 name: "no diacritics", 60 s: `Finé`, 61 want: "fine", 62 }, 63 { 64 name: "no control characters", 65 s: "\x07", //bell 66 want: "", 67 }, 68 { 69 name: "no punctuation", 70 s: ASCIIPunct, 71 want: "", 72 }, 73 { 74 name: "no null", 75 s: "\x00", 76 want: "", 77 }, 78 } 79 for _, tt := range tests { 80 t.Run(tt.name, func(t *testing.T) { 81 if got := ExtremeNormalization(tt.s); got != tt.want { 82 t.Errorf("ExtremeNormalization() = %v, want %v", got, tt.want) 83 } 84 }) 85 } 86 }