|
|
@ -1,7 +1,7 @@ |
|
|
|
package check_test |
|
|
|
package check_test |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
. "gopkg.in/check.v1" |
|
|
|
. "gopkg.in/check.v1" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
var _ = Suite(&PrinterS{}) |
|
|
|
var _ = Suite(&PrinterS{}) |
|
|
@ -9,96 +9,101 @@ var _ = Suite(&PrinterS{}) |
|
|
|
type PrinterS struct{} |
|
|
|
type PrinterS struct{} |
|
|
|
|
|
|
|
|
|
|
|
func (s *PrinterS) TestCountSuite(c *C) { |
|
|
|
func (s *PrinterS) TestCountSuite(c *C) { |
|
|
|
suitesRun += 1 |
|
|
|
suitesRun += 1 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var printTestFuncLine int |
|
|
|
var printTestFuncLine int |
|
|
|
|
|
|
|
|
|
|
|
func init() { |
|
|
|
func init() { |
|
|
|
printTestFuncLine = getMyLine() + 3 |
|
|
|
printTestFuncLine = getMyLine() + 3 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func printTestFunc() { |
|
|
|
func printTestFunc() { |
|
|
|
println(1) // Comment1
|
|
|
|
println(1) // Comment1
|
|
|
|
if 2 == 2 { // Comment2
|
|
|
|
if 2 == 2 { // Comment2
|
|
|
|
println(3) // Comment3
|
|
|
|
println(3) // Comment3
|
|
|
|
} |
|
|
|
} |
|
|
|
switch 5 { |
|
|
|
switch 5 { |
|
|
|
case 6: println(6) // Comment6
|
|
|
|
case 6: |
|
|
|
println(7) |
|
|
|
println(6) // Comment6
|
|
|
|
} |
|
|
|
println(7) |
|
|
|
switch interface{}(9).(type) {// Comment9
|
|
|
|
} |
|
|
|
case int: println(10) |
|
|
|
switch interface{}(9).(type) { // Comment9
|
|
|
|
println(11) |
|
|
|
case int: |
|
|
|
} |
|
|
|
println(10) |
|
|
|
select { |
|
|
|
println(11) |
|
|
|
case <-(chan bool)(nil): println(14) |
|
|
|
} |
|
|
|
println(15) |
|
|
|
select { |
|
|
|
default: println(16) |
|
|
|
case <-(chan bool)(nil): |
|
|
|
println(17) |
|
|
|
println(14) |
|
|
|
} |
|
|
|
println(15) |
|
|
|
println(19, |
|
|
|
default: |
|
|
|
20) |
|
|
|
println(16) |
|
|
|
_ = func() { println(21) |
|
|
|
println(17) |
|
|
|
println(22) |
|
|
|
} |
|
|
|
} |
|
|
|
println(19, |
|
|
|
println(24, func() { |
|
|
|
20) |
|
|
|
println(25) |
|
|
|
_ = func() { |
|
|
|
}) |
|
|
|
println(21) |
|
|
|
// Leading comment
|
|
|
|
println(22) |
|
|
|
// with multiple lines.
|
|
|
|
} |
|
|
|
println(29) // Comment29
|
|
|
|
println(24, func() { |
|
|
|
|
|
|
|
println(25) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
// Leading comment
|
|
|
|
|
|
|
|
// with multiple lines.
|
|
|
|
|
|
|
|
println(29) // Comment29
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var printLineTests = []struct { |
|
|
|
var printLineTests = []struct { |
|
|
|
line int |
|
|
|
line int |
|
|
|
output string |
|
|
|
output string |
|
|
|
}{ |
|
|
|
}{ |
|
|
|
{1, "println(1) // Comment1"}, |
|
|
|
{1, "println(1) // Comment1"}, |
|
|
|
{2, "if 2 == 2 { // Comment2\n ...\n}"}, |
|
|
|
{2, "if 2 == 2 { // Comment2\n ...\n}"}, |
|
|
|
{3, "println(3) // Comment3"}, |
|
|
|
{3, "println(3) // Comment3"}, |
|
|
|
{5, "switch 5 {\n...\n}"}, |
|
|
|
{5, "switch 5 {\n...\n}"}, |
|
|
|
{6, "case 6:\n println(6) // Comment6\n ..."}, |
|
|
|
{6, "case 6:\n println(6) // Comment6\n ..."}, |
|
|
|
{7, "println(7)"}, |
|
|
|
{7, "println(7)"}, |
|
|
|
{9, "switch interface{}(9).(type) { // Comment9\n...\n}"}, |
|
|
|
{9, "switch interface{}(9).(type) { // Comment9\n...\n}"}, |
|
|
|
{10, "case int:\n println(10)\n ..."}, |
|
|
|
{10, "case int:\n println(10)\n ..."}, |
|
|
|
{14, "case <-(chan bool)(nil):\n println(14)\n ..."}, |
|
|
|
{14, "case <-(chan bool)(nil):\n println(14)\n ..."}, |
|
|
|
{15, "println(15)"}, |
|
|
|
{15, "println(15)"}, |
|
|
|
{16, "default:\n println(16)\n ..."}, |
|
|
|
{16, "default:\n println(16)\n ..."}, |
|
|
|
{17, "println(17)"}, |
|
|
|
{17, "println(17)"}, |
|
|
|
{19, "println(19,\n 20)"}, |
|
|
|
{19, "println(19,\n 20)"}, |
|
|
|
{20, "println(19,\n 20)"}, |
|
|
|
{20, "println(19,\n 20)"}, |
|
|
|
{21, "_ = func() {\n println(21)\n println(22)\n}"}, |
|
|
|
{21, "_ = func() {\n println(21)\n println(22)\n}"}, |
|
|
|
{22, "println(22)"}, |
|
|
|
{22, "println(22)"}, |
|
|
|
{24, "println(24, func() {\n println(25)\n})"}, |
|
|
|
{24, "println(24, func() {\n println(25)\n})"}, |
|
|
|
{25, "println(25)"}, |
|
|
|
{25, "println(25)"}, |
|
|
|
{26, "println(24, func() {\n println(25)\n})"}, |
|
|
|
{26, "println(24, func() {\n println(25)\n})"}, |
|
|
|
{29, "// Leading comment\n// with multiple lines.\nprintln(29) // Comment29"}, |
|
|
|
{29, "// Leading comment\n// with multiple lines.\nprintln(29) // Comment29"}, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (s *PrinterS) TestPrintLine(c *C) { |
|
|
|
func (s *PrinterS) TestPrintLine(c *C) { |
|
|
|
for _, test := range printLineTests { |
|
|
|
for _, test := range printLineTests { |
|
|
|
output, err := PrintLine("printer_test.go", printTestFuncLine+test.line) |
|
|
|
output, err := PrintLine("printer_test.go", printTestFuncLine+test.line) |
|
|
|
c.Assert(err, IsNil) |
|
|
|
c.Assert(err, IsNil) |
|
|
|
c.Assert(output, Equals, test.output) |
|
|
|
c.Assert(output, Equals, test.output) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var indentTests = []struct { |
|
|
|
var indentTests = []struct { |
|
|
|
in, out string |
|
|
|
in, out string |
|
|
|
}{ |
|
|
|
}{ |
|
|
|
{"", ""}, |
|
|
|
{"", ""}, |
|
|
|
{"\n", "\n"}, |
|
|
|
{"\n", "\n"}, |
|
|
|
{"a", ">>>a"}, |
|
|
|
{"a", ">>>a"}, |
|
|
|
{"a\n", ">>>a\n"}, |
|
|
|
{"a\n", ">>>a\n"}, |
|
|
|
{"a\nb", ">>>a\n>>>b"}, |
|
|
|
{"a\nb", ">>>a\n>>>b"}, |
|
|
|
{" ", ">>> "}, |
|
|
|
{" ", ">>> "}, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (s *PrinterS) TestIndent(c *C) { |
|
|
|
func (s *PrinterS) TestIndent(c *C) { |
|
|
|
for _, test := range indentTests { |
|
|
|
for _, test := range indentTests { |
|
|
|
out := Indent(test.in, ">>>") |
|
|
|
out := Indent(test.in, ">>>") |
|
|
|
c.Assert(out, Equals, test.out) |
|
|
|
c.Assert(out, Equals, test.out) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|