blob: 6ad5e077db13757875eb530e3d405c79df17e36c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
package iputil
import (
"math/big"
"net"
"testing"
)
func TestToDecimal(t *testing.T) {
var msb = new(big.Int)
msb, _ = msb.SetString("80000000000000000000000000000000", 16)
var tests = []struct {
in string
out *big.Int
}{
{"127.0.0.1", big.NewInt(2130706433)},
{"::1", big.NewInt(1)},
{"8000::", msb},
}
for _, tt := range tests {
i := ToDecimal(net.ParseIP(tt.in))
if tt.out.Cmp(i) != 0 {
t.Errorf("Expected %d, got %d for IP %s", tt.out, i, tt.in)
}
}
}
|