Example #1
0
			It("should fail if path is not a number", func() {
				v, err := tree.FindNum(data, "string")
				Ω(err).Should(HaveOccurred())
				Ω(v).Should(Equal(tree.Number(0)))
			})

			It("should succeed if path exists and is numeric", func() {
				v, err := tree.FindNum(data, "number")
				Ω(err).ShouldNot(HaveOccurred())
				Ω(v).Should(Equal(tree.Number(1234)))
			})
		})

		Context("tree.FindBool()", func() {
			It("should fail if tree.Find() fails", func() {
				v, err := tree.FindBool(data, "nonexistent")
				Ω(err).Should(HaveOccurred())
				Ω(v).Should(Equal(false))
			})

			It("should fail if path is not a bool", func() {
				v, err := tree.FindBool(data, "number")
				Ω(err).Should(HaveOccurred())
				Ω(v).Should(Equal(false))
			})

			It("should succeed if path exists and is boolean", func() {
				v, err := tree.FindBool(data, "boolean")
				Ω(err).ShouldNot(HaveOccurred())
				Ω(v).Should(Equal(true))
			})
Example #2
0
// Returns a bool-typed value found in the JSON data
// returned in the response, at `path`
func (r *Response) BoolVal(path string) (bool, error) {
	return tree.FindBool(r.Data, path)
}