From 69cefc1e3b58604b44499301dcc4202c327a6e4c Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Wed, 4 Nov 2009 16:50:13 -0800 Subject: rename testfiles from .go -> .orig so that they won't be picked up by gofmt (they should not be modified) or godoc (testdata should not be considered a potential package directory) R=rsc http://go/go-review/1018045 --- src/pkg/go/printer/printer_test.go | 16 +- src/pkg/go/printer/testdata/comments.go | 236 ------------- src/pkg/go/printer/testdata/comments.input | 236 +++++++++++++ src/pkg/go/printer/testdata/declarations.go | 461 ------------------------- src/pkg/go/printer/testdata/declarations.input | 461 +++++++++++++++++++++++++ src/pkg/go/printer/testdata/empty.go | 5 - src/pkg/go/printer/testdata/empty.input | 5 + src/pkg/go/printer/testdata/expressions.go | 212 ------------ src/pkg/go/printer/testdata/expressions.input | 212 ++++++++++++ src/pkg/go/printer/testdata/linebreaks.go | 222 ------------ src/pkg/go/printer/testdata/linebreaks.input | 222 ++++++++++++ src/pkg/go/printer/testdata/statements.go | 201 ----------- src/pkg/go/printer/testdata/statements.input | 201 +++++++++++ 13 files changed, 1345 insertions(+), 1345 deletions(-) delete mode 100644 src/pkg/go/printer/testdata/comments.go create mode 100644 src/pkg/go/printer/testdata/comments.input delete mode 100644 src/pkg/go/printer/testdata/declarations.go create mode 100644 src/pkg/go/printer/testdata/declarations.input delete mode 100644 src/pkg/go/printer/testdata/empty.go create mode 100644 src/pkg/go/printer/testdata/empty.input delete mode 100644 src/pkg/go/printer/testdata/expressions.go create mode 100644 src/pkg/go/printer/testdata/expressions.input delete mode 100644 src/pkg/go/printer/testdata/linebreaks.go create mode 100644 src/pkg/go/printer/testdata/linebreaks.input delete mode 100644 src/pkg/go/printer/testdata/statements.go create mode 100644 src/pkg/go/printer/testdata/statements.input (limited to 'src') diff --git a/src/pkg/go/printer/printer_test.go b/src/pkg/go/printer/printer_test.go index 1941f86ef..49bd9741e 100644 --- a/src/pkg/go/printer/printer_test.go +++ b/src/pkg/go/printer/printer_test.go @@ -111,14 +111,14 @@ type entry struct { // Use gotest -update to create/update the respective golden files. var data = []entry{ - entry{ "empty.go", "empty.golden", 0 }, - entry{ "comments.go", "comments.golden", 0 }, - entry{ "comments.go", "comments.x", export }, - entry{ "linebreaks.go", "linebreaks.golden", 0 }, - entry{ "expressions.go", "expressions.golden", 0 }, - entry{ "expressions.go", "expressions.raw", rawFormat }, - entry{ "declarations.go", "declarations.golden", 0 }, - entry{ "statements.go", "statements.golden", 0 }, + entry{ "empty.input", "empty.golden", 0 }, + entry{ "comments.input", "comments.golden", 0 }, + entry{ "comments.input", "comments.x", export }, + entry{ "linebreaks.input", "linebreaks.golden", 0 }, + entry{ "expressions.input", "expressions.golden", 0 }, + entry{ "expressions.input", "expressions.raw", rawFormat }, + entry{ "declarations.input", "declarations.golden", 0 }, + entry{ "statements.input", "statements.golden", 0 }, } diff --git a/src/pkg/go/printer/testdata/comments.go b/src/pkg/go/printer/testdata/comments.go deleted file mode 100644 index 05399a3c6..000000000 --- a/src/pkg/go/printer/testdata/comments.go +++ /dev/null @@ -1,236 +0,0 @@ -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// This is a package for testing comment placement by go/printer. -// -package main - -import "fmt" // fmt - -const c0 = 0; // zero -const ( - c1 = iota; // c1 - c2; // c2 -) - - -// The SZ struct; it is empty. -type SZ struct {} - -// The S0 struct; no field is exported. -type S0 struct { - int; - x, y, z int; // 3 unexported fields -} - -// The S1 struct; some fields are not exported. -type S1 struct { - S0; - A, B, C float; // 3 exported fields - D, b, c int; // 2 unexported fields -} - -// The S2 struct; all fields are exported. -type S2 struct { - S1; - A, B, C float; // 3 exported fields -} - -// The IZ interface; it is empty. -type SZ interface {} - -// The I0 interface; no method is exported. -type I0 interface { - f(x int) int; // unexported method -} - -// The I1 interface; some methods are not exported. -type I1 interface { - I0; - F(x float) float; // exported methods - g(x int) int; // unexported method -} - -// The I2 interface; all methods are exported. -type I2 interface { - I0; - F(x float) float; // exported method - G(x float) float; // exported method -} - -// This comment group should be separated -// with a newline from the next comment -// group. - -// This comment should NOT be associated with the next declaration. - -var x int; // x -var () - - -// This comment SHOULD be associated with the next declaration. -func f0() { - const pi = 3.14; // pi - var s1 struct {} /* an empty struct */ /* foo */ - // a struct constructor - // -------------------- - var s2 struct {} = struct {}{}; - x := pi; -} -// -// NO SPACE HERE -// -func f1() { - f0(); - /* 1 */ - // 2 - /* 3 */ - /* 4 */ - f0(); -} - - -func _() { - // this comment should be properly indented -} - - -func abs(x int) int { - if x < 0 { // the tab printed before this comment's // must not affect the remaining lines - return -x; // this statement should be properly indented - } - return x; -} - - -func typeswitch(x interface{}) { - switch v := x.(type) { - case bool, int, float: - case string: - default: - } - - switch x.(type) { - } - - switch v0, ok := x.(int); v := x.(type) { - } - - switch v0, ok := x.(int); x.(type) { - case bool, int, float: - // this comment should be indented - case string: - default: - // this comment should be indented - } - // this comment should not be indented -} - -func _() { - /* freestanding comment - aligned line - aligned line - */ -} - -func _() { - /* freestanding comment - aligned line - aligned line - */ -} - -func _() { - /* freestanding comment - aligned line - aligned line */ -} - -func _() { - /* freestanding comment - aligned line - aligned line - */ -} - -func _() { - /* freestanding comment - aligned line - aligned line - */ -} - -func _() { - /* freestanding comment - aligned line - aligned line */ -} - - -/* - * line - * of - * stars - */ - -/* another line - * of - * stars */ - -/* and another line - * of - * stars */ - -/* -aligned in middle -here - not here -*/ - -/* -blank line in middle: - -with no leading spaces on blank line. -*/ - -func _() { - /* - * line - * of - * stars - */ - - /* - aligned in middle - here - not here - */ - - /* - blank line in middle: - - with no leading spaces on blank line. -*/ -} - - -// Some interesting interspersed comments -func _(/* this */x/* is *//* an */ int) { -} - - -// Line comments with tabs -func _() { -var finput *bufio.Reader; // input file -var stderr *bufio.Writer; -var ftable *bufio.Writer; // y.go file -var foutput *bufio.Writer; // y.output file - -var oflag string; // -o [y.go] - y.go file -var vflag string; // -v [y.output] - y.output file -var lflag bool; // -l - disable line directives -} - - -// This comment is the last entry in this file. It must be printed. diff --git a/src/pkg/go/printer/testdata/comments.input b/src/pkg/go/printer/testdata/comments.input new file mode 100644 index 000000000..05399a3c6 --- /dev/null +++ b/src/pkg/go/printer/testdata/comments.input @@ -0,0 +1,236 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// This is a package for testing comment placement by go/printer. +// +package main + +import "fmt" // fmt + +const c0 = 0; // zero +const ( + c1 = iota; // c1 + c2; // c2 +) + + +// The SZ struct; it is empty. +type SZ struct {} + +// The S0 struct; no field is exported. +type S0 struct { + int; + x, y, z int; // 3 unexported fields +} + +// The S1 struct; some fields are not exported. +type S1 struct { + S0; + A, B, C float; // 3 exported fields + D, b, c int; // 2 unexported fields +} + +// The S2 struct; all fields are exported. +type S2 struct { + S1; + A, B, C float; // 3 exported fields +} + +// The IZ interface; it is empty. +type SZ interface {} + +// The I0 interface; no method is exported. +type I0 interface { + f(x int) int; // unexported method +} + +// The I1 interface; some methods are not exported. +type I1 interface { + I0; + F(x float) float; // exported methods + g(x int) int; // unexported method +} + +// The I2 interface; all methods are exported. +type I2 interface { + I0; + F(x float) float; // exported method + G(x float) float; // exported method +} + +// This comment group should be separated +// with a newline from the next comment +// group. + +// This comment should NOT be associated with the next declaration. + +var x int; // x +var () + + +// This comment SHOULD be associated with the next declaration. +func f0() { + const pi = 3.14; // pi + var s1 struct {} /* an empty struct */ /* foo */ + // a struct constructor + // -------------------- + var s2 struct {} = struct {}{}; + x := pi; +} +// +// NO SPACE HERE +// +func f1() { + f0(); + /* 1 */ + // 2 + /* 3 */ + /* 4 */ + f0(); +} + + +func _() { + // this comment should be properly indented +} + + +func abs(x int) int { + if x < 0 { // the tab printed before this comment's // must not affect the remaining lines + return -x; // this statement should be properly indented + } + return x; +} + + +func typeswitch(x interface{}) { + switch v := x.(type) { + case bool, int, float: + case string: + default: + } + + switch x.(type) { + } + + switch v0, ok := x.(int); v := x.(type) { + } + + switch v0, ok := x.(int); x.(type) { + case bool, int, float: + // this comment should be indented + case string: + default: + // this comment should be indented + } + // this comment should not be indented +} + +func _() { + /* freestanding comment + aligned line + aligned line + */ +} + +func _() { + /* freestanding comment + aligned line + aligned line + */ +} + +func _() { + /* freestanding comment + aligned line + aligned line */ +} + +func _() { + /* freestanding comment + aligned line + aligned line + */ +} + +func _() { + /* freestanding comment + aligned line + aligned line + */ +} + +func _() { + /* freestanding comment + aligned line + aligned line */ +} + + +/* + * line + * of + * stars + */ + +/* another line + * of + * stars */ + +/* and another line + * of + * stars */ + +/* +aligned in middle +here + not here +*/ + +/* +blank line in middle: + +with no leading spaces on blank line. +*/ + +func _() { + /* + * line + * of + * stars + */ + + /* + aligned in middle + here + not here + */ + + /* + blank line in middle: + + with no leading spaces on blank line. +*/ +} + + +// Some interesting interspersed comments +func _(/* this */x/* is *//* an */ int) { +} + + +// Line comments with tabs +func _() { +var finput *bufio.Reader; // input file +var stderr *bufio.Writer; +var ftable *bufio.Writer; // y.go file +var foutput *bufio.Writer; // y.output file + +var oflag string; // -o [y.go] - y.go file +var vflag string; // -v [y.output] - y.output file +var lflag bool; // -l - disable line directives +} + + +// This comment is the last entry in this file. It must be printed. diff --git a/src/pkg/go/printer/testdata/declarations.go b/src/pkg/go/printer/testdata/declarations.go deleted file mode 100644 index c54a2ce22..000000000 --- a/src/pkg/go/printer/testdata/declarations.go +++ /dev/null @@ -1,461 +0,0 @@ -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package imports - -import "io" - -import ( - _ "io" -) - -import _ "io" - -import ( - "io"; - "io"; - "io"; -) - -import ( - "io"; - aLongRename "io"; - - b "io"; - c "i" "o"; -) - -// no newlines between consecutive single imports, but -// respect extra line breaks in the source (at most one empty line) -import _ "io" -import _ "io" -import _ "io" - -import _ "os" -import _ "os" -import _ "os" - - -import _ "fmt" -import _ "fmt" -import _ "fmt" - - -// at least one empty line between declarations of different kind -import _ "io" -var _ int; - - -func _() { - // the following decls need a semicolon at the end - type _ int; - type _ *int; - type _ []int; - type _ map[string]int; - type _ chan int; - type _ func() int; - - var _ int; - var _ *int; - var _ []int; - var _ map[string]int; - var _ chan int; - var _ func() int; - - // the following decls don't need a semicolon at the end - type _ struct{} - type _ *struct{} - type _ []struct{} - type _ map[string]struct{} - type _ chan struct{} - type _ func() struct{} - - type _ interface{} - type _ *interface{} - type _ []interface{} - type _ map[string]interface{} - type _ chan interface{} - type _ func() interface{} - - var _ struct{} - var _ *struct{} - var _ []struct{} - var _ map[string]struct{} - var _ chan struct{} - var _ func() struct{} - - var _ interface{} - var _ *interface{} - var _ []interface{} - var _ map[string]interface{} - var _ chan interface{} - var _ func() interface{} -} - - -// don't lose blank lines in grouped declarations -const ( - _ int = 0; - _ float = 1; - - _ string = "foo"; - - _ = iota; - _; - - // a comment - _; - - _; -) - - -type ( - _ int; - _ struct {}; - - _ interface{}; - - // a comment - _ map[string]int; -) - - -var ( - _ int = 0; - _ float = 1; - - _ string = "foo"; - - _ bool; - - // a comment - _ bool; -) - - -// don't lose blank lines in this struct -type _ struct { - String struct { - Str, Len int; - }; - Slice struct { - Array, Len, Cap int; - }; - Eface struct { - Typ, Ptr int; - }; - - UncommonType struct { - Name, PkgPath int; - }; - CommonType struct { - Size, Hash, Alg, Align, FieldAlign, String, UncommonType int; - }; - Type struct { - Typ, Ptr int; - }; - StructField struct { - Name, PkgPath, Typ, Tag, Offset int; - }; - StructType struct { - Fields int; - }; - PtrType struct { - Elem int; - }; - SliceType struct { - Elem int; - }; - ArrayType struct { - Elem, Len int; - }; - - Stktop struct { - Stackguard, Stackbase, Gobuf int; - }; - Gobuf struct { - Sp, Pc, G int; - }; - G struct { - Stackbase, Sched, Status, Alllink int; - }; -} - - -// no tabs for single or ungrouped decls -func _() { - const xxxxxx = 0; - type x int; - var xxx int; - var yyyy float = 3.14; - var zzzzz = "bar"; - - const ( - xxxxxx = 0; - ) - type ( - x int; - ) - var ( - xxx int; - ) - var ( - yyyy float = 3.14; - ) - var ( - zzzzz = "bar"; - ) -} - -// tabs for multiple or grouped decls -func _() { - // no entry has a type - const ( - zzzzzz = 1; - z = 2; - zzz = 3; - ) - // some entries have a type - const ( - xxxxxx = 1; - x = 2; - xxx = 3; - yyyyyyyy float = iota; - yyyy = "bar"; - yyy; - yy = 2; - ) -} - -func _() { - // no entry has a type - var ( - zzzzzz = 1; - z = 2; - zzz = 3; - ) - // no entry has a value - var ( - _ int; - _ float; - _ string; - - _ int; // comment - _ float; // comment - _ string; // comment - ) - // some entries have a type - var ( - xxxxxx int; - x float; - xxx string; - yyyyyyyy int = 1234; - y float = 3.14; - yyyy = "bar"; - yyy string = "foo"; - ) - // mixed entries - all comments should be aligned - var ( - a, b, c int; - x = 10; - d int; // comment - y = 20; // comment - f, ff, fff, ffff int = 0, 1, 2, 3; // comment - ) - // respect original line breaks - var _ = []T { - T{0x20, "Telugu"} - }; - var _ = []T { - // respect original line breaks - T{0x20, "Telugu"} - }; -} - -func _() { - type ( - xxxxxx int; - x float; - xxx string; - xxxxx []x; - xx struct{}; - xxxxxxx struct { - _, _ int; - _ float; - }; - xxxx chan<- string; - ) -} - - -// formatting of structs -type _ struct{} - -type _ struct{ /* this comment should be visible */ } - -type _ struct{ - // this comment should be visible and properly indented -} - -type _ struct { // this comment must not change indentation - f int; - f, ff, fff, ffff int; -} - -type _ struct { - string; -} - -type _ struct { - string; // comment -} - -type _ struct { - string "tag" -} - -type _ struct { - string "tag" // comment -} - -type _ struct { - f int; -} - -type _ struct { - f int; // comment -} - -type _ struct { - f int "tag"; -} - -type _ struct { - f int "tag"; // comment -} - -type _ struct { - bool; - a, b, c int; - int "tag"; - ES; // comment - float "tag"; // comment - f int; // comment - f, ff, fff, ffff int; // comment - g float "tag"; - h float "tag"; // comment -} - - -// difficult cases -type _ struct { - bool; // comment - text []byte; // comment -} - - - -// formatting of interfaces -type EI interface{} - -type _ interface { - EI; -} - -type _ interface { - f(); - fffff(); -} - -type _ interface { - EI; - f(); - fffffg(); -} - -type _ interface { // this comment must not change indentation - EI; // here's a comment - f(); // no blank between identifier and () - fffff(); // no blank between identifier and () - gggggggggggg(x, y, z int) (); // hurray -} - -// formatting of variable declarations -func _() { - type day struct { n int; short, long string }; - var ( - Sunday = day{ 0, "SUN", "Sunday" }; - Monday = day{ 1, "MON", "Monday" }; - Tuesday = day{ 2, "TUE", "Tuesday" }; - Wednesday = day{ 3, "WED", "Wednesday" }; - Thursday = day{ 4, "THU", "Thursday" }; - Friday = day{ 5, "FRI", "Friday" }; - Saturday = day{ 6, "SAT", "Saturday" }; - ) -} - - -func _() { - var Universe = Scope { - Names: map[string]*Ident { - // basic types - "bool": nil, - "byte": nil, - "int8": nil, - "int16": nil, - "int32": nil, - "int64": nil, - "uint8": nil, - "uint16": nil, - "uint32": nil, - "uint64": nil, - "float32": nil, - "float64": nil, - "string": nil, - - // convenience types - "int": nil, - "uint": nil, - "uintptr": nil, - "float": nil, - - // constants - "false": nil, - "true": nil, - "iota": nil, - "nil": nil, - - // functions - "cap": nil, - "len": nil, - "new": nil, - "make": nil, - "panic": nil, - "panicln": nil, - "print": nil, - "println": nil, - } - } -} - - -// formatting of consecutive single-line functions -func _() {} -func _() {} -func _() {} - -func _() {} // an empty line before this function -func _() {} -func _() {} - -func _() { - f(1, 2, 3); -} -func _(x int) int { - return x+1 -} -func _() int { - type T struct{} -} diff --git a/src/pkg/go/printer/testdata/declarations.input b/src/pkg/go/printer/testdata/declarations.input new file mode 100644 index 000000000..c54a2ce22 --- /dev/null +++ b/src/pkg/go/printer/testdata/declarations.input @@ -0,0 +1,461 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package imports + +import "io" + +import ( + _ "io" +) + +import _ "io" + +import ( + "io"; + "io"; + "io"; +) + +import ( + "io"; + aLongRename "io"; + + b "io"; + c "i" "o"; +) + +// no newlines between consecutive single imports, but +// respect extra line breaks in the source (at most one empty line) +import _ "io" +import _ "io" +import _ "io" + +import _ "os" +import _ "os" +import _ "os" + + +import _ "fmt" +import _ "fmt" +import _ "fmt" + + +// at least one empty line between declarations of different kind +import _ "io" +var _ int; + + +func _() { + // the following decls need a semicolon at the end + type _ int; + type _ *int; + type _ []int; + type _ map[string]int; + type _ chan int; + type _ func() int; + + var _ int; + var _ *int; + var _ []int; + var _ map[string]int; + var _ chan int; + var _ func() int; + + // the following decls don't need a semicolon at the end + type _ struct{} + type _ *struct{} + type _ []struct{} + type _ map[string]struct{} + type _ chan struct{} + type _ func() struct{} + + type _ interface{} + type _ *interface{} + type _ []interface{} + type _ map[string]interface{} + type _ chan interface{} + type _ func() interface{} + + var _ struct{} + var _ *struct{} + var _ []struct{} + var _ map[string]struct{} + var _ chan struct{} + var _ func() struct{} + + var _ interface{} + var _ *interface{} + var _ []interface{} + var _ map[string]interface{} + var _ chan interface{} + var _ func() interface{} +} + + +// don't lose blank lines in grouped declarations +const ( + _ int = 0; + _ float = 1; + + _ string = "foo"; + + _ = iota; + _; + + // a comment + _; + + _; +) + + +type ( + _ int; + _ struct {}; + + _ interface{}; + + // a comment + _ map[string]int; +) + + +var ( + _ int = 0; + _ float = 1; + + _ string = "foo"; + + _ bool; + + // a comment + _ bool; +) + + +// don't lose blank lines in this struct +type _ struct { + String struct { + Str, Len int; + }; + Slice struct { + Array, Len, Cap int; + }; + Eface struct { + Typ, Ptr int; + }; + + UncommonType struct { + Name, PkgPath int; + }; + CommonType struct { + Size, Hash, Alg, Align, FieldAlign, String, UncommonType int; + }; + Type struct { + Typ, Ptr int; + }; + StructField struct { + Name, PkgPath, Typ, Tag, Offset int; + }; + StructType struct { + Fields int; + }; + PtrType struct { + Elem int; + }; + SliceType struct { + Elem int; + }; + ArrayType struct { + Elem, Len int; + }; + + Stktop struct { + Stackguard, Stackbase, Gobuf int; + }; + Gobuf struct { + Sp, Pc, G int; + }; + G struct { + Stackbase, Sched, Status, Alllink int; + }; +} + + +// no tabs for single or ungrouped decls +func _() { + const xxxxxx = 0; + type x int; + var xxx int; + var yyyy float = 3.14; + var zzzzz = "bar"; + + const ( + xxxxxx = 0; + ) + type ( + x int; + ) + var ( + xxx int; + ) + var ( + yyyy float = 3.14; + ) + var ( + zzzzz = "bar"; + ) +} + +// tabs for multiple or grouped decls +func _() { + // no entry has a type + const ( + zzzzzz = 1; + z = 2; + zzz = 3; + ) + // some entries have a type + const ( + xxxxxx = 1; + x = 2; + xxx = 3; + yyyyyyyy float = iota; + yyyy = "bar"; + yyy; + yy = 2; + ) +} + +func _() { + // no entry has a type + var ( + zzzzzz = 1; + z = 2; + zzz = 3; + ) + // no entry has a value + var ( + _ int; + _ float; + _ string; + + _ int; // comment + _ float; // comment + _ string; // comment + ) + // some entries have a type + var ( + xxxxxx int; + x float; + xxx string; + yyyyyyyy int = 1234; + y float = 3.14; + yyyy = "bar"; + yyy string = "foo"; + ) + // mixed entries - all comments should be aligned + var ( + a, b, c int; + x = 10; + d int; // comment + y = 20; // comment + f, ff, fff, ffff int = 0, 1, 2, 3; // comment + ) + // respect original line breaks + var _ = []T { + T{0x20, "Telugu"} + }; + var _ = []T { + // respect original line breaks + T{0x20, "Telugu"} + }; +} + +func _() { + type ( + xxxxxx int; + x float; + xxx string; + xxxxx []x; + xx struct{}; + xxxxxxx struct { + _, _ int; + _ float; + }; + xxxx chan<- string; + ) +} + + +// formatting of structs +type _ struct{} + +type _ struct{ /* this comment should be visible */ } + +type _ struct{ + // this comment should be visible and properly indented +} + +type _ struct { // this comment must not change indentation + f int; + f, ff, fff, ffff int; +} + +type _ struct { + string; +} + +type _ struct { + string; // comment +} + +type _ struct { + string "tag" +} + +type _ struct { + string "tag" // comment +} + +type _ struct { + f int; +} + +type _ struct { + f int; // comment +} + +type _ struct { + f int "tag"; +} + +type _ struct { + f int "tag"; // comment +} + +type _ struct { + bool; + a, b, c int; + int "tag"; + ES; // comment + float "tag"; // comment + f int; // comment + f, ff, fff, ffff int; // comment + g float "tag"; + h float "tag"; // comment +} + + +// difficult cases +type _ struct { + bool; // comment + text []byte; // comment +} + + + +// formatting of interfaces +type EI interface{} + +type _ interface { + EI; +} + +type _ interface { + f(); + fffff(); +} + +type _ interface { + EI; + f(); + fffffg(); +} + +type _ interface { // this comment must not change indentation + EI; // here's a comment + f(); // no blank between identifier and () + fffff(); // no blank between identifier and () + gggggggggggg(x, y, z int) (); // hurray +} + +// formatting of variable declarations +func _() { + type day struct { n int; short, long string }; + var ( + Sunday = day{ 0, "SUN", "Sunday" }; + Monday = day{ 1, "MON", "Monday" }; + Tuesday = day{ 2, "TUE", "Tuesday" }; + Wednesday = day{ 3, "WED", "Wednesday" }; + Thursday = day{ 4, "THU", "Thursday" }; + Friday = day{ 5, "FRI", "Friday" }; + Saturday = day{ 6, "SAT", "Saturday" }; + ) +} + + +func _() { + var Universe = Scope { + Names: map[string]*Ident { + // basic types + "bool": nil, + "byte": nil, + "int8": nil, + "int16": nil, + "int32": nil, + "int64": nil, + "uint8": nil, + "uint16": nil, + "uint32": nil, + "uint64": nil, + "float32": nil, + "float64": nil, + "string": nil, + + // convenience types + "int": nil, + "uint": nil, + "uintptr": nil, + "float": nil, + + // constants + "false": nil, + "true": nil, + "iota": nil, + "nil": nil, + + // functions + "cap": nil, + "len": nil, + "new": nil, + "make": nil, + "panic": nil, + "panicln": nil, + "print": nil, + "println": nil, + } + } +} + + +// formatting of consecutive single-line functions +func _() {} +func _() {} +func _() {} + +func _() {} // an empty line before this function +func _() {} +func _() {} + +func _() { + f(1, 2, 3); +} +func _(x int) int { + return x+1 +} +func _() int { + type T struct{} +} diff --git a/src/pkg/go/printer/testdata/empty.go b/src/pkg/go/printer/testdata/empty.go deleted file mode 100644 index a055f4758..000000000 --- a/src/pkg/go/printer/testdata/empty.go +++ /dev/null @@ -1,5 +0,0 @@ -// a comment at the beginning of the file - -package empty - -// a comment at the end of the file diff --git a/src/pkg/go/printer/testdata/empty.input b/src/pkg/go/printer/testdata/empty.input new file mode 100644 index 000000000..a055f4758 --- /dev/null +++ b/src/pkg/go/printer/testdata/empty.input @@ -0,0 +1,5 @@ +// a comment at the beginning of the file + +package empty + +// a comment at the end of the file diff --git a/src/pkg/go/printer/testdata/expressions.go b/src/pkg/go/printer/testdata/expressions.go deleted file mode 100644 index c4103ae3f..000000000 --- a/src/pkg/go/printer/testdata/expressions.go +++ /dev/null @@ -1,212 +0,0 @@ -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package expressions - -type T struct { - x, y, z int -} - -var ( - a, b, c, d, e int; - under_bar int; - longIdentifier1, longIdentifier2, longIdentifier3 int; - t0, t1, t2 T; - s string; - p *int; -) - - -func _() { - // no spaces around simple or parenthesized expressions - _ = a+b; - _ = a+b+c; - _ = a+b-c; - _ = a-b-c; - _ = a+(b*c); - _ = a+(b/c); - _ = a-(b%c); - _ = 1+a; - _ = a+1; - _ = a+b+1; - _ = s[1:2]; - _ = s[a:b]; - _ = s[0:len(s)]; - _ = s[0]<<1; - _ = (s[0]<<1)&0xf; - _ = s[0] << 2 | s[1] >> 4; - _ = "foo"+s; - _ = s+"foo"; - _ = 'a'+'b'; - _ = len(s)/2; - _ = len(t0.x)/a; - - // spaces around expressions of different precedence or expressions containing spaces - _ = a + -b; - _ = a - ^b; - _ = a / *p; - _ = a + b*c; - _ = 1 + b*c; - _ = a + 2*c; - _ = a + c*2; - _ = 1 + 2*3; - _ = s[1 : 2*3]; - _ = s[a : b-c]; - _ = s[a+b : len(s)]; - _ = s[len(s) : -a]; - _ = s[a : len(s)+1]; - _ = s[a : len(s)+1]+s; - - // spaces around operators with equal or lower precedence than comparisons - _ = a == b; - _ = a != b; - _ = a > b; - _ = a >= b; - _ = a < b; - _ = a <= b; - _ = a < b && c > d; - _ = a < b || c > d; - - // spaces around "long" operands - _ = a + longIdentifier1; - _ = longIdentifier1 + a; - _ = longIdentifier1 + longIdentifier2 * longIdentifier3; - _ = s + "a longer string"; - - // some selected cases - _ = a + t0.x; - _ = a + t0.x + t1.x * t2.x; - _ = a + b + c + d + e + 2*3; - _ = a + b + c + 2*3 + d + e; - _ = (a+b+c)*2; - _ = a - b + c - d + (a+b+c) + d&e; - _ = under_bar-1; - _ = Open(dpath + "/file", O_WRONLY | O_CREAT, 0666); - _ = int(c0&_Mask4)<<18 | int(c1&_Maskx)<<12 | int(c2&_Maskx)<<6 | int(c3&_Maskx); -} - - -func _() { - _ = T{}; - _ = struct{}{}; - _ = [10]T{}; - _ = [...]T{}; - _ = []T{}; - _ = map[int]T{}; - - _ = (T){}; - _ = (struct{}){}; - _ = ([10]T){}; - _ = ([...]T){}; - _ = ([]T){}; - _ = (map[int]T){}; -} - - -func _() { - // do not modify literals - _ = "tab1 tab2 tab3 end"; // string contains 3 tabs - _ = "tab1 tab2 tab3 end"; // same string with 3 blanks - may be unaligned because editors see tabs in strings - _ = ""; // this comment should be aligned with the one on the previous line - _ = ``; - _ = ` -`; -_ = `foo - bar`; -} - - -func _() { - // one-line function literals - _ = func() {}; - _ = func() int { - return 0; - }; - _ = func(x, y int) bool { - return x < y - }; - - f(func() {}); - f(func() int { - return 0; - }); - f(func(x, y int) bool { - return x < y - }); -} - - -func _() { - // not not add extra indentation to multi-line string lists - _ = "foo" "bar"; - _ = "foo" - "bar" - "bah"; - _ = []string { - "abc" - "def", - "foo" - "bar" - } -} - - -func _() { - // respect source lines in multi-line expressions - _ = a+ - b+ - c; - _ = a < b || - b < a; - _ = "933262154439441526816992388562667004907159682643816214685929" - "638952175999932299156089414639761565182862536979208272237582" - "51185210916864000000000000000000000000"; // 100! - _ = "170141183460469231731687303715884105727"; // prime -} - - -// Alignment after overlong lines -const ( - _ = "991"; - _ = "2432902008176640000"; // 20! - _ = "933262154439441526816992388562667004907159682643816214685929" - "638952175999932299156089414639761565182862536979208272237582" - "51185210916864000000000000000000000000"; // 100! - _ = "170141183460469231731687303715884105727"; // prime -) - - -func same(t, u *Time) bool { - // respect source lines in multi-line expressions - return t.Year == u.Year - && t.Month == u.Month - && t.Day == u.Day - && t.Hour == u.Hour - && t.Minute == u.Minute - && t.Second == u.Second - && t.Weekday == u.Weekday - && t.ZoneOffset == u.ZoneOffset - && t.Zone == u.Zone -} - - -func (p *parser) charClass() { - // respect source lines in multi-line expressions - if cc.negate && len(cc.ranges) == 2 && - cc.ranges[0] == '\n' && cc.ranges[1] == '\n' { - nl := new(_NotNl); - p.re.add(nl); - } -} - - -func addState(s []state, inst instr, match []int) { - // handle comments correctly in multi-line expressions - for i := 0; i < l; i++ { - if s[i].inst.index() == index && // same instruction - s[i].match[0] < pos { // earlier match already going; leftmost wins - return s - } - } -} diff --git a/src/pkg/go/printer/testdata/expressions.input b/src/pkg/go/printer/testdata/expressions.input new file mode 100644 index 000000000..c4103ae3f --- /dev/null +++ b/src/pkg/go/printer/testdata/expressions.input @@ -0,0 +1,212 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package expressions + +type T struct { + x, y, z int +} + +var ( + a, b, c, d, e int; + under_bar int; + longIdentifier1, longIdentifier2, longIdentifier3 int; + t0, t1, t2 T; + s string; + p *int; +) + + +func _() { + // no spaces around simple or parenthesized expressions + _ = a+b; + _ = a+b+c; + _ = a+b-c; + _ = a-b-c; + _ = a+(b*c); + _ = a+(b/c); + _ = a-(b%c); + _ = 1+a; + _ = a+1; + _ = a+b+1; + _ = s[1:2]; + _ = s[a:b]; + _ = s[0:len(s)]; + _ = s[0]<<1; + _ = (s[0]<<1)&0xf; + _ = s[0] << 2 | s[1] >> 4; + _ = "foo"+s; + _ = s+"foo"; + _ = 'a'+'b'; + _ = len(s)/2; + _ = len(t0.x)/a; + + // spaces around expressions of different precedence or expressions containing spaces + _ = a + -b; + _ = a - ^b; + _ = a / *p; + _ = a + b*c; + _ = 1 + b*c; + _ = a + 2*c; + _ = a + c*2; + _ = 1 + 2*3; + _ = s[1 : 2*3]; + _ = s[a : b-c]; + _ = s[a+b : len(s)]; + _ = s[len(s) : -a]; + _ = s[a : len(s)+1]; + _ = s[a : len(s)+1]+s; + + // spaces around operators with equal or lower precedence than comparisons + _ = a == b; + _ = a != b; + _ = a > b; + _ = a >= b; + _ = a < b; + _ = a <= b; + _ = a < b && c > d; + _ = a < b || c > d; + + // spaces around "long" operands + _ = a + longIdentifier1; + _ = longIdentifier1 + a; + _ = longIdentifier1 + longIdentifier2 * longIdentifier3; + _ = s + "a longer string"; + + // some selected cases + _ = a + t0.x; + _ = a + t0.x + t1.x * t2.x; + _ = a + b + c + d + e + 2*3; + _ = a + b + c + 2*3 + d + e; + _ = (a+b+c)*2; + _ = a - b + c - d + (a+b+c) + d&e; + _ = under_bar-1; + _ = Open(dpath + "/file", O_WRONLY | O_CREAT, 0666); + _ = int(c0&_Mask4)<<18 | int(c1&_Maskx)<<12 | int(c2&_Maskx)<<6 | int(c3&_Maskx); +} + + +func _() { + _ = T{}; + _ = struct{}{}; + _ = [10]T{}; + _ = [...]T{}; + _ = []T{}; + _ = map[int]T{}; + + _ = (T){}; + _ = (struct{}){}; + _ = ([10]T){}; + _ = ([...]T){}; + _ = ([]T){}; + _ = (map[int]T){}; +} + + +func _() { + // do not modify literals + _ = "tab1 tab2 tab3 end"; // string contains 3 tabs + _ = "tab1 tab2 tab3 end"; // same string with 3 blanks - may be unaligned because editors see tabs in strings + _ = ""; // this comment should be aligned with the one on the previous line + _ = ``; + _ = ` +`; +_ = `foo + bar`; +} + + +func _() { + // one-line function literals + _ = func() {}; + _ = func() int { + return 0; + }; + _ = func(x, y int) bool { + return x < y + }; + + f(func() {}); + f(func() int { + return 0; + }); + f(func(x, y int) bool { + return x < y + }); +} + + +func _() { + // not not add extra indentation to multi-line string lists + _ = "foo" "bar"; + _ = "foo" + "bar" + "bah"; + _ = []string { + "abc" + "def", + "foo" + "bar" + } +} + + +func _() { + // respect source lines in multi-line expressions + _ = a+ + b+ + c; + _ = a < b || + b < a; + _ = "933262154439441526816992388562667004907159682643816214685929" + "638952175999932299156089414639761565182862536979208272237582" + "51185210916864000000000000000000000000"; // 100! + _ = "170141183460469231731687303715884105727"; // prime +} + + +// Alignment after overlong lines +const ( + _ = "991"; + _ = "2432902008176640000"; // 20! + _ = "933262154439441526816992388562667004907159682643816214685929" + "638952175999932299156089414639761565182862536979208272237582" + "51185210916864000000000000000000000000"; // 100! + _ = "170141183460469231731687303715884105727"; // prime +) + + +func same(t, u *Time) bool { + // respect source lines in multi-line expressions + return t.Year == u.Year + && t.Month == u.Month + && t.Day == u.Day + && t.Hour == u.Hour + && t.Minute == u.Minute + && t.Second == u.Second + && t.Weekday == u.Weekday + && t.ZoneOffset == u.ZoneOffset + && t.Zone == u.Zone +} + + +func (p *parser) charClass() { + // respect source lines in multi-line expressions + if cc.negate && len(cc.ranges) == 2 && + cc.ranges[0] == '\n' && cc.ranges[1] == '\n' { + nl := new(_NotNl); + p.re.add(nl); + } +} + + +func addState(s []state, inst instr, match []int) { + // handle comments correctly in multi-line expressions + for i := 0; i < l; i++ { + if s[i].inst.index() == index && // same instruction + s[i].match[0] < pos { // earlier match already going; leftmost wins + return s + } + } +} diff --git a/src/pkg/go/printer/testdata/linebreaks.go b/src/pkg/go/printer/testdata/linebreaks.go deleted file mode 100644 index 6624e55d0..000000000 --- a/src/pkg/go/printer/testdata/linebreaks.go +++ /dev/null @@ -1,222 +0,0 @@ -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package linebreaks - -import ( - "bytes"; - "fmt"; - "io"; - "os"; - "reflect"; - "strings"; - "testing"; -) - -type writerTestEntry struct { - header *Header; - contents string; -} - -type writerTest struct { - file string; // filename of expected output - entries []*writerTestEntry; -} - -var writerTests = []*writerTest{ - &writerTest{ - file: "testdata/writer.tar", - entries: []*writerTestEntry{ - &writerTestEntry{ - header: &Header{ - Name: "small.txt", - Mode: 0640, - Uid: 73025, - Gid: 5000, - Size: 5, - Mtime: 1246508266, - Typeflag: '0', - Uname: "dsymonds", - Gname: "eng", - }, - contents: "Kilts", - }, - &writerTestEntry{ - header: &Header{ - Name: "small2.txt", - Mode: 0640, - Uid: 73025, - Gid: 5000, - Size: 11, - Mtime: 1245217492, - Typeflag: '0', - Uname: "dsymonds", - Gname: "eng", - }, - contents: "Google.com\n", - }, - } - }, - // The truncated test file was produced using these commands: - // dd if=/dev/zero bs=1048576 count=16384 > /tmp/16gig.txt - // tar -b 1 -c -f- /tmp/16gig.txt | dd bs=512 count=8 > writer-big.tar - &writerTest{ - file: "testdata/writer-big.tar", - entries: []*writerTestEntry{ - &writerTestEntry{ - header: &Header{ - Name: "tmp/16gig.txt", - Mode: 0640, - Uid: 73025, - Gid: 5000, - Size: 16 << 30, - Mtime: 1254699560, - Typeflag: '0', - Uname: "dsymonds", - Gname: "eng", - }, - // no contents - }, - }, - }, -} - -type untarTest struct { - file string; - headers []*Header; -} - -var untarTests = []*untarTest{ - &untarTest{ - file: "testdata/gnu.tar", - headers: []*Header{ - &Header{ - Name: "small.txt", - Mode: 0640, - Uid: 73025, - Gid: 5000, - Size: 5, - Mtime: 1244428340, - Typeflag: '0', - Uname: "dsymonds", - Gname: "eng", - }, - &Header{ - Name: "small2.txt", - Mode: 0640, - Uid: 73025, - Gid: 5000, - Size: 11, - Mtime: 1244436044, - Typeflag: '0', - Uname: "dsymonds", - Gname: "eng", - }, - }, - }, - &untarTest{ - file: "testdata/star.tar", - headers: []*Header{ - &Header{ - Name: "small.txt", - Mode: 0640, - Uid: 73025, - Gid: 5000, - Size: 5, - Mtime: 1244592783, - Typeflag: '0', - Uname: "dsymonds", - Gname: "eng", - Atime: 1244592783, - Ctime: 1244592783, - }, - &Header{ - Name: "small2.txt", - Mode: 0640, - Uid: 73025, - Gid: 5000, - Size: 11, - Mtime: 1244592783, - Typeflag: '0', - Uname: "dsymonds", - Gname: "eng", - Atime: 1244592783, - Ctime: 1244592783, - }, - }, - }, - &untarTest{ - file: "testdata/v7.tar", - headers: []*Header{ - &Header{ - Name: "small.txt", - Mode: 0444, - Uid: 73025, - Gid: 5000, - Size: 5, - Mtime: 1244593104, - Typeflag: '\x00', - }, - &Header{ - Name: "small2.txt", - Mode: 0444, - Uid: 73025, - Gid: 5000, - Size: 11, - Mtime: 1244593104, - Typeflag: '\x00', - }, - }, - }, -} - -var facts = map[int] string { - 0: "1", - 1: "1", - 2: "2", - 10: "3628800", - 20: "2432902008176640000", - 100: "933262154439441526816992388562667004907159682643816214685929" - "638952175999932299156089414639761565182862536979208272237582" - "51185210916864000000000000000000000000", -} - -func usage() { - fmt.Fprintf(os.Stderr, - // TODO(gri): the 2nd string of this string list should not be indented - "usage: godoc package [name ...]\n" - " godoc -http=:6060\n" - ); - flag.PrintDefaults(); - os.Exit(2); -} - -func TestReader(t *testing.T) { -testLoop: - for i, test := range untarTests { - f, err := os.Open(test.file, os.O_RDONLY, 0444); - if err != nil { - t.Errorf("test %d: Unexpected error: %v", i, err); - continue - } - tr := NewReader(f); - for j, header := range test.headers { - hdr, err := tr.Next(); - if err != nil || hdr == nil { - t.Errorf("test %d, entry %d: Didn't get entry: %v", i, j, err); - f.Close(); - continue testLoop - } - if !reflect.DeepEqual(hdr, header) { - t.Errorf("test %d, entry %d: Incorrect header:\nhave %+v\nwant %+v", - i, j, *hdr, *header); - } - } - hdr, err := tr.Next(); - if hdr != nil || err != nil { - t.Errorf("test %d: Unexpected entry or error: hdr=%v err=%v", i, err); - } - f.Close(); - } -} diff --git a/src/pkg/go/printer/testdata/linebreaks.input b/src/pkg/go/printer/testdata/linebreaks.input new file mode 100644 index 000000000..6624e55d0 --- /dev/null +++ b/src/pkg/go/printer/testdata/linebreaks.input @@ -0,0 +1,222 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package linebreaks + +import ( + "bytes"; + "fmt"; + "io"; + "os"; + "reflect"; + "strings"; + "testing"; +) + +type writerTestEntry struct { + header *Header; + contents string; +} + +type writerTest struct { + file string; // filename of expected output + entries []*writerTestEntry; +} + +var writerTests = []*writerTest{ + &writerTest{ + file: "testdata/writer.tar", + entries: []*writerTestEntry{ + &writerTestEntry{ + header: &Header{ + Name: "small.txt", + Mode: 0640, + Uid: 73025, + Gid: 5000, + Size: 5, + Mtime: 1246508266, + Typeflag: '0', + Uname: "dsymonds", + Gname: "eng", + }, + contents: "Kilts", + }, + &writerTestEntry{ + header: &Header{ + Name: "small2.txt", + Mode: 0640, + Uid: 73025, + Gid: 5000, + Size: 11, + Mtime: 1245217492, + Typeflag: '0', + Uname: "dsymonds", + Gname: "eng", + }, + contents: "Google.com\n", + }, + } + }, + // The truncated test file was produced using these commands: + // dd if=/dev/zero bs=1048576 count=16384 > /tmp/16gig.txt + // tar -b 1 -c -f- /tmp/16gig.txt | dd bs=512 count=8 > writer-big.tar + &writerTest{ + file: "testdata/writer-big.tar", + entries: []*writerTestEntry{ + &writerTestEntry{ + header: &Header{ + Name: "tmp/16gig.txt", + Mode: 0640, + Uid: 73025, + Gid: 5000, + Size: 16 << 30, + Mtime: 1254699560, + Typeflag: '0', + Uname: "dsymonds", + Gname: "eng", + }, + // no contents + }, + }, + }, +} + +type untarTest struct { + file string; + headers []*Header; +} + +var untarTests = []*untarTest{ + &untarTest{ + file: "testdata/gnu.tar", + headers: []*Header{ + &Header{ + Name: "small.txt", + Mode: 0640, + Uid: 73025, + Gid: 5000, + Size: 5, + Mtime: 1244428340, + Typeflag: '0', + Uname: "dsymonds", + Gname: "eng", + }, + &Header{ + Name: "small2.txt", + Mode: 0640, + Uid: 73025, + Gid: 5000, + Size: 11, + Mtime: 1244436044, + Typeflag: '0', + Uname: "dsymonds", + Gname: "eng", + }, + }, + }, + &untarTest{ + file: "testdata/star.tar", + headers: []*Header{ + &Header{ + Name: "small.txt", + Mode: 0640, + Uid: 73025, + Gid: 5000, + Size: 5, + Mtime: 1244592783, + Typeflag: '0', + Uname: "dsymonds", + Gname: "eng", + Atime: 1244592783, + Ctime: 1244592783, + }, + &Header{ + Name: "small2.txt", + Mode: 0640, + Uid: 73025, + Gid: 5000, + Size: 11, + Mtime: 1244592783, + Typeflag: '0', + Uname: "dsymonds", + Gname: "eng", + Atime: 1244592783, + Ctime: 1244592783, + }, + }, + }, + &untarTest{ + file: "testdata/v7.tar", + headers: []*Header{ + &Header{ + Name: "small.txt", + Mode: 0444, + Uid: 73025, + Gid: 5000, + Size: 5, + Mtime: 1244593104, + Typeflag: '\x00', + }, + &Header{ + Name: "small2.txt", + Mode: 0444, + Uid: 73025, + Gid: 5000, + Size: 11, + Mtime: 1244593104, + Typeflag: '\x00', + }, + }, + }, +} + +var facts = map[int] string { + 0: "1", + 1: "1", + 2: "2", + 10: "3628800", + 20: "2432902008176640000", + 100: "933262154439441526816992388562667004907159682643816214685929" + "638952175999932299156089414639761565182862536979208272237582" + "51185210916864000000000000000000000000", +} + +func usage() { + fmt.Fprintf(os.Stderr, + // TODO(gri): the 2nd string of this string list should not be indented + "usage: godoc package [name ...]\n" + " godoc -http=:6060\n" + ); + flag.PrintDefaults(); + os.Exit(2); +} + +func TestReader(t *testing.T) { +testLoop: + for i, test := range untarTests { + f, err := os.Open(test.file, os.O_RDONLY, 0444); + if err != nil { + t.Errorf("test %d: Unexpected error: %v", i, err); + continue + } + tr := NewReader(f); + for j, header := range test.headers { + hdr, err := tr.Next(); + if err != nil || hdr == nil { + t.Errorf("test %d, entry %d: Didn't get entry: %v", i, j, err); + f.Close(); + continue testLoop + } + if !reflect.DeepEqual(hdr, header) { + t.Errorf("test %d, entry %d: Incorrect header:\nhave %+v\nwant %+v", + i, j, *hdr, *header); + } + } + hdr, err := tr.Next(); + if hdr != nil || err != nil { + t.Errorf("test %d: Unexpected entry or error: hdr=%v err=%v", i, err); + } + f.Close(); + } +} diff --git a/src/pkg/go/printer/testdata/statements.go b/src/pkg/go/printer/testdata/statements.go deleted file mode 100644 index 85a79f152..000000000 --- a/src/pkg/go/printer/testdata/statements.go +++ /dev/null @@ -1,201 +0,0 @@ -// Copyright 2009 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package statements - -var expr bool; - -func use(x interface{}) {} - -// Formatting of if-statement headers. -func _() { - if {} - if;{} // no semicolon printed - if expr{} - if;expr{} // no semicolon printed - if (expr){} // no parens printed - if;((expr)){} // no semicolon and parens printed - if x:=expr;{ - use(x)} - if x:=expr; expr {use(x)} -} - - -// Formatting of switch-statement headers. -func _() { - switch {} - switch;{} // no semicolon printed - switch expr {} - switch;expr{} // no semicolon printed - switch (expr) {} // no parens printed - switch;((expr)){} // no semicolon and parens printed - switch x := expr; { default:use( -x) - } - switch x := expr; expr {default:use(x)} -} - - -// Formatting of switch statement bodies. -func _() { - switch { - } - - switch x := 0; x { - case 1: - use(x); - use(x); // followed by an empty line - - case 2: // followed by an empty line - - use(x); // followed by an empty line - - case 3: // no empty lines - use(x); - use(x); - } - - switch x { - case 0: - use(x); - case 1: // this comment should have no effect on the previous or next line - use(x); - } - - switch x := 0; x { - case 1: - x = 0; - // this comment should be indented - case 2: - x = 0; - // this comment should not be indented, it is aligned with the next case - case 3: - x = 0; - /* indented comment - aligned - aligned - */ - // bla - /* and more */ - case 4: - x = 0; - /* not indented comment - aligned - aligned - */ - // bla - /* and more */ - case 5: - } -} - - -// Formatting of for-statement headers. -func _() { - for{} - for expr {} - for (expr) {} // no parens printed - for;;{} // no semicolons printed - for x :=expr;; {use( x)} - for; expr;{} // no semicolons printed - for; ((expr));{} // no semicolons and parens printed - for; ; expr = false {} - for x :=expr; expr; {use(x)} - for x := expr;; expr=false {use(x)} - for;expr;expr =false { - } - for x := expr;expr;expr = false { use(x) } - for x := range []int{} { use(x) } -} - - -// Extra empty lines inside functions. Do respect source code line -// breaks between statement boundaries but print at most one empty -// line at a time. -func _() { - - const _ = 0; - - const _ = 1; - type _ int; - type _ float; - - var _ = 0; - var x = 1; - - // Each use(x) call below should have at most one empty line before and after. - - - - use(x); - - if x < x { - - use(x); - - } else { - - use(x); - - } -} - - -// Formatting around labels. -func _() { - L: -} - - -func _() { - // this comment should be indented - L: -} - - -func _() { - L: _ = 0; -} - - -func _() { - // this comment should be indented - L: _ = 0; -} - - -func _() { - for { - L1: _ = 0; - L2: - _ = 0; - } -} - - -func _() { - // this comment should be indented - for { - L1: _ = 0; - L2: - _ = 0; - } -} - - -func _() { - if { - _ = 0; - } - _ = 0; // the indentation here should not be affected by the long label name -AnOverlongLabel: - _ = 0; - - if { - _ = 0; - } - _ = 0; - -L: _ = 0; -} diff --git a/src/pkg/go/printer/testdata/statements.input b/src/pkg/go/printer/testdata/statements.input new file mode 100644 index 000000000..85a79f152 --- /dev/null +++ b/src/pkg/go/printer/testdata/statements.input @@ -0,0 +1,201 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package statements + +var expr bool; + +func use(x interface{}) {} + +// Formatting of if-statement headers. +func _() { + if {} + if;{} // no semicolon printed + if expr{} + if;expr{} // no semicolon printed + if (expr){} // no parens printed + if;((expr)){} // no semicolon and parens printed + if x:=expr;{ + use(x)} + if x:=expr; expr {use(x)} +} + + +// Formatting of switch-statement headers. +func _() { + switch {} + switch;{} // no semicolon printed + switch expr {} + switch;expr{} // no semicolon printed + switch (expr) {} // no parens printed + switch;((expr)){} // no semicolon and parens printed + switch x := expr; { default:use( +x) + } + switch x := expr; expr {default:use(x)} +} + + +// Formatting of switch statement bodies. +func _() { + switch { + } + + switch x := 0; x { + case 1: + use(x); + use(x); // followed by an empty line + + case 2: // followed by an empty line + + use(x); // followed by an empty line + + case 3: // no empty lines + use(x); + use(x); + } + + switch x { + case 0: + use(x); + case 1: // this comment should have no effect on the previous or next line + use(x); + } + + switch x := 0; x { + case 1: + x = 0; + // this comment should be indented + case 2: + x = 0; + // this comment should not be indented, it is aligned with the next case + case 3: + x = 0; + /* indented comment + aligned + aligned + */ + // bla + /* and more */ + case 4: + x = 0; + /* not indented comment + aligned + aligned + */ + // bla + /* and more */ + case 5: + } +} + + +// Formatting of for-statement headers. +func _() { + for{} + for expr {} + for (expr) {} // no parens printed + for;;{} // no semicolons printed + for x :=expr;; {use( x)} + for; expr;{} // no semicolons printed + for; ((expr));{} // no semicolons and parens printed + for; ; expr = false {} + for x :=expr; expr; {use(x)} + for x := expr;; expr=false {use(x)} + for;expr;expr =false { + } + for x := expr;expr;expr = false { use(x) } + for x := range []int{} { use(x) } +} + + +// Extra empty lines inside functions. Do respect source code line +// breaks between statement boundaries but print at most one empty +// line at a time. +func _() { + + const _ = 0; + + const _ = 1; + type _ int; + type _ float; + + var _ = 0; + var x = 1; + + // Each use(x) call below should have at most one empty line before and after. + + + + use(x); + + if x < x { + + use(x); + + } else { + + use(x); + + } +} + + +// Formatting around labels. +func _() { + L: +} + + +func _() { + // this comment should be indented + L: +} + + +func _() { + L: _ = 0; +} + + +func _() { + // this comment should be indented + L: _ = 0; +} + + +func _() { + for { + L1: _ = 0; + L2: + _ = 0; + } +} + + +func _() { + // this comment should be indented + for { + L1: _ = 0; + L2: + _ = 0; + } +} + + +func _() { + if { + _ = 0; + } + _ = 0; // the indentation here should not be affected by the long label name +AnOverlongLabel: + _ = 0; + + if { + _ = 0; + } + _ = 0; + +L: _ = 0; +} -- cgit v1.2.3