-
Notifications
You must be signed in to change notification settings - Fork 0
/
identifier_test.go
51 lines (48 loc) · 1.06 KB
/
identifier_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
package djson
import "testing"
func TestIdentifier_Value(t *testing.T) {
vs := NewContext(
Variable{
Name: []byte("hello"),
Value: Value{
Type: ValueArray,
Value: NewArray(
Value{Type: ValueInt, Value: int64(1)},
),
},
})
// hello.0
id := NewIdentifier([]byte{'0'}, vs)
id.SetParent(Value{
Type: ValueIdentifier, Value: NewIdentifier([]byte("hello"), vs),
})
val := id.Value()
if !(val.Type == ValueInt && val.Value.(int64) == 1) {
t.Fatal("value of array error")
}
}
func TestIdentifier_Assign(t *testing.T) {
vs := NewContext(
Variable{
Name: []byte("hello"),
Value: Value{
Type: ValueArray,
Value: NewArray(
Value{Type: ValueInt, Value: int64(1)},
),
},
})
// hello.0 = 2
id := NewIdentifier([]byte{'0'}, vs)
id.SetParent(Value{
Type: ValueIdentifier, Value: NewIdentifier([]byte("hello"), vs),
})
err := id.Assign(Value{Type: ValueInt, Value: int64(2)})
if err != nil {
t.Fatal(err)
}
val := id.Value()
if !(val.Type == ValueInt && val.Value.(int64) == 2) {
t.Fatal("value of array error")
}
}