1
0
mirror of https://github.com/charlienet/go-mixed.git synced 2025-07-18 08:32:40 +08:00

添加掩码格式

This commit is contained in:
2022-07-28 14:27:23 +08:00
parent 52fabedd66
commit 135b3a983b
4 changed files with 110 additions and 1 deletions

View File

@ -0,0 +1,26 @@
package iprange
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func TestMaskToBits(t *testing.T) {
masks := []struct {
mask string
expect int
}{
{"255.255.255.0", 24},
{"255.255.248.0", 21},
{"255.255.192.0", 18},
{"255.255.255.192", 26},
}
for _, m := range masks {
bits := MaskToBits(m.mask)
assert.Equal(t, m.expect, bits, fmt.Sprintf("IP:%s 掩码位数错误。", m.mask))
}
}