1package entity
2
3import (
4 "testing"
5)
6
7func TestHasAccents(t *testing.T) {
8 tests := []struct {
9 name string
10 char rune
11 want bool
12 }{
13 {"lowercase e", 'e', true},
14 {"uppercase E", 'E', true},
15 {"lowercase a", 'a', true},
16 {"uppercase A", 'A', true},
17 {"lowercase c", 'c', true},
18 {"lowercase n", 'n', true},
19 {"lowercase x (no accents)", 'x', false},
20 {"uppercase X (no accents)", 'X', false},
21 {"digit 1 (no accents)", '1', false},
22 {"space (no accents)", ' ', false},
23 }
24
25 for _, tt := range tests {
26 t.Run(tt.name, func(t *testing.T) {
27 got := HasAccents(tt.char)
28 if got != tt.want {
29 t.Errorf("HasAccents(%q) = %v, want %v", tt.char, got, tt.want)
30 }
31 })
32 }
33}
34
35func TestGetAccents(t *testing.T) {
36 tests := []struct {
37 name string
38 char rune
39 uppercase bool
40 wantLen int
41 wantFirst rune
42 }{
43 {"lowercase e", 'e', false, 6, 'è'},
44 {"uppercase E", 'E', true, 6, 'È'},
45 {"lowercase a", 'a', false, 7, 'à'},
46 {"uppercase A", 'A', true, 7, 'À'},
47 {"lowercase c", 'c', false, 3, 'ç'},
48 {"uppercase C with shift", 'c', true, 3, 'Ç'},
49 {"no accents x", 'x', false, 0, 0},
50 }
51
52 for _, tt := range tests {
53 t.Run(tt.name, func(t *testing.T) {
54 got := GetAccents(tt.char, tt.uppercase)
55
56 if len(got) != tt.wantLen {
57 t.Errorf("GetAccents(%q, %v) length = %d, want %d", tt.char, tt.uppercase, len(got), tt.wantLen)
58 }
59
60 if tt.wantLen > 0 && got[0] != tt.wantFirst {
61 t.Errorf("GetAccents(%q, %v)[0] = %q, want %q", tt.char, tt.uppercase, got[0], tt.wantFirst)
62 }
63 })
64 }
65}
66
67func TestGetAccents_UppercaseFromLowercase(t *testing.T) {
68 // When passing lowercase char with uppercase=true, should return uppercase accents
69 uppercase := GetAccents('e', true)
70 lowercase := GetAccents('e', false)
71
72 if len(uppercase) == 0 {
73 t.Fatal("expected accents for 'e' with uppercase=true")
74 }
75
76 if len(uppercase) != len(lowercase) {
77 t.Fatalf("uppercase and lowercase accent counts differ: %d vs %d", len(uppercase), len(lowercase))
78 }
79
80 // Verify each uppercase accent is different from the corresponding lowercase accent
81 for i, upper := range uppercase {
82 lower := lowercase[i]
83 if upper == lower {
84 t.Errorf("accent at index %d is same for uppercase and lowercase: %q", i, upper)
85 }
86 }
87
88 // Verify first accent is È (uppercase of è)
89 if uppercase[0] != 'È' {
90 t.Errorf("expected first uppercase accent to be È, got %q", uppercase[0])
91 }
92}
93
94func TestAccentMapCoverage(t *testing.T) {
95 // Verify all expected characters have accents
96 expectedChars := []rune{'a', 'c', 'e', 'i', 'n', 'o', 's', 'u', 'y'}
97
98 for _, char := range expectedChars {
99 if !HasAccents(char) {
100 t.Errorf("expected %q to have accents", char)
101 }
102
103 accents := GetAccents(char, false)
104 if len(accents) == 0 {
105 t.Errorf("expected %q to have at least one accent variant", char)
106 }
107 }
108}