printer_test.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. package check_test
  2. import (
  3. . "gopkg.in/check.v1"
  4. )
  5. var _ = Suite(&PrinterS{})
  6. type PrinterS struct{}
  7. func (s *PrinterS) TestCountSuite(c *C) {
  8. suitesRun += 1
  9. }
  10. var printTestFuncLine int
  11. func init() {
  12. printTestFuncLine = getMyLine() + 3
  13. }
  14. func printTestFunc() {
  15. println(1) // Comment1
  16. if 2 == 2 { // Comment2
  17. println(3) // Comment3
  18. }
  19. switch 5 {
  20. case 6: println(6) // Comment6
  21. println(7)
  22. }
  23. switch interface{}(9).(type) {// Comment9
  24. case int: println(10)
  25. println(11)
  26. }
  27. select {
  28. case <-(chan bool)(nil): println(14)
  29. println(15)
  30. default: println(16)
  31. println(17)
  32. }
  33. println(19,
  34. 20)
  35. _ = func() { println(21)
  36. println(22)
  37. }
  38. println(24, func() {
  39. println(25)
  40. })
  41. // Leading comment
  42. // with multiple lines.
  43. println(29) // Comment29
  44. }
  45. var printLineTests = []struct {
  46. line int
  47. output string
  48. }{
  49. {1, "println(1) // Comment1"},
  50. {2, "if 2 == 2 { // Comment2\n ...\n}"},
  51. {3, "println(3) // Comment3"},
  52. {5, "switch 5 {\n...\n}"},
  53. {6, "case 6:\n println(6) // Comment6\n ..."},
  54. {7, "println(7)"},
  55. {9, "switch interface{}(9).(type) { // Comment9\n...\n}"},
  56. {10, "case int:\n println(10)\n ..."},
  57. {14, "case <-(chan bool)(nil):\n println(14)\n ..."},
  58. {15, "println(15)"},
  59. {16, "default:\n println(16)\n ..."},
  60. {17, "println(17)"},
  61. {19, "println(19,\n 20)"},
  62. {20, "println(19,\n 20)"},
  63. {21, "_ = func() {\n println(21)\n println(22)\n}"},
  64. {22, "println(22)"},
  65. {24, "println(24, func() {\n println(25)\n})"},
  66. {25, "println(25)"},
  67. {26, "println(24, func() {\n println(25)\n})"},
  68. {29, "// Leading comment\n// with multiple lines.\nprintln(29) // Comment29"},
  69. }
  70. func (s *PrinterS) TestPrintLine(c *C) {
  71. for _, test := range printLineTests {
  72. output, err := PrintLine("printer_test.go", printTestFuncLine+test.line)
  73. c.Assert(err, IsNil)
  74. c.Assert(output, Equals, test.output)
  75. }
  76. }
  77. var indentTests = []struct {
  78. in, out string
  79. }{
  80. {"", ""},
  81. {"\n", "\n"},
  82. {"a", ">>>a"},
  83. {"a\n", ">>>a\n"},
  84. {"a\nb", ">>>a\n>>>b"},
  85. {" ", ">>> "},
  86. }
  87. func (s *PrinterS) TestIndent(c *C) {
  88. for _, test := range indentTests {
  89. out := Indent(test.in, ">>>")
  90. c.Assert(out, Equals, test.out)
  91. }
  92. }