Пример #1
0
				Ω(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)))
			})
		})
Пример #2
0
			str, err := response.StringVal("number")
			Expect(err).Should(HaveOccurred())
			Expect(str).Should(Equal(""))
		})
		It("should succeed when specified path points to a string", func() {
			str, err := response.StringVal("string")
			Expect(err).ShouldNot(HaveOccurred())
			Expect(str).Should(Equal("asdf"))
		})
	})

	Context("Response.NumVal()", func() {
		It("should fail when specified path does not point to a number", func() {
			num, err := response.NumVal("string")
			Expect(err).Should(HaveOccurred())
			Expect(num).Should(Equal(tree.Number(0)))
		})
		It("should succeed when specified path points to a number", func() {
			num, err := response.NumVal("number")
			Expect(err).ShouldNot(HaveOccurred())
			Expect(num).Should(Equal(tree.Number(1234)))
		})
	})

	Context("Response.BoolVal()", func() {
		It("should fail when specified path does not point to a boolean", func() {
			b, err := response.BoolVal("number")
			Expect(err).Should(HaveOccurred())
			Expect(b).Should(Equal(false))
		})
		It("should succeed when specified path points to a boolean", func() {