launchpad.net/gocheck@v0.0.0-20140225173054-000000000087/printer_test.go (about)

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