forked from zserge/lorca
-
Notifications
You must be signed in to change notification settings - Fork 0
/
value_test.go
52 lines (46 loc) · 879 Bytes
/
value_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
package lorca
import (
"encoding/json"
"errors"
"testing"
)
var errTest = errors.New("fail")
func TestValueError(t *testing.T) {
v := value{err: errTest}
if v.Err() != errTest {
t.Fail()
}
v = value{raw: json.RawMessage(`"hello"`)}
if v.Err() != nil {
t.Fail()
}
}
func TestValuePrimitive(t *testing.T) {
v := value{raw: json.RawMessage(`42`)}
if v.Int() != 42 {
t.Fail()
}
v = value{raw: json.RawMessage(`"hello"`)}
if v.Int() != 0 || v.String() != "hello" {
t.Fail()
}
v = value{err: errTest}
if v.Int() != 0 || v.String() != "" {
t.Fail()
}
}
func TestValueComplex(t *testing.T) {
v := value{raw: json.RawMessage(`["foo", 42.3, {"x": 5}]`)}
if len(v.Array()) != 3 {
t.Fail()
}
if v.Array()[0].String() != "foo" {
t.Fail()
}
if v.Array()[1].Float() != 42.3 {
t.Fail()
}
if v.Array()[2].Object()["x"].Int() != 5 {
t.Fail()
}
}