Update documentation for Query Fix #54
diff --git a/doc.go b/doc.go index 23c125a..c8c9add 100644 --- a/doc.go +++ b/doc.go
@@ -83,9 +83,9 @@ // 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. // -// 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") // if next != nil { @@ -96,6 +96,11 @@ // } // 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 // 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
diff --git a/query_test.go b/query_test.go index 81818ba..9bf7bad 100644 --- a/query_test.go +++ b/query_test.go
@@ -57,3 +57,14 @@ } 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)) + } +}