-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjst_test.go
153 lines (137 loc) · 4.9 KB
/
jst_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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package jst
import (
"bytes"
"strings"
"testing"
. "github.com/warpfork/go-wish"
"github.com/ipld/go-ipld-prime/codec/dagjson"
"github.com/ipld/go-ipld-prime/node/basicnode"
)
func TestSimple(t *testing.T) {
fixture := Dedent(`
[
{"path": "./foo", "moduleName": "whiz.org/teamBar/foo", "status": "changed"},
{"path": "./baz", "moduleName": "whiz.org/teamBar/baz", "status": "green"},
{"path": "./quxx", "moduleName": "example.net/quxx", "status": "lit"}
]`)
nb := basicnode.Prototype.Any.NewBuilder()
Require(t, dagjson.Decode(nb, strings.NewReader(fixture)), ShouldEqual, nil)
n := nb.Build()
st := state{}
Wish(t, stride(&st, n), ShouldEqual, nil)
Wish(t, st.tables, ShouldEqual, map[tableGroupID]*table{
"path": {
entryStyles: map[columnName]entryStyle{"path": entryStyle_column, "moduleName": entryStyle_column, "status": entryStyle_column},
keySize: map[columnName]int{"path": 6, "moduleName": 12, "status": 8},
cols: []columnName{"path", "moduleName", "status"},
colSize: map[columnName]int{"path": 8, "moduleName": 22, "status": 9},
ownLine: nil,
},
})
var buf bytes.Buffer
Wish(t, Marshal(n, &buf), ShouldEqual, nil)
Wish(t, buf.String(), ShouldEqual, fixture)
}
func TestAbsentColumn(t *testing.T) {
t.Run("absent column midrow", func(t *testing.T) {
fixture := Dedent(`
[
{"path": "./foo", "optionalColumn": "fwoo", "status": "changed"},
{"path": "./baz", "status": "green"},
{"path": "./quxx", "optionalColumn": "wicked", "status": "lit"}
]`)
nb := basicnode.Prototype.Any.NewBuilder()
Require(t, dagjson.Decode(nb, strings.NewReader(fixture)), ShouldEqual, nil)
n := nb.Build()
var buf bytes.Buffer
Wish(t, Marshal(n, &buf), ShouldEqual, nil)
Wish(t, buf.String(), ShouldEqual, fixture)
})
t.Run("absent column rowend", func(t *testing.T) {
fixture := Dedent(`
[
{"path": "./foo", "status": "changed", "optionalColumn": "fwoo"},
{"path": "./baz", "status": "asdf"},
{"path": "./quxx", "status": "lit", "optionalColumn": "wicked"}
]`)
nb := basicnode.Prototype.Any.NewBuilder()
Require(t, dagjson.Decode(nb, strings.NewReader(fixture)), ShouldEqual, nil)
n := nb.Build()
var buf bytes.Buffer
Wish(t, Marshal(n, &buf), ShouldEqual, nil)
Wish(t, buf.String(), ShouldEqual, fixture)
})
}
func TestTrailing(t *testing.T) {
// FUTURE
}
func TestSubTables(t *testing.T) {
fixture := Dedent(`
[
{"path": "./foo", "moduleName": "whiz.org/teamBar/foo", "status": "changed"},
{"path": "./baz", "moduleName": "whiz.org/teamBar/baz", "status": "green",
"subtable": [
{"frob": "zozzle", "zim": "boink"},
{"frob": "narf", "zim": "zamf"}
]},
{"path": "./quxx", "moduleName": "example.net/quxx", "status": "lit"}
]`)
nb := basicnode.Prototype.Any.NewBuilder()
Require(t, dagjson.Decode(nb, strings.NewReader(fixture)), ShouldEqual, nil)
n := nb.Build()
var buf bytes.Buffer
Wish(t, Marshal(n, &buf), ShouldEqual, nil)
Wish(t, buf.String(), ShouldEqual, fixture)
}
func TestSubTablesCorrelated(t *testing.T) {
fixture := Dedent(`
[
{"path": "./foo", "moduleName": "whiz.org/teamBar/foo", "status": "changed"},
{"path": "./baz", "moduleName": "whiz.org/teamBar/baz", "status": "green",
"subtable": [
{"frob": "zozzle", "zim": "boink"},
{"frob": "narf", "zim": "zamf"}
]},
{"path": "./quxx", "moduleName": "example.net/quxx", "status": "lit",
"subtable": [
{"frob": "evenlonger", "zim": "boink"},
{"frob": "narf", "zim": "zamf"}
]}
]`)
nb := basicnode.Prototype.Any.NewBuilder()
Require(t, dagjson.Decode(nb, strings.NewReader(fixture)), ShouldEqual, nil)
n := nb.Build()
var buf bytes.Buffer
Wish(t, Marshal(n, &buf), ShouldEqual, nil)
Wish(t, buf.String(), ShouldEqual, fixture)
}
func TestSubSubTables(t *testing.T) {
fixture := Dedent(`
[
{"path": "./foo", "moduleName": "whiz.org/teamBar/foo", "status": "changed"},
{"path": "./baz", "moduleName": "whiz.org/teamBar/baz", "status": "green",
"subtable": [
{"frob": "zozzle", "zim": "boink",
"subsubtable": [
{"quite": "something", "very": "neat"},
{"quite": "staggering", "very": "sweet"}
]},
{"frob": "narf", "zim": "zamf"},
{"frob": "whoop", "zim": "zamlloou"}
]},
{"path": "./quxx", "moduleName": "example.net/quxx", "status": "lit",
"subtable": [
{"frob": "evenlonger", "zim": "boink",
"subsubtable": [
{"i hope": "you'll agree"}
]},
{"frob": "narf", "zim": "zamf"}
]}
]`)
nb := basicnode.Prototype.Any.NewBuilder()
Require(t, dagjson.Decode(nb, strings.NewReader(fixture)), ShouldEqual, nil)
n := nb.Build()
var buf bytes.Buffer
Wish(t, Marshal(n, &buf), ShouldEqual, nil)
Wish(t, buf.String(), ShouldEqual, fixture)
}