-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathchunker_test.go
83 lines (79 loc) · 1.97 KB
/
chunker_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
// Copyright 2023 Sneller, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package ion
import (
"fmt"
"io"
"testing"
)
func TestPathLess(t *testing.T) {
ord := [][]Symbol{
{0},
{0, 1},
{0, 1, 1},
{0, 2},
{0, 2, 1},
{0, 2, 2},
{0, 2, 3},
{0, 3},
{1, 0},
{2},
}
for i := range ord[:len(ord)-1] {
tail := ord[i+1:]
if pathCompare(ord[i], ord[i]) != 0 {
t.Errorf("%v less than itself?", ord)
}
for j := range tail {
if pathCompare(ord[i], tail[j]) >= 0 {
t.Errorf("%v not less than %v?", ord[i], tail[j])
}
if pathCompare(tail[j], ord[i]) < 0 {
t.Errorf("%v < %v ?", tail[j], ord[i])
}
}
}
}
func TestUniqueFields(t *testing.T) {
fields := []Field{
{Datum: Uint(1000)},
{Datum: String("foobarbaz")},
{Datum: Null},
{Datum: Empty}, // set below
}
fields2 := []Field{
{Datum: String("inner")},
{Datum: Float(3.5)},
}
cn := Chunker{
W: io.Discard,
Align: 2048,
}
// test that infinite unique fields
// do not cause the symbol table to explode
for i := 0; i < 1000; i++ {
fields[0].Label = fmt.Sprintf("f0_%d", i)
fields[1].Label = fmt.Sprintf("f1_%d", i)
fields[2].Label = fmt.Sprintf("f2_%d", i)
fields[3].Label = fmt.Sprintf("f3_%d", i)
fields2[0].Label = fmt.Sprintf("f0_%d", i-1)
fields2[1].Label = fmt.Sprintf("f1_%d", i+1)
fields[3].Datum = NewStruct(nil, fields2).Datum()
NewStruct(nil, fields).Encode(&cn.Buffer, &cn.Symbols)
err := cn.Commit()
if err != nil {
t.Fatal(err)
}
}
}