-
Notifications
You must be signed in to change notification settings - Fork 0
/
as_test.go
34 lines (28 loc) · 1.18 KB
/
as_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
package bencode_test
import (
"testing"
"code.gopub.tech/assert"
"code.gopub.tech/bencode"
)
func TestAs(t *testing.T) {
var val bencode.Value = bencode.String("str")
assert.Equal(t, bencode.AsStr(val), "str")
assert.Equal(t, bencode.AsInt(val), int64(0))
assert.DeepEqual(t, bencode.AsList(val), bencode.List{})
assert.DeepEqual(t, bencode.AsDict(val), bencode.Dict{})
val = bencode.Integer(10)
assert.Equal(t, bencode.AsStr(val), "")
assert.Equal(t, bencode.AsInt(val), int64(10))
assert.DeepEqual(t, bencode.AsList(val), bencode.List{})
assert.DeepEqual(t, bencode.AsDict(val), bencode.Dict{})
val = bencode.Dict{"key": bencode.Integer(10)}
assert.Equal(t, bencode.AsStr(val), "")
assert.Equal(t, bencode.AsInt(val), int64(0))
assert.DeepEqual(t, bencode.AsList(val), bencode.List{})
assert.DeepEqual(t, bencode.AsDict(val), bencode.Dict{"key": bencode.Integer(10)})
val = bencode.List{bencode.Integer(10), bencode.String("str")}
assert.Equal(t, bencode.AsStr(val), "")
assert.Equal(t, bencode.AsInt(val), int64(0))
assert.DeepEqual(t, bencode.AsList(val), bencode.List{bencode.Integer(10), bencode.String("str")})
assert.DeepEqual(t, bencode.AsDict(val), bencode.Dict{})
}