Skip to content

Commit fa86c17

Browse files
committed
fixed a few tests that break when executed in a fr-CA locale
1 parent 10d1353 commit fa86c17

File tree

3 files changed

+27
-18
lines changed

3 files changed

+27
-18
lines changed

Rubberduck.Parsing/Preprocessing/DecimalValue.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Globalization;
23

34
namespace Rubberduck.Parsing.Preprocessing
45
{
@@ -55,13 +56,13 @@ public string AsString
5556
{
5657
get
5758
{
58-
return _value.ToString();
59+
return _value.ToString(CultureInfo.InvariantCulture);
5960
}
6061
}
6162

6263
public override string ToString()
6364
{
64-
return _value.ToString();
65+
return _value.ToString(CultureInfo.InvariantCulture);
6566
}
6667
}
6768
}

Rubberduck.Parsing/Preprocessing/StringValue.cs

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Diagnostics;
23
using System.Globalization;
34

45
namespace Rubberduck.Parsing.Preprocessing
@@ -28,29 +29,30 @@ public bool AsBool
2829
{
2930
return false;
3031
}
31-
var str = _value;
32-
if (string.CompareOrdinal(str.ToLower(), "true") == 0
33-
|| string.CompareOrdinal(str, "#TRUE#") == 0)
32+
var value = _value;
33+
if (string.CompareOrdinal(value.ToLower(), "true") == 0 || string.CompareOrdinal(value, "#TRUE#") == 0)
3434
{
3535
return true;
3636
}
37-
else if (string.CompareOrdinal(str.ToLower(), "false") == 0
38-
|| string.CompareOrdinal(str, "#FALSE#") == 0)
37+
38+
if (string.CompareOrdinal(value.ToLower(), "false") == 0 || string.CompareOrdinal(value, "#FALSE#") == 0)
3939
{
4040
return false;
4141
}
42-
else
43-
{
44-
decimal number = AsDecimal;
45-
return new DecimalValue(number).AsBool;
46-
}
42+
43+
return new DecimalValue(AsDecimal).ToString() != "0"; // any non-zero value evaluates to TRUE in VBA
4744
}
4845
}
4946

5047
public byte AsByte
5148
{
5249
get
5350
{
51+
byte value;
52+
if (byte.TryParse(_value, NumberStyles.Float, CultureInfo.InvariantCulture, out value))
53+
{
54+
return value;
55+
}
5456
return byte.Parse(_value, NumberStyles.Float);
5557
}
5658
}
@@ -59,10 +61,10 @@ public DateTime AsDate
5961
{
6062
get
6163
{
62-
DateTime date;
63-
if (DateTime.TryParse(_value, out date))
64+
DateTime value;
65+
if (DateTime.TryParse(_value, out value))
6466
{
65-
return date;
67+
return value;
6668
}
6769
decimal number = AsDecimal;
6870
return new DecimalValue(number).AsDate;
@@ -73,7 +75,13 @@ public decimal AsDecimal
7375
{
7476
get
7577
{
76-
return decimal.Parse(_value, NumberStyles.Float);
78+
decimal value;
79+
if (decimal.TryParse(_value, NumberStyles.Float, CultureInfo.InvariantCulture, out value))
80+
{
81+
return value;
82+
}
83+
Debug.Assert(false); // this line was never hit in any unit test covering it.
84+
return 0;
7785
}
7886
}
7987

@@ -87,7 +95,7 @@ public string AsString
8795

8896
public override string ToString()
8997
{
90-
return _value.ToString();
98+
return _value;
9199
}
92100
}
93101
}

RubberduckTests/Preprocessing/VBAPreprocessorVisitorTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ public void TestCStrFunction()
376376
Assert.AreEqual(string.Empty, result.Item1.Get("b").AsString);
377377
Assert.AreEqual("True", result.Item1.Get("c").AsString);
378378
Assert.AreEqual("False", result.Item1.Get("d").AsString);
379-
Assert.AreEqual(345.23.ToString(), result.Item1.Get("e").AsString);
379+
Assert.AreEqual(345.23.ToString(CultureInfo.InvariantCulture), result.Item1.Get("e").AsString);
380380
Assert.AreEqual(new DateTime(1899, 12, 30, 2, 1, 0).ToLongTimeString(), result.Item1.Get("f").AsString);
381381
Assert.AreEqual(new DateTime(2016, 1, 31).ToShortDateString(), result.Item1.Get("g").AsString);
382382
}

0 commit comments

Comments
 (0)