pointer_test.go 711 B

123456789101112131415161718192021222324252627282930313233
  1. package gstruct_test
  2. import (
  3. . "github.com/onsi/ginkgo"
  4. . "github.com/onsi/gomega"
  5. . "github.com/onsi/gomega/gstruct"
  6. )
  7. var _ = Describe("PointTo", func() {
  8. It("should fail when passed nil", func() {
  9. var p *struct{}
  10. Expect(p).Should(BeNil())
  11. })
  12. It("should succeed when passed non-nil pointer", func() {
  13. var s struct{}
  14. Expect(&s).Should(PointTo(Ignore()))
  15. })
  16. It("should unwrap the pointee value", func() {
  17. i := 1
  18. Expect(&i).Should(PointTo(Equal(1)))
  19. Expect(&i).ShouldNot(PointTo(Equal(2)))
  20. })
  21. It("should work with nested pointers", func() {
  22. i := 1
  23. ip := &i
  24. ipp := &ip
  25. Expect(ipp).Should(PointTo(PointTo(Equal(1))))
  26. Expect(ipp).ShouldNot(PointTo(PointTo(Equal(2))))
  27. })
  28. })