Skip to content

Commit fbd9d88

Browse files
author
Bernhard Millauer
committed
Added a specific culture to the format-tests because tests expecting to be executed in a english environment / country;
1 parent 7eff257 commit fbd9d88

4 files changed

Lines changed: 58 additions & 51 deletions

File tree

src/SmartFormat.Tests/CodeProjectExampleTests.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
using System.Drawing;
44
using System.Linq;
55
using System.Text;
6+
using System.Threading;
7+
68
using NUnit.Framework;
79
using SmartFormat.Core;
810
using SmartFormat.Core.Extensions;
@@ -49,7 +51,8 @@ public void BasicSyntax()
4951
var formatString = "{0} is {1} years old and has {2:N2} friends.";
5052
var expectedOutput = "Quentin is 30 years old and has 4.00 friends.";
5153

52-
string actualOutput = Smart.Format(formatString, p.FirstName, p.Age, p.Friends.Count);
54+
var specificCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-us");
55+
string actualOutput = Smart.Format(specificCulture, formatString, p.FirstName, p.Age, p.Friends.Count);
5356
Assert.AreEqual(expectedOutput, actualOutput);
5457
}
5558

@@ -62,7 +65,8 @@ public void BasicReflection()
6265
var formatString = "{FirstName} is {Age} years old and has {Friends.Count:N2} friends.";
6366
var expectedOutput = "Quentin is 30 years old and has 4.00 friends.";
6467

65-
string actualOutput = Smart.Format(formatString, p);
68+
var specificCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-us");
69+
string actualOutput = Smart.Format(specificCulture, formatString, p);
6670
Assert.AreEqual(expectedOutput, actualOutput);
6771
}
6872

@@ -91,7 +95,8 @@ public void BasicArray()
9195
var formatString = "All dates: {0:{:M/d/yyyy}| and }.";
9296
var expectedOutput = "All dates: 12/31/1999 and 10/10/2010 and 1/1/3000.";
9397

94-
string actualOutput = Smart.Format(formatString, data);
98+
var specificCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-us");
99+
string actualOutput = Smart.Format(specificCulture, formatString, data);
95100
Assert.AreEqual(expectedOutput, actualOutput);
96101
}
97102

@@ -363,7 +368,8 @@ public void AdvancedArray()
363368
var formatString = "{0:{:M/d/yyyy}|, |, and }.";
364369
var expectedOutput = "12/31/1999, 10/10/2010, and 1/1/3000.";
365370

366-
string actualOutput = Smart.Format(formatString, data);
371+
var specificCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-us");
372+
string actualOutput = Smart.Format(specificCulture, formatString, data);
367373
Assert.AreEqual(expectedOutput, actualOutput);
368374
}
369375

src/SmartFormat.Tests/Extensions/ListFormatterTests.cs

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,33 @@
77

88
namespace SmartFormat.Tests
99
{
10-
[TestFixture]
11-
public class ListFormatterTests
12-
{
13-
public object[] GetArgs()
14-
{
15-
var args = new object[] {
10+
[TestFixture]
11+
public class ListFormatterTests
12+
{
13+
public object[] GetArgs()
14+
{
15+
var args = new object[] {
1616
"ABCDE".ToCharArray(),
1717
"One|Two|Three|Four|Five".Split('|'),
1818
TestFactory.GetPerson().Friends,
19-
"1/1/2000|10/10/2010|5/5/5555".Split('|').Select(s=>DateTime.ParseExact(s,"M/d/yyyy",null)),
19+
"1/1/2000|10/10/2010|5/5/5555".Split('|').Select(s=>DateTime.ParseExact(s,"M/d/yyyy",System.Globalization.CultureInfo.CreateSpecificCulture("en-us"))),
2020
new []{1,2,3,4,5},
2121
};
22-
return args;
23-
}
24-
25-
[Test]
26-
public void FormatTest()
27-
{
28-
var formats = new string[] {
22+
return args;
23+
}
24+
25+
[Test]
26+
public void FormatTest()
27+
{
28+
var formats = new string[] {
2929
"{4}",
3030
"{4:|}",
3131
"{4:00|}",
3232
"{4:|,}",
3333
"{4:|, |, and }",
3434
"{4:N2|, |, and }",
3535
};
36-
var expected = new string[] {
36+
var expected = new string[] {
3737
"System.Int32[]",
3838
"12345",
3939
"0102030405",
@@ -42,64 +42,64 @@ public void FormatTest()
4242
"1.00, 2.00, 3.00, 4.00, and 5.00",
4343
};
4444

45-
var args = GetArgs();
46-
Smart.Default.Test(formats, args, expected);
45+
var args = GetArgs();
46+
Smart.Default.Test(formats, args, expected);
4747

48-
}
49-
[Test]
50-
public void NestedFormatTest()
51-
{
52-
var formats = new string[] {
48+
}
49+
[Test]
50+
public void NestedFormatTest()
51+
{
52+
var formats = new string[] {
5353
"{0:{}-|}",
5454
"{0:{}|-}",
5555
"{0:{}|-|+}",
5656
"{0:({})|, |, and }",
5757
};
58-
var expected = new string[] {
58+
var expected = new string[] {
5959
"A-B-C-D-E-",
6060
"A-B-C-D-E",
6161
"A-B-C-D+E",
6262
"(A), (B), (C), (D), and (E)",
6363
};
64-
65-
var args = GetArgs();
66-
Smart.Default.Test(formats, args, expected);
67-
}
68-
[Test]
69-
public void NestedArraysTest()
70-
{
71-
var formats = new string[] {
64+
65+
var args = GetArgs();
66+
Smart.Default.Test(formats, args, expected);
67+
}
68+
[Test]
69+
public void NestedArraysTest()
70+
{
71+
var formats = new string[] {
7272
"{2:{:{FirstName}}|, }",
7373
"{3:{:M/d/yyyy} |}",
7474
"{2:{:{FirstName}'s friends: {Friends:{FirstName}|, } }|; }",
7575
};
76-
var expected = new string[] {
76+
var expected = new string[] {
7777
"Jim, Pam, Dwight",
7878
"1/1/2000 10/10/2010 5/5/5555 ",
7979
"Jim's friends: Dwight, Michael ; Pam's friends: Dwight, Michael ; Dwight's friends: Michael ",
8080
};
8181

82-
var args = GetArgs();
83-
Smart.Default.Test(formats, args, expected);
84-
}
85-
[Test]
86-
public void TestIndex()
87-
{
88-
var formats = new string[] {
82+
var args = GetArgs();
83+
Smart.Default.Test(formats, args, expected);
84+
}
85+
[Test]
86+
public void TestIndex()
87+
{
88+
var formats = new string[] {
8989
"{0:{} = {Index}|, }", // Index holds the current index of the iteration
9090
"{1:{Index}: {ToCharArray:{} = {Index}|, }|; }", // Index can be nested
9191
"{0:{} = {1.Index}|, }", // Index is used to synchronize 2 lists
9292
"{Index}", // Index can be used out-of-context, but should always be -1
9393
};
94-
var expected = new string[] {
94+
var expected = new string[] {
9595
"A = 0, B = 1, C = 2, D = 3, E = 4",
9696
"0: O = 0, n = 1, e = 2; 1: T = 0, w = 1, o = 2; 2: T = 0, h = 1, r = 2, e = 3, e = 4; 3: F = 0, o = 1, u = 2, r = 3; 4: F = 0, i = 1, v = 2, e = 3",
9797
"A = One, B = Two, C = Three, D = Four, E = Five",
9898
"-1",
9999
};
100100

101-
var args = GetArgs();
102-
Smart.Default.Test(formats, args, expected);
103-
}
104-
}
101+
var args = GetArgs();
102+
Smart.Default.Test(formats, args, expected);
103+
}
104+
}
105105
}

src/SmartFormat.Tests/Extensions/PluralLocalizationFormatterTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ private void TestAllResults(CultureInfo cultureInfo, string format, ExpectedResu
3030
public void Test_Default()
3131
{
3232
TestAllResults(
33-
null,
33+
CultureInfo.CreateSpecificCulture("en-us"),
3434
"There {0:is|are} {0} {0:item|items} remaining",
3535
new ExpectedResults {
3636
{ -1, "There are -1 items remaining"},

src/SmartFormat.Tests/TestUtils/TestHelpers.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ public static void Test(this SmartFormatter formatter, string[] bunchOfFormat, o
6868

6969
string actual = null;
7070
try
71-
{
72-
actual = formatter.Format(format, args);
71+
{
72+
var specificCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-us");
73+
actual = formatter.Format(specificCulture, format, args);
7374
Assert.AreEqual(expected, actual);
7475
Console.WriteLine("Success: \"{0}\" => \"{1}\"", format, actual);
7576
}

0 commit comments

Comments
 (0)