@@ -9,7 +9,7 @@ partial class NodeTests {
99 [ Test ]
1010 public void TestParse_ArgumentNull ( )
1111 {
12- Assert . Throws < ArgumentNullException > ( ( ) => Node . Parse ( null , provider : null ) ) ;
12+ Assert . Throws < ArgumentNullException > ( ( ) => Node . Parse ( ( string ) null , provider : null ) ) ;
1313
1414#if FEATURE_GENERIC_MATH
1515 Assert . Throws < ArgumentNullException > ( ( ) => Parse < Node > ( null , provider : null ) , "IParseable" ) ;
@@ -61,6 +61,49 @@ public void TestParse(string s, bool expectValid, string expectedString)
6161#endif
6262 }
6363
64+ [ TestCase ( "00:00:00:00:00:00" , true , "00:00:00:00:00:00" ) ]
65+ [ TestCase ( "01:23:45:67:89:AB" , true , "01:23:45:67:89:AB" ) ]
66+ [ TestCase ( "FF:FF:FF:FF:FF:FF" , true , "FF:FF:FF:FF:FF:FF" ) ]
67+ [ TestCase ( "ab:cd:ef:AB:CD:EF" , true , "ab:cd:ef:AB:CD:EF" ) ]
68+ [ TestCase ( "0:1:2:3:4:F" , true , "00:01:02:03:04:0F" ) ]
69+ [ TestCase ( "000:001:002:003:004:00F" , true , "00:01:02:03:04:0F" ) ]
70+ [ TestCase ( "00:00:00:00:00" , false , null ) ]
71+ [ TestCase ( "00" , false , null ) ]
72+ [ TestCase ( "" , false , null ) ]
73+ [ TestCase ( "100:00:00:00:00:00" , false , null ) ]
74+ [ TestCase ( "00:00:00:00:00:100" , false , null ) ]
75+ [ TestCase ( "00:00:00:00:00:0X" , false , null ) ]
76+ [ TestCase ( "00-00-00-00-00-00" , false , null ) ]
77+ [ TestCase ( "00:00:00:00:00-00" , false , null ) ]
78+ public void TestParse_ISpanParseable ( string s , bool expectValid , string expectedString )
79+ {
80+ Node n = default ;
81+
82+ if ( expectValid )
83+ Assert . DoesNotThrow ( ( ) => n = Node . Parse ( s . AsSpan ( ) , provider : null ) ) ;
84+ else
85+ Assert . Throws < FormatException > ( ( ) => n = Node . Parse ( s . AsSpan ( ) , provider : null ) ) ;
86+
87+ if ( expectValid ) {
88+ Assert . AreEqual ( expectedString . ToUpperInvariant ( ) , n . ToString ( "X" ) ) ;
89+ Assert . AreEqual ( expectedString . ToLowerInvariant ( ) , n . ToString ( "x" ) ) ;
90+ }
91+
92+ #if FEATURE_GENERIC_MATH
93+ if ( expectValid )
94+ Assert . DoesNotThrow ( ( ) => n = Parse < Node > ( s . AsSpan ( ) , provider : null ) , "IParseable" ) ;
95+ else
96+ Assert . Throws < FormatException > ( ( ) => n = Parse < Node > ( s . AsSpan ( ) , provider : null ) , "IParseable" ) ;
97+
98+ if ( expectValid ) {
99+ Assert . AreEqual ( expectedString . ToUpperInvariant ( ) , n . ToString ( "X" ) , "IParseable" ) ;
100+ Assert . AreEqual ( expectedString . ToLowerInvariant ( ) , n . ToString ( "x" ) , "IParseable" ) ;
101+ }
102+
103+ static T Parse < T > ( ReadOnlySpan < char > s , IFormatProvider provider ) where T : ISpanParseable < T > => T . Parse ( s , provider ) ;
104+ #endif
105+ }
106+
64107 [ TestCase ( "00:00:00:00:00:00" , true , "00:00:00:00:00:00" ) ]
65108 [ TestCase ( "01:23:45:67:89:AB" , true , "01:23:45:67:89:AB" ) ]
66109 [ TestCase ( "FF:FF:FF:FF:FF:FF" , true , "FF:FF:FF:FF:FF:FF" ) ]
@@ -94,6 +137,42 @@ public void TestTryParse(string s, bool expectValid, string expectedString)
94137 }
95138
96139 static bool TryParse < T > ( string s , out T result ) where T : IParseable < T > => T . TryParse ( s , provider : null , out result ) ;
140+ #endif
141+ }
142+
143+ [ TestCase ( "00:00:00:00:00:00" , true , "00:00:00:00:00:00" ) ]
144+ [ TestCase ( "01:23:45:67:89:AB" , true , "01:23:45:67:89:AB" ) ]
145+ [ TestCase ( "FF:FF:FF:FF:FF:FF" , true , "FF:FF:FF:FF:FF:FF" ) ]
146+ [ TestCase ( "ab:cd:ef:AB:CD:EF" , true , "ab:cd:ef:AB:CD:EF" ) ]
147+ [ TestCase ( "0:1:2:3:4:F" , true , "00:01:02:03:04:0F" ) ]
148+ [ TestCase ( "000:001:002:003:004:00F" , true , "00:01:02:03:04:0F" ) ]
149+ [ TestCase ( "00:00:00:00:00" , false , null ) ]
150+ [ TestCase ( "00" , false , null ) ]
151+ [ TestCase ( "" , false , null ) ]
152+ [ TestCase ( null , false , null ) ]
153+ [ TestCase ( "100:00:00:00:00:00" , false , null ) ]
154+ [ TestCase ( "00:00:00:00:00:100" , false , null ) ]
155+ [ TestCase ( "00:00:00:00:00:0X" , false , null ) ]
156+ [ TestCase ( "00-00-00-00-00-00" , false , null ) ]
157+ [ TestCase ( "00:00:00:00:00-00" , false , null ) ]
158+ public void TestTryParse_ISpanParseable ( string s , bool expectValid , string expectedString )
159+ {
160+ Assert . AreEqual ( expectValid , Node . TryParse ( s . AsSpan ( ) , out var node ) ) ;
161+
162+ if ( expectValid ) {
163+ Assert . AreEqual ( expectedString . ToUpperInvariant ( ) , node . ToString ( "X" ) ) ;
164+ Assert . AreEqual ( expectedString . ToLowerInvariant ( ) , node . ToString ( "x" ) ) ;
165+ }
166+
167+ #if FEATURE_GENERIC_MATH
168+ Assert . AreEqual ( expectValid , TryParse < Node > ( s . AsSpan ( ) , out var node2 ) , "IParseable" ) ;
169+
170+ if ( expectValid ) {
171+ Assert . AreEqual ( expectedString . ToUpperInvariant ( ) , node2 . ToString ( "X" ) , "IParseable" ) ;
172+ Assert . AreEqual ( expectedString . ToLowerInvariant ( ) , node2 . ToString ( "x" ) , "IParseable" ) ;
173+ }
174+
175+ static bool TryParse < T > ( ReadOnlySpan < char > s , out T result ) where T : ISpanParseable < T > => T . TryParse ( s , provider : null , out result ) ;
97176#endif
98177 }
99178}
0 commit comments