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

			It("should succeed if path exists and is string", func() {
				v, err := tree.FindString(data, "string")
				Ω(err).ShouldNot(HaveOccurred())
				Ω(v).Should(Equal("asdf"))
			})
		})

		Context("tree.FindNum()", func() {
			It("should fail if tree.Find() fails", func() {
				v, err := tree.FindNum(data, "nonexistent")
				Ω(err).Should(HaveOccurred())
				Ω(v).Should(Equal(tree.Number(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)))
			})
Beispiel #2
0
// Returns a tree.Number-typed value found in the JSON data
// returned in the response, at `path`
func (r *Response) NumVal(path string) (tree.Number, error) {
	return tree.FindNum(r.Data, path)
}