composite_test.go 895 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Copyright (c) 2016 Arista Networks, Inc.
  2. // Use of this source code is governed by the Apache License 2.0
  3. // that can be found in the COPYING file.
  4. package key_test
  5. import (
  6. "testing"
  7. . "notabug.org/themusicgod1/goarista/key"
  8. "notabug.org/themusicgod1/goarista/test"
  9. )
  10. type unhashable struct {
  11. f func()
  12. u uintptr
  13. }
  14. func TestBadComposite(t *testing.T) {
  15. test.ShouldPanicWith(t, "use of unhashable type in a map", func() {
  16. m := map[interface{}]struct{}{
  17. unhashable{func() {}, 0x42}: {},
  18. }
  19. // Use Key here to make sure init() is called.
  20. if _, ok := m[New("foo")]; ok {
  21. t.Fatal("WTF")
  22. }
  23. })
  24. test.ShouldPanicWith(t, "use of uncomparable type on the lhs of ==", func() {
  25. var a interface{}
  26. var b interface{}
  27. a = unhashable{func() {}, 0x42}
  28. b = unhashable{func() {}, 0x42}
  29. // Use Key here to make sure init() is called.
  30. if a == b {
  31. t.Fatal("WTF")
  32. }
  33. })
  34. }