-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes_test.go
More file actions
69 lines (62 loc) · 1.55 KB
/
Copy pathtypes_test.go
File metadata and controls
69 lines (62 loc) · 1.55 KB
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
package jsonc
import (
"encoding/json"
"testing"
)
func TestMapSliceBasics(t *testing.T) {
ms := MapSlice{
{Key: "first", Value: 1},
{Key: "second", Value: "two"},
{Key: "third", Value: true},
}
if len(ms) != 3 {
t.Errorf("len = %d, want 3", len(ms))
}
if ms[0].Key != "first" || ms[0].Value != 1 {
t.Errorf("ms[0] = %+v", ms[0])
}
if ms[2].Value != true {
t.Errorf("ms[2].Value = %v", ms[2].Value)
}
}
func TestMapItemKeyIsString(t *testing.T) {
// The point of typing MapItem.Key as string (rather than any like
// TOML/YAML) is that JSON only allows string keys. This test simply
// asserts the type at compile time.
var item MapItem
item.Key = "x"
_ = item.Key
}
func TestNumberAlias(t *testing.T) {
// jsonc.Number must be the same type as encoding/json.Number so values
// are interchangeable.
var n Number = "42"
var stdN json.Number = n
if stdN != "42" {
t.Errorf("alias broken: %q", stdN)
}
got, err := n.Int64()
if err != nil {
t.Fatal(err)
}
if got != 42 {
t.Errorf("Int64 = %d", got)
}
gotF, err := n.Float64()
if err != nil {
t.Fatal(err)
}
if gotF != 42.0 {
t.Errorf("Float64 = %v", gotF)
}
}
func TestMapKeyOrderConstants(t *testing.T) {
// The two constants must be distinct values; the iota order locks the
// default to MapKeyOrderLexicographic (the zero value).
if MapKeyOrderLexicographic == MapKeyOrderInsertion {
t.Error("MapKeyOrder constants collapsed")
}
if int(MapKeyOrderLexicographic) != 0 {
t.Errorf("MapKeyOrderLexicographic = %d, want 0 (zero value default)", MapKeyOrderLexicographic)
}
}