-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy patharguments_test.go
62 lines (47 loc) · 1.24 KB
/
arguments_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 porthos
import (
"encoding/json"
"testing"
)
func TestStringArgument(t *testing.T) {
value, _ := (&argument{"text"}).AsString()
if value != "text" {
t.Errorf("Argument cast failed, expected: 'text', got: '%s'", value)
}
}
func TestIntArgument(t *testing.T) {
value, _ := (&argument{json.Number("10")}).AsInt()
if value != 10 {
t.Errorf("Argument cast failed, expected: '10', got: '%d'", value)
}
}
func TestBoolArgument(t *testing.T) {
value, _ := (&argument{"true"}).AsBool()
if value {
t.Errorf("Argument cast failed, expected: 'true', got: 'false'")
}
}
func TestInvalidIntArgument(t *testing.T) {
value, err := (&argument{json.Number("xxx")}).AsInt()
if err == nil {
t.Errorf("Error as expected")
}
if value != 0 {
t.Errorf("Argument cast returned non zero result, got: '%d'", value)
}
}
func TestInvalidInt64Argument(t *testing.T) {
value, err := (&argument{json.Number("64000000")}).AsInt()
if err != nil {
t.Errorf("Got an error: %s", err)
}
if value != 64000000 {
t.Errorf("Argument cast failed, expected: '64000000', got: '%d'", value)
}
}
func TestInvalidBoolArgument(t *testing.T) {
_, err := (&argument{"xxx"}).AsBool()
if err != ErrTypeCast {
t.Errorf("Expected ErrTypeCast, got %s", err)
}
}