@@ -413,6 +413,32 @@ func TestAddrPortMarshalUnmarshalBinary(t *testing.T) {
413
413
}
414
414
}
415
415
416
+ func TestPrefixMarshalTextString (t * testing.T ) {
417
+ tests := []struct {
418
+ in Prefix
419
+ want string
420
+ }{
421
+ {mustPrefix ("1.2.3.4/24" ), "1.2.3.4/24" },
422
+ {mustPrefix ("fd7a:115c:a1e0:ab12:4843:cd96:626b:430b/118" ), "fd7a:115c:a1e0:ab12:4843:cd96:626b:430b/118" },
423
+ {mustPrefix ("::ffff:c000:0280/96" ), "::ffff:192.0.2.128/96" },
424
+ {mustPrefix ("::ffff:c000:0280%eth0/37" ), "::ffff:192.0.2.128/37" }, // Zone should be stripped
425
+ {mustPrefix ("::ffff:192.168.140.255/8" ), "::ffff:192.168.140.255/8" },
426
+ }
427
+ for i , tt := range tests {
428
+ if got := tt .in .String (); got != tt .want {
429
+ t .Errorf ("%d. for %v String = %q; want %q" , i , tt .in , got , tt .want )
430
+ }
431
+ mt , err := tt .in .MarshalText ()
432
+ if err != nil {
433
+ t .Errorf ("%d. for %v MarshalText error: %v" , i , tt .in , err )
434
+ continue
435
+ }
436
+ if string (mt ) != tt .want {
437
+ t .Errorf ("%d. for %v MarshalText = %q; want %q" , i , tt .in , mt , tt .want )
438
+ }
439
+ }
440
+ }
441
+
416
442
func TestPrefixMarshalUnmarshalBinary (t * testing.T ) {
417
443
type testCase struct {
418
444
prefix Prefix
@@ -994,7 +1020,6 @@ func TestPrefixMarshalUnmarshal(t *testing.T) {
994
1020
"0.0.0.0/0" ,
995
1021
"::/0" ,
996
1022
"::1/128" ,
997
- "::ffff:c000:1234/128" ,
998
1023
"2001:db8::/32" ,
999
1024
}
1000
1025
0 commit comments