@@ -83,9 +83,9 @@
|
|||||||
// The idea behind a query path is to allow quick access to any element, or set
|
// The idea behind a query path is to allow quick access to any element, or set
|
||||||
// of elements within TOML document, with a single expression.
|
// of elements within TOML document, with a single expression.
|
||||||
//
|
//
|
||||||
// result := tree.Query("$.foo.bar.baz") // result is 'nil' if the path is not present
|
// result, err := tree.Query("$.foo.bar.baz")
|
||||||
//
|
//
|
||||||
// This is equivalent to:
|
// This is roughly equivalent to:
|
||||||
//
|
//
|
||||||
// next := tree.Get("foo")
|
// next := tree.Get("foo")
|
||||||
// if next != nil {
|
// if next != nil {
|
||||||
@@ -96,6 +96,11 @@
|
|||||||
// }
|
// }
|
||||||
// result := next
|
// result := next
|
||||||
//
|
//
|
||||||
|
// err is nil if any parsing exception occurs.
|
||||||
|
//
|
||||||
|
// If no node in the tree matches the query, result will simply contain an empty list of
|
||||||
|
// items.
|
||||||
|
//
|
||||||
// As illustrated above, the query path is much more efficient, especially since
|
// As illustrated above, the query path is much more efficient, especially since
|
||||||
// the structure of the TOML file can vary. Rather than making assumptions about
|
// the structure of the TOML file can vary. Rather than making assumptions about
|
||||||
// a document's structure, a query allows the programmer to make structured
|
// a document's structure, a query allows the programmer to make structured
|
||||||
|
|||||||
@@ -57,3 +57,14 @@ password = "mypassword"
|
|||||||
}
|
}
|
||||||
assertArrayContainsInAnyOrder(t, values, "pelletier", "mypassword")
|
assertArrayContainsInAnyOrder(t, values, "pelletier", "mypassword")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestQueryPathNotPresent(t *testing.T) {
|
||||||
|
config, _ := Load(`a = "hello"`)
|
||||||
|
results, err := config.Query("$.foo.bar")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("err should be nil. got %s instead", err)
|
||||||
|
}
|
||||||
|
if len(results.items) != 0 {
|
||||||
|
t.Fatalf("no items should be matched. %d matched instead", len(results.items))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user