@@ -38,6 +38,7 @@ public class ParseTests
38
38
{
39
39
[ Theory ]
40
40
[ InlineData ( "1km" , 1000 ) ]
41
+ [ InlineData ( " 1km " , 1000 ) ] // Check that it also trims string
41
42
[ InlineData ( "1 km" , 1000 ) ]
42
43
[ InlineData ( "1e-3 km" , 1 ) ]
43
44
[ InlineData ( "5.5 m" , 5.5 ) ]
@@ -51,11 +52,11 @@ public void ParseLengthToMetersUsEnglish(string s, double expected)
51
52
52
53
[ Theory ]
53
54
[ InlineData ( null , typeof ( ArgumentNullException ) ) ] // Can't parse null.
54
- [ InlineData ( "1" , typeof ( ArgumentException ) ) ] // No unit abbreviation.
55
- [ InlineData ( "km" , typeof ( UnitsNetException ) ) ] // No value, wrong measurement type.
56
- [ InlineData ( "1 kg" , typeof ( UnitsNetException ) ) ] // Wrong measurement type.
57
- [ InlineData ( "1ft monkey 1in" , typeof ( UnitsNetException ) ) ] // Invalid separator between two valid measurements.
58
- [ InlineData ( "1ft 1invalid" , typeof ( UnitsNetException ) ) ] // Valid
55
+ [ InlineData ( "1" , typeof ( FormatException ) ) ] // No unit abbreviation.
56
+ [ InlineData ( "km" , typeof ( FormatException ) ) ] // No value, wrong measurement type.
57
+ [ InlineData ( "1 kg" , typeof ( FormatException ) ) ] // Wrong measurement type.
58
+ [ InlineData ( "1ft monkey 1in" , typeof ( FormatException ) ) ] // Invalid separator between two valid measurements.
59
+ [ InlineData ( "1ft 1invalid" , typeof ( FormatException ) ) ] // Valid
59
60
public void ParseLength_InvalidString_USEnglish_ThrowsException ( string s , Type expectedExceptionType )
60
61
{
61
62
var usEnglish = new CultureInfo ( "en-US" ) ;
@@ -71,20 +72,24 @@ public void ParseWithCultureUsingSpaceAsThousandSeparators(string s, double expe
71
72
{
72
73
var numberFormat = ( NumberFormatInfo ) CultureInfo . InvariantCulture . NumberFormat . Clone ( ) ;
73
74
numberFormat . NumberGroupSeparator = " " ;
75
+ numberFormat . CurrencyGroupSeparator = " " ;
74
76
numberFormat . NumberDecimalSeparator = "." ;
77
+ numberFormat . CurrencyDecimalSeparator = "." ;
75
78
76
79
double actual = Length . Parse ( s , numberFormat ) . Meters ;
77
80
Assert . Equal ( expected , actual ) ;
78
81
}
79
82
80
83
[ Theory ]
81
- [ InlineData ( "500.005.050,001 m" , typeof ( UnitsNetException ) ) ]
84
+ [ InlineData ( "500.005.050,001 m" , typeof ( FormatException ) ) ]
82
85
// quantity doesn't match number format
83
86
public void ParseWithCultureUsingSpaceAsThousandSeparators_ThrowsExceptionOnInvalidString ( string s , Type expectedExceptionType )
84
87
{
85
88
var numberFormat = ( NumberFormatInfo ) CultureInfo . InvariantCulture . NumberFormat . Clone ( ) ;
86
89
numberFormat . NumberGroupSeparator = " " ;
90
+ numberFormat . CurrencyGroupSeparator = " " ;
87
91
numberFormat . NumberDecimalSeparator = "." ;
92
+ numberFormat . CurrencyDecimalSeparator = "." ;
88
93
89
94
Assert . Throws ( expectedExceptionType , ( ) => Length . Parse ( s , numberFormat ) ) ;
90
95
}
@@ -98,7 +103,9 @@ public void ParseWithCultureUsingDotAsThousandSeparators(string s, double expect
98
103
{
99
104
var numberFormat = ( NumberFormatInfo ) CultureInfo . InvariantCulture . NumberFormat . Clone ( ) ;
100
105
numberFormat . NumberGroupSeparator = "." ;
106
+ numberFormat . CurrencyGroupSeparator = "." ;
101
107
numberFormat . NumberDecimalSeparator = "," ;
108
+ numberFormat . CurrencyDecimalSeparator = "," ;
102
109
103
110
double actual = Length . Parse ( s , numberFormat ) . Meters ;
104
111
Assert . Equal ( expected , actual ) ;
@@ -112,12 +119,14 @@ public void ParseMultiWordAbbreviations()
112
119
}
113
120
114
121
[ Theory ]
115
- [ InlineData ( "500 005 m" , typeof ( UnitsNetException ) ) ] // Quantity doesn't match number format.
122
+ [ InlineData ( "500 005 m" , typeof ( FormatException ) ) ] // Quantity doesn't match number format.
116
123
public void ParseWithCultureUsingDotAsThousandSeparators_ThrowsExceptionOnInvalidString ( string s , Type expectedExceptionType )
117
124
{
118
125
var numberFormat = ( NumberFormatInfo ) CultureInfo . InvariantCulture . NumberFormat . Clone ( ) ;
119
126
numberFormat . NumberGroupSeparator = "." ;
127
+ numberFormat . CurrencyGroupSeparator = "." ;
120
128
numberFormat . NumberDecimalSeparator = "," ;
129
+ numberFormat . CurrencyDecimalSeparator = "," ;
121
130
122
131
Assert . Throws ( expectedExceptionType , ( ) => Length . Parse ( s , numberFormat ) ) ;
123
132
}
@@ -142,7 +151,7 @@ public void ParseLengthUnitUsEnglish_ThrowsExceptionOnInvalidString(string s, Ty
142
151
143
152
[ Theory ]
144
153
[ InlineData ( "1 m" , true ) ]
145
- [ InlineData ( "1 m 50 cm" , true ) ]
154
+ [ InlineData ( "1 m 50 cm" , false ) ]
146
155
[ InlineData ( "2 kg" , false ) ]
147
156
[ InlineData ( null , false ) ]
148
157
[ InlineData ( "foo" , false ) ]
0 commit comments