@@ -3,14 +3,32 @@ package main
33import "testing"
44
55func TestIsIPFull (t * testing.T ) {
6- assertCidrNotateSplit ("192.168.33.1" , []string {"192.168.33.1" , "32" }, t )
7- assertCidrNotateSplit ("192.168.33.1/30" , []string {"192.168.33.1" , "30" }, t )
8- assertCidrNotateSplit ("255.255.0.0" , []string {"255.255.0.0" , "32" }, t )
9- assertCidrNotateSplit ("255.255.0.0/16" , []string {"255.255.0.0" , "16" }, t )
10- assertCidrNotateSplit ("255.0" , []string {"255.0" , "32" }, t )
11- assertCidrNotateSplit ("255.0/8" , []string {"255.0" , "8" }, t )
12- assertCidrNotateSplit ("1" , []string {"1" , "32" }, t )
13- assertCidrNotateSplit ("1/30" , []string {"1" , "30" }, t )
6+ assertNotateSplit ("192.168.33.1" , newNt ("192.168.33.1" ), t )
7+ assertNotateSplit ("192.168.33.1/30" , newNt ("192.168.33.1" , "/" , "30" ), t )
8+ assertNotateSplit ("255.255.0.0" , newNt ("255.255.0.0" ), t )
9+ assertNotateSplit ("255.255.0.0/16" , newNt ("255.255.0.0" , "/" , "16" ), t )
10+ assertNotateSplit ("255.0" , newNt ("255.0" ), t )
11+ assertNotateSplit ("255.0/8" , newNt ("255.0" , "/" , "8" ), t )
12+ assertNotateSplit ("1" , newNt ("1" ), t )
13+ assertNotateSplit ("1/30" , newNt ("1" , "/" , "30" ), t )
14+
15+ assertNotateSplit ("192.168.33.1" , newNt ("192.168.33.1" ), t )
16+ assertNotateSplit ("192.168.33.1+30" , newNt ("192.168.33.1" , "+" , "30" ), t )
17+ assertNotateSplit ("255.255.0.0" , newNt ("255.255.0.0" ), t )
18+ assertNotateSplit ("255.255.0.0+16" , newNt ("255.255.0.0" , "+" , "16" ), t )
19+ assertNotateSplit ("255.0" , newNt ("255.0" ), t )
20+ assertNotateSplit ("255.0+8" , newNt ("255.0" , "+" , "8" ), t )
21+ assertNotateSplit ("1" , newNt ("1" ), t )
22+ assertNotateSplit ("1+30" , newNt ("1" , "+" , "30" ), t )
23+
24+ assertNotateSplit ("192.168.33.1" , newNt ("192.168.33.1" ), t )
25+ assertNotateSplit ("192.168.33.1-30" , newNt ("192.168.33.1" , "-" , "30" ), t )
26+ assertNotateSplit ("255.255.0.0" , newNt ("255.255.0.0" ), t )
27+ assertNotateSplit ("255.255.0.0-16" , newNt ("255.255.0.0" , "-" , "16" ), t )
28+ assertNotateSplit ("255.0" , newNt ("255.0" ), t )
29+ assertNotateSplit ("255.0-8" , newNt ("255.0" , "-" , "8" ), t )
30+ assertNotateSplit ("1" , newNt ("1" ), t )
31+ assertNotateSplit ("1-30" , newNt ("1" , "-" , "30" ), t )
1432
1533 assertIsCIDRNotation ("192.168.33.1" , false , t )
1634 assertIsCIDRNotation ("192.168.33.1/30" , true , t )
@@ -40,22 +58,14 @@ func TestIsIPFull(t *testing.T) {
4058 assertIsInt ("1" , true , t )
4159}
4260
43- func assertCidrNotateSplit (inp string , exp [] string , t * testing.T ) {
44- res := cidrNotateSplit (inp )
45- if len ( res ) != len ( exp ) {
61+ func assertNotateSplit (inp string , exp tNotation , t * testing.T ) {
62+ res := notateSplit (inp )
63+ if res . Pre != exp . Pre || res . Op != exp . Op || res . Suf != exp . Suf {
4664 t .Errorf (
47- "result and expecation differ in length : %s -> %s != %s" ,
65+ "notateSplit failed : %s -> %s != %s" ,
4866 inp , exp , res ,
4967 )
5068 }
51- for i := 1 ; i <= len (res )- 1 ; i ++ {
52- if exp [i ] != res [i ] {
53- t .Errorf (
54- "result and expectation differ: %s -> %s != %s" ,
55- inp , exp , res ,
56- )
57- }
58- }
5969}
6070
6171func assertIsCIDRNotation (inp string , exp bool , t * testing.T ) {
@@ -85,3 +95,16 @@ func assertIsInt(inp string, exp bool, t *testing.T) {
8595 t .Errorf ("isInt failed: %s -> %v != %v" , inp , exp , res )
8696 }
8797}
98+
99+ func newNt (params ... any ) (nt tNotation ) {
100+ if len (params ) > 0 {
101+ nt .Pre = params [0 ].(string )
102+ }
103+ if len (params ) > 1 {
104+ nt .Op = params [1 ].(string )
105+ }
106+ if len (params ) > 2 {
107+ nt .Suf = params [2 ].(string )
108+ }
109+ return nt
110+ }
0 commit comments