Skip to content

Commit b60d78e

Browse files
authored
Update tests for explicit culture (#804)
1 parent 5719cb1 commit b60d78e

File tree

1 file changed

+68
-50
lines changed

1 file changed

+68
-50
lines changed

UnitsNet.Tests/CustomCode/LengthTests.FeetInches.cs

Lines changed: 68 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Licensed under MIT No Attribution, see LICENSE file at the root.
22
// Copyright 2013 Andreas Gullberg Larsen ([email protected]). Maintained at https://github.com/angularsen/UnitsNet.
33

4+
using System.Collections.Generic;
5+
using System.Globalization;
46
using Xunit;
57

68
namespace UnitsNet.Tests.CustomCode
@@ -29,63 +31,79 @@ public void FeetInchesRoundTrip()
2931
AssertEx.EqualTolerance(3, feetInches.Inches, InchesTolerance);
3032
}
3133

34+
public static IEnumerable<object[]> ValidData => new List<object[]>
35+
{
36+
new object[]{"1'", 1, new CultureInfo("en-US", false)}, // Feet only
37+
new object[]{"1′", 1, new CultureInfo("en-US", false)}, // Feet only
38+
new object[]{"1,000′", 1000, new CultureInfo("en-US", false)}, // Feet only, with seperator
39+
new object[]{"1e3'", 1000, new CultureInfo("en-US", false)}, // Feet only, exponential notation
40+
new object[]{"1\"", 0.08333333, new CultureInfo("en-US", false)}, // Inches only
41+
new object[]{"1″", 0.08333333, new CultureInfo("en-US", false)}, // Inches only
42+
new object[]{"0' 1\"", 0.08333333, new CultureInfo("en-US", false)}, // Inches only
43+
new object[]{"0' 1″", 0.08333333, new CultureInfo("en-US", false)}, // Inches only
44+
new object[]{"0′ 1\"", 0.08333333, new CultureInfo("en-US", false)}, // Inches only
45+
new object[]{"0′ 1″", 0.08333333, new CultureInfo("en-US", false)}, // Inches only
46+
new object[]{"1' 1\"", 1.08333333, new CultureInfo("en-US", false)}, // Normal form
47+
new object[]{"1′ 1″", 1.08333333, new CultureInfo("en-US", false)}, // Normal form
48+
new object[]{" 1′ 1″ ", 1.08333333, new CultureInfo("en-US", false)}, // Normal form, requires trimming
49+
new object[]{"1'1\"", 1.08333333, new CultureInfo("en-US", false)}, // Without space
50+
new object[]{"1′1″", 1.08333333, new CultureInfo("en-US", false)}, // Without space
51+
new object[]{"1 ft 1 in", 1.08333333, new CultureInfo("en-US", false)},
52+
new object[]{"1ft 1in", 1.08333333, new CultureInfo("en-US", false)},
53+
new object[]{"-1'", -1, new CultureInfo("en-US", false)}, // Feet only
54+
new object[]{"-1′", -1, new CultureInfo("en-US", false)}, // Feet only
55+
new object[]{"-1,000′", -1000, new CultureInfo("en-US", false)}, // Feet only, with seperator
56+
new object[]{"-1e3'", -1000, new CultureInfo("en-US", false)}, // Feet only, exponential notation
57+
new object[]{"-1\"", -0.08333333, new CultureInfo("en-US", false)}, // Inches only
58+
new object[]{"-1″", -0.08333333, new CultureInfo("en-US", false)}, // Inches only
59+
new object[]{"-0' 1\"", -0.08333333, new CultureInfo("en-US", false)}, // Inches only
60+
new object[]{"-0' 1″", -0.08333333, new CultureInfo("en-US", false)}, // Inches only
61+
new object[]{"-0′ 1\"", -0.08333333, new CultureInfo("en-US", false)}, // Inches only
62+
new object[]{"-0′ 1″", -0.08333333, new CultureInfo("en-US", false)}, // Inches only
63+
new object[]{"-1' 1\"", -1.08333333, new CultureInfo("en-US", false)}, // Normal form
64+
new object[]{"-1′ 1″", -1.08333333, new CultureInfo("en-US", false)}, // Normal form
65+
new object[]{" -1′ 1″ ", -1.08333333, new CultureInfo("en-US", false)}, // Normal form, requires trimming
66+
new object[]{"-1'1\"", -1.08333333, new CultureInfo("en-US", false)}, // Without space
67+
new object[]{"-1′1″", -1.08333333, new CultureInfo("en-US", false)}, // Without space
68+
new object[]{"-1 ft 1 in", -1.08333333, new CultureInfo("en-US", false)},
69+
new object[]{"-1ft 1in", -1.08333333, new CultureInfo("en-US", false)},
70+
new object[]{"1’000′", 1000, new CultureInfo("de-CH", false)}, // Feet only, with seperator
71+
new object[]{"1’000′ 6\"", 1000.5, new CultureInfo("de-CH", false)}, // Normal form, using separators for culture
72+
};
73+
3274
[Theory]
33-
[InlineData("1'", 1)] // Feet only
34-
[InlineData("1′", 1)] // Feet only
35-
[InlineData("1\"", 0.08333333)] // Inches only
36-
[InlineData("1″", 0.08333333)] // Inches only
37-
[InlineData("0' 1\"", 0.08333333)] // Inches only
38-
[InlineData("0' 1″", 0.08333333)] // Inches only
39-
[InlineData("0′ 1\"", 0.08333333)] // Inches only
40-
[InlineData("0′ 1″", 0.08333333)] // Inches only
41-
[InlineData("1' 1\"", 1.08333333)] // Normal form
42-
[InlineData("1′ 1″", 1.08333333)] // Normal form
43-
[InlineData(" 1′ 1″ ", 1.08333333)] // Normal form, requires trimming
44-
[InlineData("1'1\"", 1.08333333)] // Without space
45-
[InlineData("1′1″", 1.08333333)] // Without space
46-
[InlineData("1 ft 1 in", 1.08333333)]
47-
[InlineData("1ft 1in", 1.08333333)]
48-
[InlineData("-1'", -1)] // Feet only
49-
[InlineData("-1′", -1)] // Feet only
50-
[InlineData("-1\"", -0.08333333)] // Inches only
51-
[InlineData("-1″", -0.08333333)] // Inches only
52-
[InlineData("-0' 1\"", -0.08333333)] // Inches only
53-
[InlineData("-0' 1″", -0.08333333)] // Inches only
54-
[InlineData("-0′ 1\"", -0.08333333)] // Inches only
55-
[InlineData("-0′ 1″", -0.08333333)] // Inches only
56-
[InlineData("-1' 1\"", -1.08333333)] // Normal form
57-
[InlineData("-1′ 1″", -1.08333333)] // Normal form
58-
[InlineData(" -1′ 1″ ", -1.08333333)] // Normal form, requires trimming
59-
[InlineData("-1'1\"", -1.08333333)] // Without space
60-
[InlineData("-1′1″", -1.08333333)] // Without space
61-
[InlineData("-1 ft 1 in", -1.08333333)]
62-
[InlineData("-1ft 1in", -1.08333333)]
63-
public void TryParseFeetInches(string str, double expectedFeet)
75+
[MemberData(nameof(ValidData))]
76+
public void TryParseFeetInches(string str, double expectedFeet, CultureInfo formatProvider)
6477
{
65-
Assert.True(Length.TryParseFeetInches(str, out Length result));
78+
Assert.True(Length.TryParseFeetInches(str, out Length result, formatProvider));
6679
AssertEx.EqualTolerance(expectedFeet, result.Feet, 1e-5);
6780
}
6881

82+
public static IEnumerable<object[]> InvalidData => new List<object[]>
83+
{
84+
new object[]{"a", new CultureInfo("en-US", false)}, // Missing or invalid apostrophe or double prime chars
85+
new object[]{"1", new CultureInfo("en-US", false)},
86+
new object[]{"1`", new CultureInfo("en-US", false)},
87+
new object[]{"1^", new CultureInfo("en-US", false)},
88+
new object[]{"1' 1'", new CultureInfo("en-US", false)}, // Feet apostrophe twice
89+
new object[]{"1′ 1′", new CultureInfo("en-US", false)},
90+
new object[]{"1' 1", new CultureInfo("en-US", false)}, // No inches double prime
91+
new object[]{"1′ 1", new CultureInfo("en-US", false)},
92+
new object[]{"1′ 1`", new CultureInfo("en-US", false)}, // Invalid inches double prime
93+
new object[]{"1' 1`", new CultureInfo("en-US", false)},
94+
new object[]{"1'1'", new CultureInfo("en-US", false)}, // Same without space
95+
new object[]{"1′1′", new CultureInfo("en-US", false)},
96+
new object[]{"1'1", new CultureInfo("en-US", false)},
97+
new object[]{"1′1", new CultureInfo("en-US", false)},
98+
new object[]{"1′1`", new CultureInfo("en-US", false)},
99+
new object[]{"1'1`", new CultureInfo("en-US", false)}
100+
};
101+
69102
[Theory]
70-
[InlineData("a")] // Missing or invalid apostrophe or double prime chars
71-
[InlineData("1")]
72-
[InlineData("1`")]
73-
[InlineData("1^")]
74-
[InlineData("1' 1'")] // Feet apostrophe twice
75-
[InlineData("1′ 1′")]
76-
[InlineData("1' 1")] // No inches double prime
77-
[InlineData("1′ 1")]
78-
[InlineData("1′ 1`")] // Invalid inches double prime
79-
[InlineData("1' 1`")]
80-
[InlineData("1'1'")] // Same without space
81-
[InlineData("1′1′")]
82-
[InlineData("1'1")]
83-
[InlineData("1′1")]
84-
[InlineData("1′1`")]
85-
[InlineData("1'1`")]
86-
public void TryParseFeetInches_GivenInvalidString_ReturnsFalseAndZeroOut(string str)
103+
[MemberData(nameof(InvalidData))]
104+
public void TryParseFeetInches_GivenInvalidString_ReturnsFalseAndZeroOut(string str, CultureInfo formatProvider)
87105
{
88-
Assert.False(Length.TryParseFeetInches(str, out Length result));
106+
Assert.False(Length.TryParseFeetInches(str, out Length result, formatProvider));
89107
Assert.Equal(Length.Zero, result);
90108
}
91109
}

0 commit comments

Comments
 (0)