-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformat_test.go
80 lines (70 loc) · 1.55 KB
/
format_test.go
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package asn_test
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/thatmattlove/go-asn"
)
type decimalFmtT struct {
from asn.ASN
want string
}
var decimalCases = []decimalFmtT{
{asn.ASN{0, 0, 0, 1}, "1"},
{asn.ASN{0, 0, 56, 189}, "14525"},
}
func TestASN_Decimal(t *testing.T) {
for _, c := range decimalCases {
c := c
t.Run(c.want, func(t *testing.T) {
t.Parallel()
assert.Equal(t, c.want, c.from.Decimal())
})
}
}
func TestASN_ASPlain(t *testing.T) {
for _, c := range decimalCases {
c := c
t.Run(c.want, func(t *testing.T) {
t.Parallel()
assert.Equal(t, c.want, c.from.ASPlain())
})
}
}
func TestASN_String(t *testing.T) {
for _, c := range decimalCases {
c := c
t.Run(c.want, func(t *testing.T) {
t.Parallel()
assert.Equal(t, c.want, c.from.String())
})
}
}
func TestASN_ASDot(t *testing.T) {
t.Run("4B", func(t *testing.T) {
t.Parallel()
a := asn.MustDecimal("4200000000")
assert.Equal(t, "64086.59904", a.ASDot())
})
t.Run("2B", func(t *testing.T) {
t.Parallel()
a := asn.MustDecimal("65000")
assert.Equal(t, "65000", a.ASDot())
})
}
func TestASN_ASDotPlus(t *testing.T) {
t.Run("2B", func(t *testing.T) {
t.Parallel()
a := asn.MustParse("65000")
assert.Equal(t, "0.65000", a.ASDotPlus())
})
t.Run("4B", func(t *testing.T) {
t.Parallel()
a := asn.MustParse("4200000000")
assert.Equal(t, "64086.59904", a.ASDotPlus())
})
}
func TestASN_ByteString(t *testing.T) {
asn := asn.MustParse("65000")
expected := "{0,0,253,232}"
assert.Equal(t, expected, asn.ByteString())
}