@@ -11,38 +11,46 @@ public class FormatTests : TestBase
1111{
1212 public FormatTests ( ITestOutputHelper output ) : base ( output ) { }
1313
14- public static IEnumerable < object [ ] > EndpointData ( )
14+ public static IEnumerable < object ? [ ] > EndpointData ( )
1515 {
16+ // note: the 3rd arg is for formatting; null means "expect the original string"
17+
1618 // DNS
17- yield return new object [ ] { "localhost" , new DnsEndPoint ( "localhost" , 0 ) } ;
18- yield return new object [ ] { "localhost:6390" , new DnsEndPoint ( "localhost" , 6390 ) } ;
19- yield return new object [ ] { "bob.the.builder.com" , new DnsEndPoint ( "bob.the.builder.com" , 0 ) } ;
20- yield return new object [ ] { "bob.the.builder.com:6390" , new DnsEndPoint ( "bob.the.builder.com" , 6390 ) } ;
19+ yield return new object ? [ ] { "localhost" , new DnsEndPoint ( "localhost" , 0 ) , null } ;
20+ yield return new object ? [ ] { "localhost:6390" , new DnsEndPoint ( "localhost" , 6390 ) , null } ;
21+ yield return new object ? [ ] { "bob.the.builder.com" , new DnsEndPoint ( "bob.the.builder.com" , 0 ) , null } ;
22+ yield return new object ? [ ] { "bob.the.builder.com:6390" , new DnsEndPoint ( "bob.the.builder.com" , 6390 ) , null } ;
2123 // IPv4
22- yield return new object [ ] { "0.0.0.0" , new IPEndPoint ( IPAddress . Parse ( "0.0.0.0" ) , 0 ) } ;
23- yield return new object [ ] { "127.0.0.1" , new IPEndPoint ( IPAddress . Parse ( "127.0.0.1" ) , 0 ) } ;
24- yield return new object [ ] { "127.1" , new IPEndPoint ( IPAddress . Parse ( "127.1" ) , 0 ) } ;
25- yield return new object [ ] { "127.1:6389" , new IPEndPoint ( IPAddress . Parse ( "127.1" ) , 6389 ) } ;
26- yield return new object [ ] { "127.0.0.1:6389" , new IPEndPoint ( IPAddress . Parse ( "127.0.0.1" ) , 6389 ) } ;
27- yield return new object [ ] { "127.0.0.1:1" , new IPEndPoint ( IPAddress . Parse ( "127.0.0.1" ) , 1 ) } ;
28- yield return new object [ ] { "127.0.0.1:2" , new IPEndPoint ( IPAddress . Parse ( "127.0.0.1" ) , 2 ) } ;
29- yield return new object [ ] { "10.10.9.18:2" , new IPEndPoint ( IPAddress . Parse ( "10.10.9.18" ) , 2 ) } ;
24+ yield return new object ? [ ] { "0.0.0.0" , new IPEndPoint ( IPAddress . Parse ( "0.0.0.0" ) , 0 ) , null } ;
25+ yield return new object ? [ ] { "127.0.0.1" , new IPEndPoint ( IPAddress . Parse ( "127.0.0.1" ) , 0 ) , null } ;
26+ yield return new object ? [ ] { "127.1" , new IPEndPoint ( IPAddress . Parse ( "127.1" ) , 0 ) , "127.0.0.1" } ;
27+ yield return new object ? [ ] { "127.1:6389" , new IPEndPoint ( IPAddress . Parse ( "127.1" ) , 6389 ) , "127.0.0.1:6389" } ;
28+ yield return new object ? [ ] { "127.0.0.1:6389" , new IPEndPoint ( IPAddress . Parse ( "127.0.0.1" ) , 6389 ) , null } ;
29+ yield return new object ? [ ] { "127.0.0.1:1" , new IPEndPoint ( IPAddress . Parse ( "127.0.0.1" ) , 1 ) , null } ;
30+ yield return new object ? [ ] { "127.0.0.1:2" , new IPEndPoint ( IPAddress . Parse ( "127.0.0.1" ) , 2 ) , null } ;
31+ yield return new object ? [ ] { "10.10.9.18:2" , new IPEndPoint ( IPAddress . Parse ( "10.10.9.18" ) , 2 ) , null } ;
3032 // IPv6
31- yield return new object [ ] { "::1" , new IPEndPoint ( IPAddress . Parse ( "::1" ) , 0 ) } ;
32- yield return new object [ ] { "::1:6379" , new IPEndPoint ( IPAddress . Parse ( "::0.1.99.121" ) , 0 ) } ; // remember your brackets!
33- yield return new object [ ] { "[::1]:6379" , new IPEndPoint ( IPAddress . Parse ( "::1" ) , 6379 ) } ;
34- yield return new object [ ] { "[::1]" , new IPEndPoint ( IPAddress . Parse ( "::1" ) , 0 ) } ;
35- yield return new object [ ] { "[::1]:1000" , new IPEndPoint ( IPAddress . Parse ( "::1" ) , 1000 ) } ;
36- yield return new object [ ] { "[2001:db7:85a3:8d2:1319:8a2e:370:7348]" , new IPEndPoint ( IPAddress . Parse ( "2001:db7:85a3:8d2:1319:8a2e:370:7348" ) , 0 ) } ;
37- yield return new object [ ] { "[2001:db7:85a3:8d2:1319:8a2e:370:7348]:1000" , new IPEndPoint ( IPAddress . Parse ( "2001:db7:85a3:8d2:1319:8a2e:370:7348" ) , 1000 ) } ;
33+ yield return new object ? [ ] { "::1" , new IPEndPoint ( IPAddress . Parse ( "::1" ) , 0 ) , null } ;
34+ yield return new object ? [ ] { "::1:6379" , new IPEndPoint ( IPAddress . Parse ( "::0.1.99.121" ) , 0 ) , "::0.1.99.121" } ; // remember your brackets!
35+ yield return new object ? [ ] { "[::1]:6379" , new IPEndPoint ( IPAddress . Parse ( "::1" ) , 6379 ) , null } ;
36+ yield return new object ? [ ] { "[::1]" , new IPEndPoint ( IPAddress . Parse ( "::1" ) , 0 ) , "::1" } ;
37+ yield return new object ? [ ] { "[::1]:1000" , new IPEndPoint ( IPAddress . Parse ( "::1" ) , 1000 ) , null } ;
38+ yield return new object ? [ ] { "2001:db7:85a3:8d2:1319:8a2e:370:7348" , new IPEndPoint ( IPAddress . Parse ( "2001:db7:85a3:8d2:1319:8a2e:370:7348" ) , 0 ) , null } ;
39+ yield return new object ? [ ] { "[2001:db7:85a3:8d2:1319:8a2e:370:7348]" , new IPEndPoint ( IPAddress . Parse ( "2001:db7:85a3:8d2:1319:8a2e:370:7348" ) , 0 ) , "2001:db7:85a3:8d2:1319:8a2e:370:7348" } ;
40+ yield return new object ? [ ] { "[2001:db7:85a3:8d2:1319:8a2e:370:7348]:1000" , new IPEndPoint ( IPAddress . Parse ( "2001:db7:85a3:8d2:1319:8a2e:370:7348" ) , 1000 ) , null } ;
3841 }
3942
4043 [ Theory ]
4144 [ MemberData ( nameof ( EndpointData ) ) ]
42- public void ParseEndPoint ( string data , EndPoint expected )
45+ public void ParseEndPoint ( string data , EndPoint expected , string ? expectedFormat )
4346 {
44- _ = Format . TryParseEndPoint ( data , out var result ) ;
47+ Assert . True ( Format . TryParseEndPoint ( data , out var result ) ) ;
4548 Assert . Equal ( expected , result ) ;
49+
50+ // and write again
51+ var s = Format . ToString ( result ) ;
52+ expectedFormat ??= data ;
53+ Assert . Equal ( expectedFormat , s ) ;
4654 }
4755
4856 [ Theory ]
0 commit comments