Return an error instead of panicking
This commit is contained in:
+11
-11
@@ -25,12 +25,12 @@ func TestCreateSubTree(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSimpleKV(t *testing.T) {
|
||||
tree := Load("a = 42")
|
||||
tree, _ := Load("a = 42")
|
||||
assertTree(t, tree, map[string]interface{}{
|
||||
"a": int64(42),
|
||||
})
|
||||
|
||||
tree = Load("a = 42\nb = 21")
|
||||
tree, _ = Load("a = 42\nb = 21")
|
||||
assertTree(t, tree, map[string]interface{}{
|
||||
"a": int64(42),
|
||||
"b": int64(21),
|
||||
@@ -38,7 +38,7 @@ func TestSimpleKV(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSimpleNumbers(t *testing.T) {
|
||||
tree := Load("a = +42\nb = -21\nc = +4.2\nd = -2.1")
|
||||
tree, _ := Load("a = +42\nb = -21\nc = +4.2\nd = -2.1")
|
||||
assertTree(t, tree, map[string]interface{}{
|
||||
"a": int64(42),
|
||||
"b": int64(-21),
|
||||
@@ -48,21 +48,21 @@ func TestSimpleNumbers(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSimpleDate(t *testing.T) {
|
||||
tree := Load("a = 1979-05-27T07:32:00Z")
|
||||
tree, _ := Load("a = 1979-05-27T07:32:00Z")
|
||||
assertTree(t, tree, map[string]interface{}{
|
||||
"a": time.Date(1979, time.May, 27, 7, 32, 0, 0, time.UTC),
|
||||
})
|
||||
}
|
||||
|
||||
func TestSimpleString(t *testing.T) {
|
||||
tree := Load("a = \"hello world\"")
|
||||
tree, _ := Load("a = \"hello world\"")
|
||||
assertTree(t, tree, map[string]interface{}{
|
||||
"a": "hello world",
|
||||
})
|
||||
}
|
||||
|
||||
func TestBools(t *testing.T) {
|
||||
tree := Load("a = true\nb = false")
|
||||
tree, _ := Load("a = true\nb = false")
|
||||
assertTree(t, tree, map[string]interface{}{
|
||||
"a": true,
|
||||
"b": false,
|
||||
@@ -70,33 +70,33 @@ func TestBools(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNestedKeys(t *testing.T) {
|
||||
tree := Load("[a.b.c]\nd = 42")
|
||||
tree, _ := Load("[a.b.c]\nd = 42")
|
||||
assertTree(t, tree, map[string]interface{}{
|
||||
"a.b.c.d": int64(42),
|
||||
})
|
||||
}
|
||||
|
||||
func TestArraySimple(t *testing.T) {
|
||||
tree := Load("a = [42, 21, 10]")
|
||||
tree, _ := Load("a = [42, 21, 10]")
|
||||
assertTree(t, tree, map[string]interface{}{
|
||||
"a": []int64{int64(42), int64(21), int64(10)},
|
||||
})
|
||||
|
||||
tree = Load("a = [42, 21, 10,]")
|
||||
tree, _ = Load("a = [42, 21, 10,]")
|
||||
assertTree(t, tree, map[string]interface{}{
|
||||
"a": []int64{int64(42), int64(21), int64(10)},
|
||||
})
|
||||
}
|
||||
|
||||
func TestArrayMultiline(t *testing.T) {
|
||||
tree := Load("a = [42,\n21, 10,]")
|
||||
tree, _ := Load("a = [42,\n21, 10,]")
|
||||
assertTree(t, tree, map[string]interface{}{
|
||||
"a": []int64{int64(42), int64(21), int64(10)},
|
||||
})
|
||||
}
|
||||
|
||||
func TestArrayNested(t *testing.T) {
|
||||
tree := Load("a = [[42, 21], [10]]")
|
||||
tree, _ := Load("a = [[42, 21], [10]]")
|
||||
assertTree(t, tree, map[string]interface{}{
|
||||
"a": [][]int64{[]int64{int64(42), int64(21)}, []int64{int64(10)}},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user