Debian Codegraph @

exp/strings/join_test.go

raw
1 package strings
2
3 import "testing"
4
5 func TestEnglishJoin(t *testing.T) {
6 for i, tc := range []struct {
7 words []string
8 lang Language
9 oxfordComma bool
10 expected string
11 }{
12 {
13 words: []string{"one", "two", "three"},
14 lang: EN,
15 oxfordComma: true,
16 expected: "one, two, and three",
17 },
18 {
19 words: []string{"one", "two", "three", "four"},
20 oxfordComma: true,
21 expected: "one, two, three, and four",
22 },
23 {
24 words: []string{"one", "two"},
25 oxfordComma: true,
26 expected: "one and two",
27 },
28 {
29 words: []string{"one", "two", "three"},
30 oxfordComma: false,
31 expected: "one, two and three",
32 },
33 {
34 words: []string{"one"},
35 oxfordComma: true,
36 expected: "one",
37 },
38 } {
39 actual := EnglishJoin(tc.words, tc.oxfordComma)
40 if actual != tc.expected {
41 t.Errorf("Test #%d:\n expected: %q\n got: %q", i+1, tc.expected, actual)
42 }
43 }
44 }
45
46 func TestSpokenLanguageJoin(t *testing.T) {
47 for i, tc := range []struct {
48 words []string
49 lang Language
50 expected string
51 }{
52 // Test for correct commas and conjunctions in each language.
53 {
54 words: []string{"eins", "zwei", "drei"},
55 lang: DE,
56 expected: "eins, zwei und drei",
57 },
58 {
59 words: []string{"en", "to", "tre"},
60 lang: DK,
61 expected: "en, to og tre",
62 },
63 {
64 words: []string{"one", "two", "three"},
65 lang: EN,
66 expected: "one, two and three",
67 },
68 {
69 words: []string{"uno", "dos", "tres"},
70 lang: ES,
71 expected: "uno, dos y tres",
72 },
73 {
74 words: []string{"un", "deux", "trois"},
75 lang: FR,
76 expected: "un, deux et trois",
77 },
78 {
79 words: []string{"uno", "due", "tre"},
80 lang: IT,
81 expected: "uno, due e tre",
82 },
83 {
84 words: []string{"en", "to", "tre"},
85 lang: NO,
86 expected: "en, to og tre",
87 },
88 {
89 words: []string{"um", "dois", "três"},
90 lang: PT,
91 expected: "um, dois e três",
92 },
93 {
94 words: []string{"ett", "två", "tre", "fyra"},
95 lang: SE,
96 expected: "ett, två, tre och fyra",
97 },
98
99 // Test other things.
100 {
101 words: []string{"one", "two", "three", "four"},
102 lang: EN,
103 expected: "one, two, three and four",
104 },
105 {
106 words: []string{"um", "dois"},
107 lang: PT,
108 expected: "um e dois",
109 },
110 {
111 words: []string{"un", "deux"},
112 lang: FR,
113 expected: "un et deux",
114 },
115 {
116 words: []string{"one"},
117 lang: EN,
118 expected: "one",
119 },
120 {
121 words: []string{},
122 lang: EN,
123 expected: "",
124 },
125 {
126 words: []string{"", "", ""},
127 lang: EN,
128 expected: "",
129 },
130 {
131 words: nil,
132 lang: EN,
133 expected: "",
134 },
135 } {
136 actual := SpokenLanguageJoin(tc.words, tc.lang)
137 if actual != tc.expected {
138 t.Errorf("Test #%d:\n expected: %q\n got: %q", i+1, tc.expected, actual)
139 }
140 }
141 }