-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdocopt_test.go
62 lines (50 loc) · 1.77 KB
/
docopt_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
package commander
import (
"github.com/WindomZ/testify/assert"
"testing"
)
func TestDocoptMap_Get(t *testing.T) {
var m map[string]interface{} = map[string]interface{}{
"string": "abc",
"strings": []string{"abc", "efg"},
"bool": true,
"int": 1,
"int8": 8,
"int16": 16,
"int32": 32,
"int64": 64,
"float32": 32.32,
"float64": 64.64,
}
var d DocoptMap = newDocoptMap(m)
assert.Equal(t, d.Contain("string"), true)
assert.Equal(t, d.MustString("string"), "abc")
assert.Equal(t, d.MustString("string-x"), "")
assert.Equal(t, d.Contain("strings"), true)
assert.Equal(t, d.MustStrings("strings"), []string{"abc", "efg"})
assert.Equal(t, d.MustStrings("strings-x"), []string{})
assert.Equal(t, d.Contain("bool"), true)
assert.Equal(t, d.MustBool("bool"), true)
assert.Equal(t, d.MustBool("bool-x"), false)
assert.Equal(t, d.Contain("int"), true)
assert.Equal(t, d.MustInt("int"), 1)
assert.Equal(t, d.MustInt("int-x"), 0)
assert.Equal(t, d.Contain("int8"), true)
assert.Equal(t, d.MustInt("int8"), 8)
assert.Equal(t, d.MustInt("int8-x"), 0)
assert.Equal(t, d.Contain("int16"), true)
assert.Equal(t, d.MustInt("int16"), 16)
assert.Equal(t, d.MustInt("int16-x"), 0)
assert.Equal(t, d.Contain("int32"), true)
assert.Equal(t, d.MustInt("int32"), 32)
assert.Equal(t, d.MustInt("int32-x"), 0)
assert.Equal(t, d.Contain("int64"), true)
assert.Equal(t, d.MustInt64("int64"), int64(64))
assert.Equal(t, d.MustInt64("int64-x"), int64(0))
assert.Equal(t, d.Contain("float32"), true)
assert.Equal(t, d.MustFloat("float32"), float32(32.32))
assert.Equal(t, d.MustFloat("float32-x"), float32(0))
assert.Equal(t, d.Contain("float64"), true)
assert.Equal(t, d.MustFloat64("float64"), float64(64.64))
assert.Equal(t, d.MustFloat64("float64-x"), float64(0))
}