-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplus_test.go
97 lines (81 loc) · 2.89 KB
/
plus_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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package jq
import (
"testing"
"nikand.dev/go/cbor"
)
func TestPlusInt(tb *testing.T) {
b := NewBuffer()
six := b.appendVal(6)
minusfive := b.appendVal(-5)
testOne(tb, NewPlus(Zero, Zero), b, Null, Zero)
testOne(tb, NewPlus(Zero, One), b, Null, One)
testOne(tb, NewPlus(One, Zero), b, Null, One)
testOne(tb, NewPlus(One, Null), b, Null, One)
testOne(tb, NewPlus(Null, One), b, Null, One)
testOne(tb, NewPlus(Null, Null), b, Null, Null)
testOne(tb, NewPlus(six, six), b, Null, 12)
testOne(tb, NewPlus(six, minusfive), b, Null, One)
testOne(tb, NewPlus(minusfive, minusfive), b, Null, -10)
}
func TestPlusString(tb *testing.T) {
b := NewBuffer()
a := b.appendVal("aa")
c := b.appendVal("ccc")
testOne(tb, NewPlus(a, c), b, Null, "aaccc")
testOne(tb, NewPlus(c, a), b, Null, "cccaa")
testOne(tb, NewPlus(a, EmptyString), b, Null, "aa")
testOne(tb, NewPlus(EmptyString, c), b, Null, "ccc")
testOne(tb, NewPlus(EmptyString, EmptyString), b, Null, "")
testOne(tb, NewPlus(a, Null), b, Null, "aa")
testOne(tb, NewPlus(Null, c), b, Null, "ccc")
}
func TestPlusArray(tb *testing.T) {
b := NewBuffer()
a := b.appendVal(arr{1, 2, 3})
c := b.appendVal(arr{4, 5})
testOne(tb, NewPlus(a, c), b, Null, arr{1, 2, 3, 4, 5})
testOne(tb, NewPlus(c, a), b, Null, arr{4, 5, 1, 2, 3})
testOne(tb, NewPlus(a, EmptyArray), b, Null, arr{1, 2, 3})
testOne(tb, NewPlus(EmptyArray, c), b, Null, arr{4, 5})
testOne(tb, NewPlus(EmptyArray, EmptyArray), b, Null, arr{})
testOne(tb, NewPlus(a, Null), b, Null, a)
testOne(tb, NewPlus(Null, c), b, Null, c)
}
func TestPlusMap(tb *testing.T) {
b := NewBuffer()
e := b.appendVal(obj{})
a := b.appendVal(obj{"a", 1, "b", 2})
c := b.appendVal(obj{"a", 3, "c", 4})
d := b.appendVal(obj{"d", 10})
testOne(tb, NewPlus(a, a), b, Null, a)
testOne(tb, NewPlus(a, e), b, Null, a)
testOne(tb, NewPlus(e, a), b, Null, a)
testOne(tb, NewPlus(a, c), b, Null, obj{"a", 3, "b", 2, "c", 4})
testOne(tb, NewPlus(c, a), b, Null, obj{"a", 1, "c", 4, "b", 2})
testOne(tb, NewPlus(a, d), b, Null, obj{"a", 1, "b", 2, "d", 10})
}
func TestPlusFloat(tb *testing.T) {
b := NewBuffer()
a := b.appendVal(6.5)
c := b.appendVal(-5.25)
d := b.appendVal(4)
e := b.appendVal(-3)
testOne(tb, NewPlus(a, a), b, Null, 6.5+6.5)
testOne(tb, NewPlus(a, c), b, Null, 6.5-5.25)
testOne(tb, NewPlus(a, d), b, Null, 6.5+4)
testOne(tb, NewPlus(a, e), b, Null, 6.5-3)
testOne(tb, NewPlus(e, c), b, Null, -3-5.25)
}
func TestPlusIter(tb *testing.T) {
b := NewBuffer()
f := b.appendVal(5)
x := b.appendVal(arr{1, 2})
y := b.appendVal(arr{10, 20})
testIter(tb, NewPlus(NewIterOf(x), f), b, Null, []any{6, 7})
testIter(tb, NewPlus(f, NewIterOf(y)), b, Null, []any{15, 25})
testIter(tb, NewPlus(NewIterOf(x), NewIterOf(y)), b, Null, []any{11, 21, 12, 22})
}
func TestPlusError(tb *testing.T) {
b := NewBuffer()
testError(tb, NewPlus(One, EmptyString), b, Null, PlusError(cbor.Int)|PlusError(cbor.String)<<8)
}