-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathI18nTest.cs
More file actions
228 lines (198 loc) · 6.41 KB
/
Copy pathI18nTest.cs
File metadata and controls
228 lines (198 loc) · 6.41 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
namespace Mgl
{
using NUnit.Framework;
public class I18nConsoleAppStub
{
public static void Main()
{
}
}
[TestFixture]
public class I18nTest
{
[SetUp]
public void Init()
{
I18n i18n = I18n.Instance;
I18n.Instance.Configure(localePath: "Locales/", newLocale: "en-US", logMissing: true, locales: new string[] { "en-US", "fr-FR", "es-ES" });
}
[Test]
public void TestLocale()
{
I18n i18n = I18n.Instance;
Assert.AreEqual("en-US", I18n.GetLocale());
}
[Test]
public void TestConfigureLocale()
{
I18n i18n = I18n.Instance;
I18n.Instance.Configure("Locales/", "fr-FR");
Assert.AreEqual("fr-FR", I18n.GetLocale());
}
[Test]
public void TestSetLocale()
{
I18n.SetLocale("es-ES");
Assert.AreEqual("es-ES", I18n.GetLocale());
I18n.SetLocale("en-US");
Assert.AreEqual("en-US", I18n.GetLocale());
}
[Test]
public void TestConfigureLocales()
{
I18n i18n = I18n.Instance;
I18n.Instance.Configure (newLocale: "de-DE", locales: new string[] { "en-US", "de-DE" });
Assert.AreEqual("de-DE", I18n.GetLocale());
Assert.AreEqual("Hallo", i18n.__ ("Hello"));
}
[Test]
public void TestHello()
{
I18n i18n = I18n.Instance;
I18n.SetLocale("en-US");
Assert.AreEqual("Hello", i18n.__("Hello"));
I18n.SetLocale("fr-FR");
Assert.AreEqual("Bonjour", i18n.__("Hello"));
I18n.SetLocale("es-ES");
Assert.AreEqual("Hola", i18n.__("Hello"));
}
[Test]
public void TestZeroNoReplacements()
{
I18n i18n = I18n.Instance;
I18n.SetLocale("en-US");
Assert.AreEqual("You have no cats", i18n.__("You have one cat", 0));
}
[Test]
public void TestOneNoReplacements()
{
I18n i18n = I18n.Instance;
I18n.SetLocale("en-US");
Assert.AreEqual("You have one cat", i18n.__("You have one cat", 1));
}
[Test]
public void TestOtherNoReplacements()
{
I18n i18n = I18n.Instance;
I18n.SetLocale("en-US");
Assert.AreEqual("You have a lot of cats!", i18n.__("You have one cat", 11));
}
[Test]
public void TestZero()
{
I18n i18n = I18n.Instance;
I18n.SetLocale("en-US");
Assert.AreEqual("No credits", i18n.__("{0} credits", 0));
}
[Test]
public void TestFloatNearZero()
{
I18n i18n = I18n.Instance;
I18n.SetLocale("en-US");
Assert.AreEqual("0.34 credits", i18n.__("{0} credits", 0.34));
}
[Test]
public void TestOne()
{
I18n i18n = I18n.Instance;
I18n.SetLocale("en-US");
Assert.AreEqual("1 credit", i18n.__("{0} credits", 1));
}
[Test]
public void TestFloat()
{
I18n i18n = I18n.Instance;
I18n.SetLocale("en-US");
Assert.AreEqual("1.23 credits", i18n.__("{0} credits", 1.23));
}
[Test]
public void TestNegativeOne()
{
I18n i18n = I18n.Instance;
I18n.SetLocale("en-US");
Assert.AreEqual("-1 credit", i18n.__("{0} credits", -1));
}
[Test]
public void TestOther()
{
I18n i18n = I18n.Instance;
I18n.SetLocale("en-US");
Assert.AreEqual("15 credits", i18n.__("{0} credits", 15));
}
[Test]
public void TestOtherFloat()
{
I18n i18n = I18n.Instance;
I18n.SetLocale("en-US");
Assert.AreEqual("15.23 credits", i18n.__("{0} credits", 15.23));
}
[Test]
public void TestNegativeOther()
{
I18n i18n = I18n.Instance;
I18n.SetLocale("en-US");
Assert.AreEqual("-15 credits", i18n.__("{0} credits", -15));
}
[Test]
public void TestNegativeOtherFloat()
{
I18n i18n = I18n.Instance;
I18n.SetLocale("en-US");
Assert.AreEqual("-15.23 credits", i18n.__("{0} credits", -15.23));
}
[Test]
public void TestBasicReplacement()
{
I18n i18n = I18n.Instance;
I18n.SetLocale("en-US");
Assert.AreEqual("Hello Tester, how are you today?", i18n.__("Hello {0}, how are you today?", "Tester"));
}
[Test]
public void TestMultipleReplacement()
{
I18n i18n = I18n.Instance;
I18n.SetLocale("en-US");
Assert.AreEqual
(
"Level The Lion's Den time: 00:44:23 score:10,0000 ammo:12 player:One",
i18n.__(
"Level {1} time: {0} score:{3} ammo:{4} player:{2}",
"00:44:23",
"The Lion's Den",
"One",
"10,0000",
"12"
)
);
}
[Test]
public void TestZeroMonkeys()
{
I18n i18n = I18n.Instance;
I18n.SetLocale("en-US");
Assert.AreEqual("There are no monkeys in the tree.", i18n.__("There is one monkey in the {1}", 0, "tree"));
}
[Test]
public void TestOneMonkey()
{
I18n i18n = I18n.Instance;
I18n.SetLocale("en-US");
Assert.AreEqual("There is one monkey in the tree.", i18n.__("There is one monkey in the {1}", 1, "tree"));
}
[Test]
public void TestMultipleMonkeys()
{
I18n i18n = I18n.Instance;
I18n.SetLocale("en-US");
Assert.AreEqual("There are 27 monkeys in the tree!", i18n.__("There is one monkey in the {1}", 27, "tree"));
}
[Test]
public void TestNegativeMultipleMonkeys()
{
// why would you have negative monkeys? well who cares - we need to test it anyways!
I18n i18n = I18n.Instance;
I18n.SetLocale("en-US");
Assert.AreEqual("There are -5 monkeys in the tree!", i18n.__("There is one monkey in the {1}", -5, "tree"));
}
}
}