pretty_test.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 test_test
  5. import (
  6. "fmt"
  7. "testing"
  8. "unsafe"
  9. . "notabug.org/themusicgod1/goarista/test"
  10. )
  11. type alias int
  12. type privateByteSlice struct {
  13. exportme []byte
  14. }
  15. func TestPrettyPrint(t *testing.T) {
  16. // This test doesn't need to cover all the types of input as a number of
  17. // them are covered by other tests in this package.
  18. ch := make(chan int, 42)
  19. testcases := []struct {
  20. input interface{}
  21. pretty string
  22. }{
  23. {true, "true"},
  24. {(chan int)(nil), "(chan int)(nil)"},
  25. {ch, fmt.Sprintf("(chan int)(%p)[42]", ch)},
  26. {func() {}, "func(...)"},
  27. {unsafe.Pointer(nil), "(unsafe.Pointer)(nil)"},
  28. {unsafe.Pointer(t), fmt.Sprintf("(unsafe.Pointer)(%p)", t)},
  29. {[]byte(nil), `[]byte(nil)`},
  30. {[]byte{42, 0, 42}, `[]byte("*\x00*")`},
  31. {[]int{42, 51}, "[]int{42, 51}"},
  32. {[2]int{42, 51}, "[2]int{42, 51}"},
  33. {[2]byte{42, 51}, "[2]uint8{42, 51}"}, // Yeah, in Go `byte' is really just `uint8'.
  34. {alias(42), "alias(42)"},
  35. {privateByteSlice{[]byte("a")}, `test_test.privateByteSlice{exportme:[]byte("a")}`},
  36. }
  37. for i, tcase := range testcases {
  38. actual := PrettyPrint(tcase.input)
  39. if actual != tcase.pretty {
  40. t.Errorf("#%d: Wanted %q but got %q", i, actual, tcase.pretty)
  41. }
  42. }
  43. }