summaryrefslogtreecommitdiffstats
path: root/src/cmd/gofmt/testdata
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/gofmt/testdata')
-rw-r--r--src/cmd/gofmt/testdata/comments.golden9
-rw-r--r--src/cmd/gofmt/testdata/comments.input9
-rw-r--r--src/cmd/gofmt/testdata/composites.golden218
-rw-r--r--src/cmd/gofmt/testdata/composites.input218
-rw-r--r--src/cmd/gofmt/testdata/crlf.golden13
-rw-r--r--src/cmd/gofmt/testdata/crlf.input13
-rw-r--r--src/cmd/gofmt/testdata/emptydecl.golden14
-rw-r--r--src/cmd/gofmt/testdata/emptydecl.input16
-rw-r--r--src/cmd/gofmt/testdata/go2numbers.golden186
-rw-r--r--src/cmd/gofmt/testdata/go2numbers.input186
-rw-r--r--src/cmd/gofmt/testdata/import.golden194
-rw-r--r--src/cmd/gofmt/testdata/import.input199
-rw-r--r--src/cmd/gofmt/testdata/issue28082.golden13
-rw-r--r--src/cmd/gofmt/testdata/issue28082.input13
-rw-r--r--src/cmd/gofmt/testdata/ranges.golden30
-rw-r--r--src/cmd/gofmt/testdata/ranges.input20
-rw-r--r--src/cmd/gofmt/testdata/rewrite1.golden14
-rw-r--r--src/cmd/gofmt/testdata/rewrite1.input14
-rw-r--r--src/cmd/gofmt/testdata/rewrite10.golden19
-rw-r--r--src/cmd/gofmt/testdata/rewrite10.input19
-rw-r--r--src/cmd/gofmt/testdata/rewrite2.golden12
-rw-r--r--src/cmd/gofmt/testdata/rewrite2.input12
-rw-r--r--src/cmd/gofmt/testdata/rewrite3.golden14
-rw-r--r--src/cmd/gofmt/testdata/rewrite3.input14
-rw-r--r--src/cmd/gofmt/testdata/rewrite4.golden76
-rw-r--r--src/cmd/gofmt/testdata/rewrite4.input76
-rw-r--r--src/cmd/gofmt/testdata/rewrite5.golden17
-rw-r--r--src/cmd/gofmt/testdata/rewrite5.input17
-rw-r--r--src/cmd/gofmt/testdata/rewrite6.golden17
-rw-r--r--src/cmd/gofmt/testdata/rewrite6.input17
-rw-r--r--src/cmd/gofmt/testdata/rewrite7.golden17
-rw-r--r--src/cmd/gofmt/testdata/rewrite7.input17
-rw-r--r--src/cmd/gofmt/testdata/rewrite8.golden12
-rw-r--r--src/cmd/gofmt/testdata/rewrite8.input12
-rw-r--r--src/cmd/gofmt/testdata/rewrite9.golden11
-rw-r--r--src/cmd/gofmt/testdata/rewrite9.input11
-rw-r--r--src/cmd/gofmt/testdata/slices1.golden66
-rw-r--r--src/cmd/gofmt/testdata/slices1.input66
-rw-r--r--src/cmd/gofmt/testdata/stdin1.golden5
-rw-r--r--src/cmd/gofmt/testdata/stdin1.input5
-rw-r--r--src/cmd/gofmt/testdata/stdin2.golden11
-rw-r--r--src/cmd/gofmt/testdata/stdin2.input11
-rw-r--r--src/cmd/gofmt/testdata/stdin3.golden7
-rw-r--r--src/cmd/gofmt/testdata/stdin3.input5
-rw-r--r--src/cmd/gofmt/testdata/stdin4.golden5
-rw-r--r--src/cmd/gofmt/testdata/stdin4.input5
-rw-r--r--src/cmd/gofmt/testdata/stdin5.golden3
-rw-r--r--src/cmd/gofmt/testdata/stdin5.input3
-rw-r--r--src/cmd/gofmt/testdata/stdin6.golden19
-rw-r--r--src/cmd/gofmt/testdata/stdin6.input21
-rw-r--r--src/cmd/gofmt/testdata/stdin7.golden19
-rw-r--r--src/cmd/gofmt/testdata/stdin7.input21
-rw-r--r--src/cmd/gofmt/testdata/tabs.golden33
-rw-r--r--src/cmd/gofmt/testdata/tabs.input33
-rw-r--r--src/cmd/gofmt/testdata/typealias.golden24
-rw-r--r--src/cmd/gofmt/testdata/typealias.input24
-rw-r--r--src/cmd/gofmt/testdata/typeparams.golden35
-rw-r--r--src/cmd/gofmt/testdata/typeparams.input32
-rw-r--r--src/cmd/gofmt/testdata/typeswitch.golden60
-rw-r--r--src/cmd/gofmt/testdata/typeswitch.input60
60 files changed, 2342 insertions, 0 deletions
diff --git a/src/cmd/gofmt/testdata/comments.golden b/src/cmd/gofmt/testdata/comments.golden
new file mode 100644
index 0000000..ad6bcaf
--- /dev/null
+++ b/src/cmd/gofmt/testdata/comments.golden
@@ -0,0 +1,9 @@
+package main
+
+func main() {}
+
+// comment here
+
+func f() {}
+
+//line foo.go:1
diff --git a/src/cmd/gofmt/testdata/comments.input b/src/cmd/gofmt/testdata/comments.input
new file mode 100644
index 0000000..ad6bcaf
--- /dev/null
+++ b/src/cmd/gofmt/testdata/comments.input
@@ -0,0 +1,9 @@
+package main
+
+func main() {}
+
+// comment here
+
+func f() {}
+
+//line foo.go:1
diff --git a/src/cmd/gofmt/testdata/composites.golden b/src/cmd/gofmt/testdata/composites.golden
new file mode 100644
index 0000000..a06a69d
--- /dev/null
+++ b/src/cmd/gofmt/testdata/composites.golden
@@ -0,0 +1,218 @@
+//gofmt -s
+
+package P
+
+type T struct {
+ x, y int
+}
+
+type T2 struct {
+ w, z int
+}
+
+var _ = [42]T{
+ {},
+ {1, 2},
+ {3, 4},
+}
+
+var _ = [...]T{
+ {},
+ {1, 2},
+ {3, 4},
+}
+
+var _ = []T{
+ {},
+ {1, 2},
+ {3, 4},
+}
+
+var _ = []T{
+ {},
+ 10: {1, 2},
+ 20: {3, 4},
+}
+
+var _ = []struct {
+ x, y int
+}{
+ {},
+ 10: {1, 2},
+ 20: {3, 4},
+}
+
+var _ = []interface{}{
+ T{},
+ 10: T{1, 2},
+ 20: T{3, 4},
+}
+
+var _ = [][]int{
+ {},
+ {1, 2},
+ {3, 4},
+}
+
+var _ = [][]int{
+ ([]int{}),
+ ([]int{1, 2}),
+ {3, 4},
+}
+
+var _ = [][][]int{
+ {},
+ {
+ {},
+ {0, 1, 2, 3},
+ {4, 5},
+ },
+}
+
+var _ = map[string]T{
+ "foo": {},
+ "bar": {1, 2},
+ "bal": {3, 4},
+}
+
+var _ = map[string]struct {
+ x, y int
+}{
+ "foo": {},
+ "bar": {1, 2},
+ "bal": {3, 4},
+}
+
+var _ = map[string]interface{}{
+ "foo": T{},
+ "bar": T{1, 2},
+ "bal": T{3, 4},
+}
+
+var _ = map[string][]int{
+ "foo": {},
+ "bar": {1, 2},
+ "bal": {3, 4},
+}
+
+var _ = map[string][]int{
+ "foo": ([]int{}),
+ "bar": ([]int{1, 2}),
+ "bal": {3, 4},
+}
+
+// from exp/4s/data.go
+var pieces4 = []Piece{
+ {0, 0, Point{4, 1}, []Point{{0, 0}, {1, 0}, {1, 0}, {1, 0}}, nil, nil},
+ {1, 0, Point{1, 4}, []Point{{0, 0}, {0, 1}, {0, 1}, {0, 1}}, nil, nil},
+ {2, 0, Point{4, 1}, []Point{{0, 0}, {1, 0}, {1, 0}, {1, 0}}, nil, nil},
+ {3, 0, Point{1, 4}, []Point{{0, 0}, {0, 1}, {0, 1}, {0, 1}}, nil, nil},
+}
+
+var _ = [42]*T{
+ {},
+ {1, 2},
+ {3, 4},
+}
+
+var _ = [...]*T{
+ {},
+ {1, 2},
+ {3, 4},
+}
+
+var _ = []*T{
+ {},
+ {1, 2},
+ {3, 4},
+}
+
+var _ = []*T{
+ {},
+ 10: {1, 2},
+ 20: {3, 4},
+}
+
+var _ = []*struct {
+ x, y int
+}{
+ {},
+ 10: {1, 2},
+ 20: {3, 4},
+}
+
+var _ = []interface{}{
+ &T{},
+ 10: &T{1, 2},
+ 20: &T{3, 4},
+}
+
+var _ = []*[]int{
+ {},
+ {1, 2},
+ {3, 4},
+}
+
+var _ = []*[]int{
+ (&[]int{}),
+ (&[]int{1, 2}),
+ {3, 4},
+}
+
+var _ = []*[]*[]int{
+ {},
+ {
+ {},
+ {0, 1, 2, 3},
+ {4, 5},
+ },
+}
+
+var _ = map[string]*T{
+ "foo": {},
+ "bar": {1, 2},
+ "bal": {3, 4},
+}
+
+var _ = map[string]*struct {
+ x, y int
+}{
+ "foo": {},
+ "bar": {1, 2},
+ "bal": {3, 4},
+}
+
+var _ = map[string]interface{}{
+ "foo": &T{},
+ "bar": &T{1, 2},
+ "bal": &T{3, 4},
+}
+
+var _ = map[string]*[]int{
+ "foo": {},
+ "bar": {1, 2},
+ "bal": {3, 4},
+}
+
+var _ = map[string]*[]int{
+ "foo": (&[]int{}),
+ "bar": (&[]int{1, 2}),
+ "bal": {3, 4},
+}
+
+var pieces4 = []*Piece{
+ {0, 0, Point{4, 1}, []Point{{0, 0}, {1, 0}, {1, 0}, {1, 0}}, nil, nil},
+ {1, 0, Point{1, 4}, []Point{{0, 0}, {0, 1}, {0, 1}, {0, 1}}, nil, nil},
+ {2, 0, Point{4, 1}, []Point{{0, 0}, {1, 0}, {1, 0}, {1, 0}}, nil, nil},
+ {3, 0, Point{1, 4}, []Point{{0, 0}, {0, 1}, {0, 1}, {0, 1}}, nil, nil},
+}
+
+var _ = map[T]T2{
+ {1, 2}: {3, 4},
+ {5, 6}: {7, 8},
+}
+
+var _ = map[*T]*T2{
+ {1, 2}: {3, 4},
+ {5, 6}: {7, 8},
+}
diff --git a/src/cmd/gofmt/testdata/composites.input b/src/cmd/gofmt/testdata/composites.input
new file mode 100644
index 0000000..9d28ac7
--- /dev/null
+++ b/src/cmd/gofmt/testdata/composites.input
@@ -0,0 +1,218 @@
+//gofmt -s
+
+package P
+
+type T struct {
+ x, y int
+}
+
+type T2 struct {
+ w, z int
+}
+
+var _ = [42]T{
+ T{},
+ T{1, 2},
+ T{3, 4},
+}
+
+var _ = [...]T{
+ T{},
+ T{1, 2},
+ T{3, 4},
+}
+
+var _ = []T{
+ T{},
+ T{1, 2},
+ T{3, 4},
+}
+
+var _ = []T{
+ T{},
+ 10: T{1, 2},
+ 20: T{3, 4},
+}
+
+var _ = []struct {
+ x, y int
+}{
+ struct{ x, y int }{},
+ 10: struct{ x, y int }{1, 2},
+ 20: struct{ x, y int }{3, 4},
+}
+
+var _ = []interface{}{
+ T{},
+ 10: T{1, 2},
+ 20: T{3, 4},
+}
+
+var _ = [][]int{
+ []int{},
+ []int{1, 2},
+ []int{3, 4},
+}
+
+var _ = [][]int{
+ ([]int{}),
+ ([]int{1, 2}),
+ []int{3, 4},
+}
+
+var _ = [][][]int{
+ [][]int{},
+ [][]int{
+ []int{},
+ []int{0, 1, 2, 3},
+ []int{4, 5},
+ },
+}
+
+var _ = map[string]T{
+ "foo": T{},
+ "bar": T{1, 2},
+ "bal": T{3, 4},
+}
+
+var _ = map[string]struct {
+ x, y int
+}{
+ "foo": struct{ x, y int }{},
+ "bar": struct{ x, y int }{1, 2},
+ "bal": struct{ x, y int }{3, 4},
+}
+
+var _ = map[string]interface{}{
+ "foo": T{},
+ "bar": T{1, 2},
+ "bal": T{3, 4},
+}
+
+var _ = map[string][]int{
+ "foo": []int{},
+ "bar": []int{1, 2},
+ "bal": []int{3, 4},
+}
+
+var _ = map[string][]int{
+ "foo": ([]int{}),
+ "bar": ([]int{1, 2}),
+ "bal": []int{3, 4},
+}
+
+// from exp/4s/data.go
+var pieces4 = []Piece{
+ Piece{0, 0, Point{4, 1}, []Point{Point{0, 0}, Point{1, 0}, Point{1, 0}, Point{1, 0}}, nil, nil},
+ Piece{1, 0, Point{1, 4}, []Point{Point{0, 0}, Point{0, 1}, Point{0, 1}, Point{0, 1}}, nil, nil},
+ Piece{2, 0, Point{4, 1}, []Point{Point{0, 0}, Point{1, 0}, Point{1, 0}, Point{1, 0}}, nil, nil},
+ Piece{3, 0, Point{1, 4}, []Point{Point{0, 0}, Point{0, 1}, Point{0, 1}, Point{0, 1}}, nil, nil},
+}
+
+var _ = [42]*T{
+ &T{},
+ &T{1, 2},
+ &T{3, 4},
+}
+
+var _ = [...]*T{
+ &T{},
+ &T{1, 2},
+ &T{3, 4},
+}
+
+var _ = []*T{
+ &T{},
+ &T{1, 2},
+ &T{3, 4},
+}
+
+var _ = []*T{
+ &T{},
+ 10: &T{1, 2},
+ 20: &T{3, 4},
+}
+
+var _ = []*struct {
+ x, y int
+}{
+ &struct{ x, y int }{},
+ 10: &struct{ x, y int }{1, 2},
+ 20: &struct{ x, y int }{3, 4},
+}
+
+var _ = []interface{}{
+ &T{},
+ 10: &T{1, 2},
+ 20: &T{3, 4},
+}
+
+var _ = []*[]int{
+ &[]int{},
+ &[]int{1, 2},
+ &[]int{3, 4},
+}
+
+var _ = []*[]int{
+ (&[]int{}),
+ (&[]int{1, 2}),
+ &[]int{3, 4},
+}
+
+var _ = []*[]*[]int{
+ &[]*[]int{},
+ &[]*[]int{
+ &[]int{},
+ &[]int{0, 1, 2, 3},
+ &[]int{4, 5},
+ },
+}
+
+var _ = map[string]*T{
+ "foo": &T{},
+ "bar": &T{1, 2},
+ "bal": &T{3, 4},
+}
+
+var _ = map[string]*struct {
+ x, y int
+}{
+ "foo": &struct{ x, y int }{},
+ "bar": &struct{ x, y int }{1, 2},
+ "bal": &struct{ x, y int }{3, 4},
+}
+
+var _ = map[string]interface{}{
+ "foo": &T{},
+ "bar": &T{1, 2},
+ "bal": &T{3, 4},
+}
+
+var _ = map[string]*[]int{
+ "foo": &[]int{},
+ "bar": &[]int{1, 2},
+ "bal": &[]int{3, 4},
+}
+
+var _ = map[string]*[]int{
+ "foo": (&[]int{}),
+ "bar": (&[]int{1, 2}),
+ "bal": &[]int{3, 4},
+}
+
+var pieces4 = []*Piece{
+ &Piece{0, 0, Point{4, 1}, []Point{Point{0, 0}, Point{1, 0}, Point{1, 0}, Point{1, 0}}, nil, nil},
+ &Piece{1, 0, Point{1, 4}, []Point{Point{0, 0}, Point{0, 1}, Point{0, 1}, Point{0, 1}}, nil, nil},
+ &Piece{2, 0, Point{4, 1}, []Point{Point{0, 0}, Point{1, 0}, Point{1, 0}, Point{1, 0}}, nil, nil},
+ &Piece{3, 0, Point{1, 4}, []Point{Point{0, 0}, Point{0, 1}, Point{0, 1}, Point{0, 1}}, nil, nil},
+}
+
+var _ = map[T]T2{
+ T{1, 2}: T2{3, 4},
+ T{5, 6}: T2{7, 8},
+}
+
+var _ = map[*T]*T2{
+ &T{1, 2}: &T2{3, 4},
+ &T{5, 6}: &T2{7, 8},
+}
diff --git a/src/cmd/gofmt/testdata/crlf.golden b/src/cmd/gofmt/testdata/crlf.golden
new file mode 100644
index 0000000..65de9cf
--- /dev/null
+++ b/src/cmd/gofmt/testdata/crlf.golden
@@ -0,0 +1,13 @@
+/*
+Source containing CR/LF line endings.
+The gofmt'ed output must only have LF
+line endings.
+Test case for issue 3961.
+*/
+package main
+
+func main() {
+ // line comment
+ println("hello, world!") // another line comment
+ println()
+}
diff --git a/src/cmd/gofmt/testdata/crlf.input b/src/cmd/gofmt/testdata/crlf.input
new file mode 100644
index 0000000..3cd4934
--- /dev/null
+++ b/src/cmd/gofmt/testdata/crlf.input
@@ -0,0 +1,13 @@
+/*
+Source containing CR/LF line endings.
+The gofmt'ed output must only have LF
+line endings.
+Test case for issue 3961.
+*/
+package main
+
+func main() {
+ // line comment
+ println("hello, world!") // another line comment
+ println()
+}
diff --git a/src/cmd/gofmt/testdata/emptydecl.golden b/src/cmd/gofmt/testdata/emptydecl.golden
new file mode 100644
index 0000000..33d6435
--- /dev/null
+++ b/src/cmd/gofmt/testdata/emptydecl.golden
@@ -0,0 +1,14 @@
+//gofmt -s
+
+// Test case for issue 7631.
+
+package main
+
+// Keep this declaration
+var ()
+
+const (
+// Keep this declaration
+)
+
+func main() {}
diff --git a/src/cmd/gofmt/testdata/emptydecl.input b/src/cmd/gofmt/testdata/emptydecl.input
new file mode 100644
index 0000000..4948a61
--- /dev/null
+++ b/src/cmd/gofmt/testdata/emptydecl.input
@@ -0,0 +1,16 @@
+//gofmt -s
+
+// Test case for issue 7631.
+
+package main
+
+// Keep this declaration
+var ()
+
+const (
+// Keep this declaration
+)
+
+type ()
+
+func main() {} \ No newline at end of file
diff --git a/src/cmd/gofmt/testdata/go2numbers.golden b/src/cmd/gofmt/testdata/go2numbers.golden
new file mode 100644
index 0000000..0184aaa
--- /dev/null
+++ b/src/cmd/gofmt/testdata/go2numbers.golden
@@ -0,0 +1,186 @@
+package p
+
+const (
+ // 0-octals
+ _ = 0
+ _ = 0123
+ _ = 0123456
+
+ _ = 0_123
+ _ = 0123_456
+
+ // decimals
+ _ = 1
+ _ = 1234
+ _ = 1234567
+
+ _ = 1_234
+ _ = 1_234_567
+
+ // hexadecimals
+ _ = 0x0
+ _ = 0x1234
+ _ = 0xcafef00d
+
+ _ = 0x0
+ _ = 0x1234
+ _ = 0xCAFEf00d
+
+ _ = 0x_0
+ _ = 0x_1234
+ _ = 0x_CAFE_f00d
+
+ // octals
+ _ = 0o0
+ _ = 0o1234
+ _ = 0o01234567
+
+ _ = 0o0
+ _ = 0o1234
+ _ = 0o01234567
+
+ _ = 0o_0
+ _ = 0o_1234
+ _ = 0o0123_4567
+
+ _ = 0o_0
+ _ = 0o_1234
+ _ = 0o0123_4567
+
+ // binaries
+ _ = 0b0
+ _ = 0b1011
+ _ = 0b00101101
+
+ _ = 0b0
+ _ = 0b1011
+ _ = 0b00101101
+
+ _ = 0b_0
+ _ = 0b10_11
+ _ = 0b_0010_1101
+
+ // decimal floats
+ _ = 0.
+ _ = 123.
+ _ = 0123.
+
+ _ = .0
+ _ = .123
+ _ = .0123
+
+ _ = 0e0
+ _ = 123e+0
+ _ = 0123e-1
+
+ _ = 0e-0
+ _ = 123e+0
+ _ = 0123e123
+
+ _ = 0.e+1
+ _ = 123.e-10
+ _ = 0123.e123
+
+ _ = .0e-1
+ _ = .123e+10
+ _ = .0123e123
+
+ _ = 0.0
+ _ = 123.123
+ _ = 0123.0123
+
+ _ = 0.0e1
+ _ = 123.123e-10
+ _ = 0123.0123e+456
+
+ _ = 1_2_3.
+ _ = 0_123.
+
+ _ = 0_0e0
+ _ = 1_2_3e0
+ _ = 0_123e0
+
+ _ = 0e-0_0
+ _ = 1_2_3e+0
+ _ = 0123e1_2_3
+
+ _ = 0.e+1
+ _ = 123.e-1_0
+ _ = 01_23.e123
+
+ _ = .0e-1
+ _ = .123e+10
+ _ = .0123e123
+
+ _ = 1_2_3.123
+ _ = 0123.01_23
+
+ // hexadecimal floats
+ _ = 0x0.p+0
+ _ = 0xdeadcafe.p-10
+ _ = 0x1234.p123
+
+ _ = 0x.1p-0
+ _ = 0x.deadcafep2
+ _ = 0x.1234p+10
+
+ _ = 0x0p0
+ _ = 0xdeadcafep+1
+ _ = 0x1234p-10
+
+ _ = 0x0.0p0
+ _ = 0xdead.cafep+1
+ _ = 0x12.34p-10
+
+ _ = 0xdead_cafep+1
+ _ = 0x_1234p-10
+
+ _ = 0x_dead_cafe.p-10
+ _ = 0x12_34.p1_2_3
+ _ = 0x1_2_3_4.p-1_2_3
+
+ // imaginaries
+ _ = 0i
+ _ = 0i
+ _ = 8i
+ _ = 0i
+ _ = 123i
+ _ = 123i
+ _ = 56789i
+ _ = 1234i
+ _ = 1234567i
+
+ _ = 0i
+ _ = 0i
+ _ = 8i
+ _ = 0i
+ _ = 123i
+ _ = 123i
+ _ = 56_789i
+ _ = 1_234i
+ _ = 1_234_567i
+
+ _ = 0.i
+ _ = 123.i
+ _ = 0123.i
+ _ = 000123.i
+
+ _ = 0e0i
+ _ = 123e0i
+ _ = 0123e0i
+ _ = 000123e0i
+
+ _ = 0.e+1i
+ _ = 123.e-1_0i
+ _ = 01_23.e123i
+ _ = 00_01_23.e123i
+
+ _ = 0b1010i
+ _ = 0b1010i
+ _ = 0o660i
+ _ = 0o660i
+ _ = 0xabcDEFi
+ _ = 0xabcDEFi
+ _ = 0xabcDEFp0i
+ _ = 0xabcDEFp0i
+)
diff --git a/src/cmd/gofmt/testdata/go2numbers.input b/src/cmd/gofmt/testdata/go2numbers.input
new file mode 100644
index 0000000..f3e7828
--- /dev/null
+++ b/src/cmd/gofmt/testdata/go2numbers.input
@@ -0,0 +1,186 @@
+package p
+
+const (
+ // 0-octals
+ _ = 0
+ _ = 0123
+ _ = 0123456
+
+ _ = 0_123
+ _ = 0123_456
+
+ // decimals
+ _ = 1
+ _ = 1234
+ _ = 1234567
+
+ _ = 1_234
+ _ = 1_234_567
+
+ // hexadecimals
+ _ = 0x0
+ _ = 0x1234
+ _ = 0xcafef00d
+
+ _ = 0X0
+ _ = 0X1234
+ _ = 0XCAFEf00d
+
+ _ = 0X_0
+ _ = 0X_1234
+ _ = 0X_CAFE_f00d
+
+ // octals
+ _ = 0o0
+ _ = 0o1234
+ _ = 0o01234567
+
+ _ = 0O0
+ _ = 0O1234
+ _ = 0O01234567
+
+ _ = 0o_0
+ _ = 0o_1234
+ _ = 0o0123_4567
+
+ _ = 0O_0
+ _ = 0O_1234
+ _ = 0O0123_4567
+
+ // binaries
+ _ = 0b0
+ _ = 0b1011
+ _ = 0b00101101
+
+ _ = 0B0
+ _ = 0B1011
+ _ = 0B00101101
+
+ _ = 0b_0
+ _ = 0b10_11
+ _ = 0b_0010_1101
+
+ // decimal floats
+ _ = 0.
+ _ = 123.
+ _ = 0123.
+
+ _ = .0
+ _ = .123
+ _ = .0123
+
+ _ = 0e0
+ _ = 123e+0
+ _ = 0123E-1
+
+ _ = 0e-0
+ _ = 123E+0
+ _ = 0123E123
+
+ _ = 0.e+1
+ _ = 123.E-10
+ _ = 0123.e123
+
+ _ = .0e-1
+ _ = .123E+10
+ _ = .0123E123
+
+ _ = 0.0
+ _ = 123.123
+ _ = 0123.0123
+
+ _ = 0.0e1
+ _ = 123.123E-10
+ _ = 0123.0123e+456
+
+ _ = 1_2_3.
+ _ = 0_123.
+
+ _ = 0_0e0
+ _ = 1_2_3e0
+ _ = 0_123e0
+
+ _ = 0e-0_0
+ _ = 1_2_3E+0
+ _ = 0123E1_2_3
+
+ _ = 0.e+1
+ _ = 123.E-1_0
+ _ = 01_23.e123
+
+ _ = .0e-1
+ _ = .123E+10
+ _ = .0123E123
+
+ _ = 1_2_3.123
+ _ = 0123.01_23
+
+ // hexadecimal floats
+ _ = 0x0.p+0
+ _ = 0Xdeadcafe.p-10
+ _ = 0x1234.P123
+
+ _ = 0x.1p-0
+ _ = 0X.deadcafep2
+ _ = 0x.1234P+10
+
+ _ = 0x0p0
+ _ = 0Xdeadcafep+1
+ _ = 0x1234P-10
+
+ _ = 0x0.0p0
+ _ = 0Xdead.cafep+1
+ _ = 0x12.34P-10
+
+ _ = 0Xdead_cafep+1
+ _ = 0x_1234P-10
+
+ _ = 0X_dead_cafe.p-10
+ _ = 0x12_34.P1_2_3
+ _ = 0X1_2_3_4.P-1_2_3
+
+ // imaginaries
+ _ = 0i
+ _ = 00i
+ _ = 08i
+ _ = 0000000000i
+ _ = 0123i
+ _ = 0000000123i
+ _ = 0000056789i
+ _ = 1234i
+ _ = 1234567i
+
+ _ = 0i
+ _ = 0_0i
+ _ = 0_8i
+ _ = 0_000_000_000i
+ _ = 0_123i
+ _ = 0_000_000_123i
+ _ = 0_000_056_789i
+ _ = 1_234i
+ _ = 1_234_567i
+
+ _ = 0.i
+ _ = 123.i
+ _ = 0123.i
+ _ = 000123.i
+
+ _ = 0e0i
+ _ = 123e0i
+ _ = 0123E0i
+ _ = 000123E0i
+
+ _ = 0.e+1i
+ _ = 123.E-1_0i
+ _ = 01_23.e123i
+ _ = 00_01_23.e123i
+
+ _ = 0b1010i
+ _ = 0B1010i
+ _ = 0o660i
+ _ = 0O660i
+ _ = 0xabcDEFi
+ _ = 0XabcDEFi
+ _ = 0xabcDEFP0i
+ _ = 0XabcDEFp0i
+)
diff --git a/src/cmd/gofmt/testdata/import.golden b/src/cmd/gofmt/testdata/import.golden
new file mode 100644
index 0000000..1125b70
--- /dev/null
+++ b/src/cmd/gofmt/testdata/import.golden
@@ -0,0 +1,194 @@
+// package comment
+package main
+
+import (
+ "errors"
+ "fmt"
+ "io"
+ "log"
+ "math"
+)
+
+import (
+ "fmt"
+
+ "math"
+
+ "log"
+
+ "errors"
+
+ "io"
+)
+
+// We reset the line numbering to test that
+// the formatting works independent of line directives
+//line :19
+
+import (
+ "errors"
+ "fmt"
+ "io"
+ "log"
+ "math"
+
+ "fmt"
+
+ "math"
+
+ "log"
+
+ "errors"
+
+ "io"
+)
+
+import (
+ // a block with comments
+ "errors"
+ "fmt" // for Printf
+ "io" // for Reader
+ "log" // for Fatal
+ "math"
+)
+
+import (
+ "fmt" // for Printf
+
+ "math"
+
+ "log" // for Fatal
+
+ "errors"
+
+ "io" // for Reader
+)
+
+import (
+ // for Printf
+ "fmt"
+
+ "math"
+
+ // for Fatal
+ "log"
+
+ "errors"
+
+ // for Reader
+ "io"
+)
+
+import (
+ "errors"
+ "fmt" // for Printf
+ "io" // for Reader
+ "log" // for Fatal
+ "math"
+
+ "fmt" // for Printf
+
+ "math"
+
+ "log" // for Fatal
+
+ "errors"
+
+ "io" // for Reader
+)
+
+import (
+ "fmt" // for Printf
+
+ "errors"
+ "io" // for Reader
+ "log" // for Fatal
+ "math"
+
+ "errors"
+ "fmt" // for Printf
+ "io" // for Reader
+ "log" // for Fatal
+ "math"
+)
+
+// Test deduping and extended sorting
+import (
+ a "A" // aA
+ b "A" // bA1
+ b "A" // bA2
+ "B" // B
+ . "B" // .B
+ _ "B" // _b
+ "C"
+ a "D" // aD
+)
+
+import (
+ "dedup_by_group"
+
+ "dedup_by_group"
+)
+
+import (
+ "fmt" // for Printf
+ /* comment */ io1 "io"
+ /* comment */ io2 "io"
+ /* comment */ "log"
+)
+
+import (
+ "fmt"
+ /* comment */ io1 "io"
+ /* comment */ io2 "io" // hello
+ "math" /* right side */
+ // end
+)
+
+import (
+ "errors" // for New
+ "fmt"
+ /* comment */ io1 "io" /* before */ // after
+ io2 "io" // another
+ // end
+)
+
+import (
+ "errors" // for New
+ /* left */ "fmt" /* right */
+ "log" // for Fatal
+ /* left */ "math" /* right */
+)
+
+import /* why */ /* comment here? */ (
+ /* comment */ "fmt"
+ "math"
+)
+
+// Reset it again
+//line :100
+
+// Dedup with different import styles
+import (
+ "path"
+ . "path"
+ _ "path"
+ pathpkg "path"
+)
+
+/* comment */
+import (
+ "fmt"
+ "math" // for Abs
+ // This is a new run
+ "errors"
+ "fmt"
+)
+
+// End an import declaration in the same line
+// as the last import. See golang.org/issue/33538.
+// Note: Must be the last (or 2nd last) line of the file.
+import (
+ "fmt"
+ "math"
+)
diff --git a/src/cmd/gofmt/testdata/import.input b/src/cmd/gofmt/testdata/import.input
new file mode 100644
index 0000000..040b872
--- /dev/null
+++ b/src/cmd/gofmt/testdata/import.input
@@ -0,0 +1,199 @@
+// package comment
+package main
+
+import (
+ "fmt"
+ "math"
+ "log"
+ "errors"
+ "io"
+)
+
+import (
+ "fmt"
+
+ "math"
+
+ "log"
+
+ "errors"
+
+ "io"
+)
+
+// We reset the line numbering to test that
+// the formatting works independent of line directives
+//line :19
+
+import (
+ "fmt"
+ "math"
+ "log"
+ "errors"
+ "io"
+
+ "fmt"
+
+ "math"
+
+ "log"
+
+ "errors"
+
+ "io"
+)
+
+import (
+ // a block with comments
+ "fmt" // for Printf
+ "math"
+ "log" // for Fatal
+ "errors"
+ "io" // for Reader
+)
+
+import (
+ "fmt" // for Printf
+
+ "math"
+
+ "log" // for Fatal
+
+ "errors"
+
+ "io" // for Reader
+)
+
+import (
+ // for Printf
+ "fmt"
+
+ "math"
+
+ // for Fatal
+ "log"
+
+ "errors"
+
+ // for Reader
+ "io"
+)
+
+import (
+ "fmt" // for Printf
+ "math"
+ "log" // for Fatal
+ "errors"
+ "io" // for Reader
+
+ "fmt" // for Printf
+
+ "math"
+
+ "log" // for Fatal
+
+ "errors"
+
+ "io" // for Reader
+)
+
+import (
+ "fmt" // for Printf
+
+ "math"
+ "log" // for Fatal
+ "errors"
+ "io" // for Reader
+
+ "fmt" // for Printf
+ "math"
+ "log" // for Fatal
+ "errors"
+ "io" // for Reader
+)
+
+// Test deduping and extended sorting
+import (
+ "B" // B
+ a "A" // aA
+ b "A" // bA2
+ b "A" // bA1
+ . "B" // .B
+ . "B"
+ "C"
+ "C"
+ "C"
+ a "D" // aD
+ "B"
+ _ "B" // _b
+)
+
+import (
+ "dedup_by_group"
+ "dedup_by_group"
+
+ "dedup_by_group"
+)
+
+import (
+ /* comment */ io1 "io"
+ "fmt" // for Printf
+ /* comment */ "log"
+ /* comment */ io2 "io"
+)
+
+import (
+ /* comment */ io2 "io" // hello
+ /* comment */ io1 "io"
+ "math" /* right side */
+ "fmt"
+ // end
+)
+
+import (
+ /* comment */ io1 "io" /* before */ // after
+ "fmt"
+ "errors" // for New
+ io2 "io" // another
+ // end
+)
+
+import (
+ /* left */ "fmt" /* right */
+ "errors" // for New
+ /* left */ "math" /* right */
+ "log" // for Fatal
+)
+
+import /* why */ /* comment here? */ (
+ /* comment */ "fmt"
+ "math"
+)
+
+// Reset it again
+//line :100
+
+// Dedup with different import styles
+import (
+ "path"
+ . "path"
+ _ "path"
+ "path"
+ pathpkg "path"
+)
+
+/* comment */
+import (
+ "math" // for Abs
+ "fmt"
+ // This is a new run
+ "errors"
+ "fmt"
+ "errors"
+)
+
+// End an import declaration in the same line
+// as the last import. See golang.org/issue/33538.
+// Note: Must be the last (or 2nd last) line of the file.
+import("fmt"
+"math") \ No newline at end of file
diff --git a/src/cmd/gofmt/testdata/issue28082.golden b/src/cmd/gofmt/testdata/issue28082.golden
new file mode 100644
index 0000000..5837fd5
--- /dev/null
+++ b/src/cmd/gofmt/testdata/issue28082.golden
@@ -0,0 +1,13 @@
+// Copyright 2019 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 main
+
+// testcase for issue #28082
+
+func foo() {}
+
+func main() {}
+
+func bar() {}
diff --git a/src/cmd/gofmt/testdata/issue28082.input b/src/cmd/gofmt/testdata/issue28082.input
new file mode 100644
index 0000000..ab7d218
--- /dev/null
+++ b/src/cmd/gofmt/testdata/issue28082.input
@@ -0,0 +1,13 @@
+// Copyright 2019 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 main
+
+// testcase for issue #28082
+
+func foo( ) {}
+
+func main( ) {}
+
+func bar() {}
diff --git a/src/cmd/gofmt/testdata/ranges.golden b/src/cmd/gofmt/testdata/ranges.golden
new file mode 100644
index 0000000..506b3a0
--- /dev/null
+++ b/src/cmd/gofmt/testdata/ranges.golden
@@ -0,0 +1,30 @@
+//gofmt -s
+
+// Test cases for range simplification.
+package p
+
+func _() {
+ for a, b = range x {
+ }
+ for a = range x {
+ }
+ for _, b = range x {
+ }
+ for range x {
+ }
+
+ for a = range x {
+ }
+ for range x {
+ }
+
+ for a, b := range x {
+ }
+ for a := range x {
+ }
+ for _, b := range x {
+ }
+
+ for a := range x {
+ }
+}
diff --git a/src/cmd/gofmt/testdata/ranges.input b/src/cmd/gofmt/testdata/ranges.input
new file mode 100644
index 0000000..df5f833
--- /dev/null
+++ b/src/cmd/gofmt/testdata/ranges.input
@@ -0,0 +1,20 @@
+//gofmt -s
+
+// Test cases for range simplification.
+package p
+
+func _() {
+ for a, b = range x {}
+ for a, _ = range x {}
+ for _, b = range x {}
+ for _, _ = range x {}
+
+ for a = range x {}
+ for _ = range x {}
+
+ for a, b := range x {}
+ for a, _ := range x {}
+ for _, b := range x {}
+
+ for a := range x {}
+}
diff --git a/src/cmd/gofmt/testdata/rewrite1.golden b/src/cmd/gofmt/testdata/rewrite1.golden
new file mode 100644
index 0000000..3ee5373
--- /dev/null
+++ b/src/cmd/gofmt/testdata/rewrite1.golden
@@ -0,0 +1,14 @@
+//gofmt -r=Foo->Bar
+
+// Copyright 2011 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 main
+
+type Bar int
+
+func main() {
+ var a Bar
+ println(a)
+}
diff --git a/src/cmd/gofmt/testdata/rewrite1.input b/src/cmd/gofmt/testdata/rewrite1.input
new file mode 100644
index 0000000..a84c8f7
--- /dev/null
+++ b/src/cmd/gofmt/testdata/rewrite1.input
@@ -0,0 +1,14 @@
+//gofmt -r=Foo->Bar
+
+// Copyright 2011 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 main
+
+type Foo int
+
+func main() {
+ var a Foo
+ println(a)
+}
diff --git a/src/cmd/gofmt/testdata/rewrite10.golden b/src/cmd/gofmt/testdata/rewrite10.golden
new file mode 100644
index 0000000..1dd781f
--- /dev/null
+++ b/src/cmd/gofmt/testdata/rewrite10.golden
@@ -0,0 +1,19 @@
+//gofmt -r=a->a
+
+// Copyright 2019 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.
+
+// Issue 33103, 33104, and 33105.
+
+package pkg
+
+func fn() {
+ _ = func() {
+ switch {
+ default:
+ }
+ }
+ _ = func() string {}
+ _ = func() { var ptr *string; println(ptr) }
+}
diff --git a/src/cmd/gofmt/testdata/rewrite10.input b/src/cmd/gofmt/testdata/rewrite10.input
new file mode 100644
index 0000000..1dd781f
--- /dev/null
+++ b/src/cmd/gofmt/testdata/rewrite10.input
@@ -0,0 +1,19 @@
+//gofmt -r=a->a
+
+// Copyright 2019 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.
+
+// Issue 33103, 33104, and 33105.
+
+package pkg
+
+func fn() {
+ _ = func() {
+ switch {
+ default:
+ }
+ }
+ _ = func() string {}
+ _ = func() { var ptr *string; println(ptr) }
+}
diff --git a/src/cmd/gofmt/testdata/rewrite2.golden b/src/cmd/gofmt/testdata/rewrite2.golden
new file mode 100644
index 0000000..f980e03
--- /dev/null
+++ b/src/cmd/gofmt/testdata/rewrite2.golden
@@ -0,0 +1,12 @@
+//gofmt -r=int->bool
+
+// Copyright 2011 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 p
+
+// Slices have nil Len values in the corresponding ast.ArrayType
+// node and reflect.NewValue(slice.Len) is an invalid reflect.Value.
+// The rewriter must not crash in that case. Was issue 1696.
+func f() []bool {}
diff --git a/src/cmd/gofmt/testdata/rewrite2.input b/src/cmd/gofmt/testdata/rewrite2.input
new file mode 100644
index 0000000..489be4e
--- /dev/null
+++ b/src/cmd/gofmt/testdata/rewrite2.input
@@ -0,0 +1,12 @@
+//gofmt -r=int->bool
+
+// Copyright 2011 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 p
+
+// Slices have nil Len values in the corresponding ast.ArrayType
+// node and reflect.NewValue(slice.Len) is an invalid reflect.Value.
+// The rewriter must not crash in that case. Was issue 1696.
+func f() []int {}
diff --git a/src/cmd/gofmt/testdata/rewrite3.golden b/src/cmd/gofmt/testdata/rewrite3.golden
new file mode 100644
index 0000000..261a220
--- /dev/null
+++ b/src/cmd/gofmt/testdata/rewrite3.golden
@@ -0,0 +1,14 @@
+//gofmt -r=x->x
+
+// Copyright 2011 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 main
+
+// Field tags are *ast.BasicLit nodes that are nil when the tag is
+// absent. These nil nodes must not be mistaken for expressions,
+// the rewriter should not try to dereference them. Was issue 2410.
+type Foo struct {
+ Field int
+}
diff --git a/src/cmd/gofmt/testdata/rewrite3.input b/src/cmd/gofmt/testdata/rewrite3.input
new file mode 100644
index 0000000..261a220
--- /dev/null
+++ b/src/cmd/gofmt/testdata/rewrite3.input
@@ -0,0 +1,14 @@
+//gofmt -r=x->x
+
+// Copyright 2011 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 main
+
+// Field tags are *ast.BasicLit nodes that are nil when the tag is
+// absent. These nil nodes must not be mistaken for expressions,
+// the rewriter should not try to dereference them. Was issue 2410.
+type Foo struct {
+ Field int
+}
diff --git a/src/cmd/gofmt/testdata/rewrite4.golden b/src/cmd/gofmt/testdata/rewrite4.golden
new file mode 100644
index 0000000..b05547b
--- /dev/null
+++ b/src/cmd/gofmt/testdata/rewrite4.golden
@@ -0,0 +1,76 @@
+//gofmt -r=(x)->x
+
+// Copyright 2012 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.
+
+// Rewriting of parenthesized expressions (x) -> x
+// must not drop parentheses if that would lead to
+// wrong association of the operands.
+// Was issue 1847.
+
+package main
+
+// From example 1 of issue 1847.
+func _() {
+ var t = (&T{1000}).Id()
+}
+
+// From example 2 of issue 1847.
+func _() {
+ fmt.Println((*xpp).a)
+}
+
+// Some more test cases.
+func _() {
+ _ = (-x).f
+ _ = (*x).f
+ _ = (&x).f
+ _ = (!x).f
+ _ = -x.f
+ _ = *x.f
+ _ = &x.f
+ _ = !x.f
+ (-x).f()
+ (*x).f()
+ (&x).f()
+ (!x).f()
+ _ = -x.f()
+ _ = *x.f()
+ _ = &x.f()
+ _ = !x.f()
+
+ _ = (-x).f
+ _ = (*x).f
+ _ = (&x).f
+ _ = (!x).f
+ _ = -x.f
+ _ = *x.f
+ _ = &x.f
+ _ = !x.f
+ (-x).f()
+ (*x).f()
+ (&x).f()
+ (!x).f()
+ _ = -x.f()
+ _ = *x.f()
+ _ = &x.f()
+ _ = !x.f()
+
+ _ = -x.f
+ _ = *x.f
+ _ = &x.f
+ _ = !x.f
+ _ = -x.f
+ _ = *x.f
+ _ = &x.f
+ _ = !x.f
+ _ = -x.f()
+ _ = *x.f()
+ _ = &x.f()
+ _ = !x.f()
+ _ = -x.f()
+ _ = *x.f()
+ _ = &x.f()
+ _ = !x.f()
+}
diff --git a/src/cmd/gofmt/testdata/rewrite4.input b/src/cmd/gofmt/testdata/rewrite4.input
new file mode 100644
index 0000000..0817099
--- /dev/null
+++ b/src/cmd/gofmt/testdata/rewrite4.input
@@ -0,0 +1,76 @@
+//gofmt -r=(x)->x
+
+// Copyright 2012 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.
+
+// Rewriting of parenthesized expressions (x) -> x
+// must not drop parentheses if that would lead to
+// wrong association of the operands.
+// Was issue 1847.
+
+package main
+
+// From example 1 of issue 1847.
+func _() {
+ var t = (&T{1000}).Id()
+}
+
+// From example 2 of issue 1847.
+func _() {
+ fmt.Println((*xpp).a)
+}
+
+// Some more test cases.
+func _() {
+ _ = (-x).f
+ _ = (*x).f
+ _ = (&x).f
+ _ = (!x).f
+ _ = (-x.f)
+ _ = (*x.f)
+ _ = (&x.f)
+ _ = (!x.f)
+ (-x).f()
+ (*x).f()
+ (&x).f()
+ (!x).f()
+ _ = (-x.f())
+ _ = (*x.f())
+ _ = (&x.f())
+ _ = (!x.f())
+
+ _ = ((-x)).f
+ _ = ((*x)).f
+ _ = ((&x)).f
+ _ = ((!x)).f
+ _ = ((-x.f))
+ _ = ((*x.f))
+ _ = ((&x.f))
+ _ = ((!x.f))
+ ((-x)).f()
+ ((*x)).f()
+ ((&x)).f()
+ ((!x)).f()
+ _ = ((-x.f()))
+ _ = ((*x.f()))
+ _ = ((&x.f()))
+ _ = ((!x.f()))
+
+ _ = -(x).f
+ _ = *(x).f
+ _ = &(x).f
+ _ = !(x).f
+ _ = -x.f
+ _ = *x.f
+ _ = &x.f
+ _ = !x.f
+ _ = -(x).f()
+ _ = *(x).f()
+ _ = &(x).f()
+ _ = !(x).f()
+ _ = -x.f()
+ _ = *x.f()
+ _ = &x.f()
+ _ = !x.f()
+}
diff --git a/src/cmd/gofmt/testdata/rewrite5.golden b/src/cmd/gofmt/testdata/rewrite5.golden
new file mode 100644
index 0000000..9beb34a
--- /dev/null
+++ b/src/cmd/gofmt/testdata/rewrite5.golden
@@ -0,0 +1,17 @@
+//gofmt -r=x+x->2*x
+
+// Copyright 2011 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.
+
+// Rewriting of expressions containing nodes with associated comments to
+// expressions without those nodes must also eliminate the associated
+// comments.
+
+package p
+
+func f(x int) int {
+ _ = 2 * x // this comment remains in the rewrite
+ _ = 2 * x
+ return 2 * x
+}
diff --git a/src/cmd/gofmt/testdata/rewrite5.input b/src/cmd/gofmt/testdata/rewrite5.input
new file mode 100644
index 0000000..d7a6122
--- /dev/null
+++ b/src/cmd/gofmt/testdata/rewrite5.input
@@ -0,0 +1,17 @@
+//gofmt -r=x+x->2*x
+
+// Copyright 2011 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.
+
+// Rewriting of expressions containing nodes with associated comments to
+// expressions without those nodes must also eliminate the associated
+// comments.
+
+package p
+
+func f(x int) int {
+ _ = x + x // this comment remains in the rewrite
+ _ = x /* this comment must not be in the rewrite */ + x
+ return x /* this comment must not be in the rewrite */ + x
+}
diff --git a/src/cmd/gofmt/testdata/rewrite6.golden b/src/cmd/gofmt/testdata/rewrite6.golden
new file mode 100644
index 0000000..48ec9aa
--- /dev/null
+++ b/src/cmd/gofmt/testdata/rewrite6.golden
@@ -0,0 +1,17 @@
+//gofmt -r=fun(x)->Fun(x)
+
+// Copyright 2013 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.
+
+// Rewriting of calls must take the ... (ellipsis)
+// attribute for the last argument into account.
+
+package p
+
+func fun(x []int) {}
+
+func g(x []int) {
+ Fun(x) // -r='fun(x)->Fun(x)' should rewrite this to Fun(x)
+ fun(x...) // -r='fun(x)->Fun(x)' should not rewrite this
+}
diff --git a/src/cmd/gofmt/testdata/rewrite6.input b/src/cmd/gofmt/testdata/rewrite6.input
new file mode 100644
index 0000000..b085a84
--- /dev/null
+++ b/src/cmd/gofmt/testdata/rewrite6.input
@@ -0,0 +1,17 @@
+//gofmt -r=fun(x)->Fun(x)
+
+// Copyright 2013 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.
+
+// Rewriting of calls must take the ... (ellipsis)
+// attribute for the last argument into account.
+
+package p
+
+func fun(x []int) {}
+
+func g(x []int) {
+ fun(x) // -r='fun(x)->Fun(x)' should rewrite this to Fun(x)
+ fun(x...) // -r='fun(x)->Fun(x)' should not rewrite this
+}
diff --git a/src/cmd/gofmt/testdata/rewrite7.golden b/src/cmd/gofmt/testdata/rewrite7.golden
new file mode 100644
index 0000000..8386a0b
--- /dev/null
+++ b/src/cmd/gofmt/testdata/rewrite7.golden
@@ -0,0 +1,17 @@
+//gofmt -r=fun(x...)->Fun(x)
+
+// Copyright 2013 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.
+
+// Rewriting of calls must take the ... (ellipsis)
+// attribute for the last argument into account.
+
+package p
+
+func fun(x []int) {}
+
+func g(x []int) {
+ fun(x) // -r='fun(x...)->Fun(x)' should not rewrite this
+ Fun(x) // -r='fun(x...)->Fun(x)' should rewrite this to Fun(x)
+}
diff --git a/src/cmd/gofmt/testdata/rewrite7.input b/src/cmd/gofmt/testdata/rewrite7.input
new file mode 100644
index 0000000..c198470
--- /dev/null
+++ b/src/cmd/gofmt/testdata/rewrite7.input
@@ -0,0 +1,17 @@
+//gofmt -r=fun(x...)->Fun(x)
+
+// Copyright 2013 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.
+
+// Rewriting of calls must take the ... (ellipsis)
+// attribute for the last argument into account.
+
+package p
+
+func fun(x []int) {}
+
+func g(x []int) {
+ fun(x) // -r='fun(x...)->Fun(x)' should not rewrite this
+ fun(x...) // -r='fun(x...)->Fun(x)' should rewrite this to Fun(x)
+}
diff --git a/src/cmd/gofmt/testdata/rewrite8.golden b/src/cmd/gofmt/testdata/rewrite8.golden
new file mode 100644
index 0000000..62f0419
--- /dev/null
+++ b/src/cmd/gofmt/testdata/rewrite8.golden
@@ -0,0 +1,12 @@
+//gofmt -r=interface{}->int
+
+// Copyright 2013 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.
+
+// Check that literal type expression rewrites are accepted.
+// Was issue 4406.
+
+package p
+
+type T int
diff --git a/src/cmd/gofmt/testdata/rewrite8.input b/src/cmd/gofmt/testdata/rewrite8.input
new file mode 100644
index 0000000..7964c5c
--- /dev/null
+++ b/src/cmd/gofmt/testdata/rewrite8.input
@@ -0,0 +1,12 @@
+//gofmt -r=interface{}->int
+
+// Copyright 2013 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.
+
+// Check that literal type expression rewrites are accepted.
+// Was issue 4406.
+
+package p
+
+type T interface{}
diff --git a/src/cmd/gofmt/testdata/rewrite9.golden b/src/cmd/gofmt/testdata/rewrite9.golden
new file mode 100644
index 0000000..fffbd3d
--- /dev/null
+++ b/src/cmd/gofmt/testdata/rewrite9.golden
@@ -0,0 +1,11 @@
+//gofmt -r=a&&b!=2->a
+
+// Copyright 2017 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.
+
+// Issue 18987.
+
+package p
+
+const _ = x != 1
diff --git a/src/cmd/gofmt/testdata/rewrite9.input b/src/cmd/gofmt/testdata/rewrite9.input
new file mode 100644
index 0000000..106ad94
--- /dev/null
+++ b/src/cmd/gofmt/testdata/rewrite9.input
@@ -0,0 +1,11 @@
+//gofmt -r=a&&b!=2->a
+
+// Copyright 2017 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.
+
+// Issue 18987.
+
+package p
+
+const _ = x != 1 && x != 2
diff --git a/src/cmd/gofmt/testdata/slices1.golden b/src/cmd/gofmt/testdata/slices1.golden
new file mode 100644
index 0000000..04bc16f
--- /dev/null
+++ b/src/cmd/gofmt/testdata/slices1.golden
@@ -0,0 +1,66 @@
+//gofmt -s
+
+// Test cases for slice expression simplification.
+package p
+
+var (
+ a [10]byte
+ b [20]float32
+ s []int
+ t struct {
+ s []byte
+ }
+
+ _ = a[0:]
+ _ = a[1:10]
+ _ = a[2:]
+ _ = a[3:(len(a))]
+ _ = a[len(a) : len(a)-1]
+ _ = a[0:len(b)]
+ _ = a[2:len(a):len(a)]
+
+ _ = a[:]
+ _ = a[:10]
+ _ = a[:]
+ _ = a[:(len(a))]
+ _ = a[:len(a)-1]
+ _ = a[:len(b)]
+ _ = a[:len(a):len(a)]
+
+ _ = s[0:]
+ _ = s[1:10]
+ _ = s[2:]
+ _ = s[3:(len(s))]
+ _ = s[len(a) : len(s)-1]
+ _ = s[0:len(b)]
+ _ = s[2:len(s):len(s)]
+
+ _ = s[:]
+ _ = s[:10]
+ _ = s[:]
+ _ = s[:(len(s))]
+ _ = s[:len(s)-1]
+ _ = s[:len(b)]
+ _ = s[:len(s):len(s)]
+
+ _ = t.s[0:]
+ _ = t.s[1:10]
+ _ = t.s[2:len(t.s)]
+ _ = t.s[3:(len(t.s))]
+ _ = t.s[len(a) : len(t.s)-1]
+ _ = t.s[0:len(b)]
+ _ = t.s[2:len(t.s):len(t.s)]
+
+ _ = t.s[:]
+ _ = t.s[:10]
+ _ = t.s[:len(t.s)]
+ _ = t.s[:(len(t.s))]
+ _ = t.s[:len(t.s)-1]
+ _ = t.s[:len(b)]
+ _ = t.s[:len(t.s):len(t.s)]
+)
+
+func _() {
+ s := s[0:]
+ _ = s
+}
diff --git a/src/cmd/gofmt/testdata/slices1.input b/src/cmd/gofmt/testdata/slices1.input
new file mode 100644
index 0000000..1f25c43
--- /dev/null
+++ b/src/cmd/gofmt/testdata/slices1.input
@@ -0,0 +1,66 @@
+//gofmt -s
+
+// Test cases for slice expression simplification.
+package p
+
+var (
+ a [10]byte
+ b [20]float32
+ s []int
+ t struct {
+ s []byte
+ }
+
+ _ = a[0:]
+ _ = a[1:10]
+ _ = a[2:len(a)]
+ _ = a[3:(len(a))]
+ _ = a[len(a) : len(a)-1]
+ _ = a[0:len(b)]
+ _ = a[2:len(a):len(a)]
+
+ _ = a[:]
+ _ = a[:10]
+ _ = a[:len(a)]
+ _ = a[:(len(a))]
+ _ = a[:len(a)-1]
+ _ = a[:len(b)]
+ _ = a[:len(a):len(a)]
+
+ _ = s[0:]
+ _ = s[1:10]
+ _ = s[2:len(s)]
+ _ = s[3:(len(s))]
+ _ = s[len(a) : len(s)-1]
+ _ = s[0:len(b)]
+ _ = s[2:len(s):len(s)]
+
+ _ = s[:]
+ _ = s[:10]
+ _ = s[:len(s)]
+ _ = s[:(len(s))]
+ _ = s[:len(s)-1]
+ _ = s[:len(b)]
+ _ = s[:len(s):len(s)]
+
+ _ = t.s[0:]
+ _ = t.s[1:10]
+ _ = t.s[2:len(t.s)]
+ _ = t.s[3:(len(t.s))]
+ _ = t.s[len(a) : len(t.s)-1]
+ _ = t.s[0:len(b)]
+ _ = t.s[2:len(t.s):len(t.s)]
+
+ _ = t.s[:]
+ _ = t.s[:10]
+ _ = t.s[:len(t.s)]
+ _ = t.s[:(len(t.s))]
+ _ = t.s[:len(t.s)-1]
+ _ = t.s[:len(b)]
+ _ = t.s[:len(t.s):len(t.s)]
+)
+
+func _() {
+ s := s[0:len(s)]
+ _ = s
+}
diff --git a/src/cmd/gofmt/testdata/stdin1.golden b/src/cmd/gofmt/testdata/stdin1.golden
new file mode 100644
index 0000000..9e4dcd2
--- /dev/null
+++ b/src/cmd/gofmt/testdata/stdin1.golden
@@ -0,0 +1,5 @@
+ //gofmt -stdin
+
+ if x {
+ y
+ }
diff --git a/src/cmd/gofmt/testdata/stdin1.input b/src/cmd/gofmt/testdata/stdin1.input
new file mode 100644
index 0000000..9e4dcd2
--- /dev/null
+++ b/src/cmd/gofmt/testdata/stdin1.input
@@ -0,0 +1,5 @@
+ //gofmt -stdin
+
+ if x {
+ y
+ }
diff --git a/src/cmd/gofmt/testdata/stdin2.golden b/src/cmd/gofmt/testdata/stdin2.golden
new file mode 100644
index 0000000..57df355
--- /dev/null
+++ b/src/cmd/gofmt/testdata/stdin2.golden
@@ -0,0 +1,11 @@
+//gofmt -stdin
+
+var x int
+
+func f() {
+ y := z
+ /* this is a comment */
+ // this is a comment too
+}
+
+
diff --git a/src/cmd/gofmt/testdata/stdin2.input b/src/cmd/gofmt/testdata/stdin2.input
new file mode 100644
index 0000000..69d6bdd
--- /dev/null
+++ b/src/cmd/gofmt/testdata/stdin2.input
@@ -0,0 +1,11 @@
+//gofmt -stdin
+
+var x int
+
+
+func f() { y := z
+ /* this is a comment */
+ // this is a comment too
+}
+
+
diff --git a/src/cmd/gofmt/testdata/stdin3.golden b/src/cmd/gofmt/testdata/stdin3.golden
new file mode 100644
index 0000000..d6da0e4
--- /dev/null
+++ b/src/cmd/gofmt/testdata/stdin3.golden
@@ -0,0 +1,7 @@
+ //gofmt -stdin
+
+ /* note: no newline at end of file */
+ for i := 0; i < 10; i++ {
+ s += i
+ }
+ \ No newline at end of file
diff --git a/src/cmd/gofmt/testdata/stdin3.input b/src/cmd/gofmt/testdata/stdin3.input
new file mode 100644
index 0000000..ab46c10
--- /dev/null
+++ b/src/cmd/gofmt/testdata/stdin3.input
@@ -0,0 +1,5 @@
+ //gofmt -stdin
+
+ /* note: no newline at end of file */
+ for i := 0; i < 10; i++ { s += i }
+ \ No newline at end of file
diff --git a/src/cmd/gofmt/testdata/stdin4.golden b/src/cmd/gofmt/testdata/stdin4.golden
new file mode 100644
index 0000000..0c7acac
--- /dev/null
+++ b/src/cmd/gofmt/testdata/stdin4.golden
@@ -0,0 +1,5 @@
+ //gofmt -stdin
+
+ // comment
+
+ i := 0
diff --git a/src/cmd/gofmt/testdata/stdin4.input b/src/cmd/gofmt/testdata/stdin4.input
new file mode 100644
index 0000000..1fc73f3
--- /dev/null
+++ b/src/cmd/gofmt/testdata/stdin4.input
@@ -0,0 +1,5 @@
+ //gofmt -stdin
+
+ // comment
+
+ i := 0
diff --git a/src/cmd/gofmt/testdata/stdin5.golden b/src/cmd/gofmt/testdata/stdin5.golden
new file mode 100644
index 0000000..31ce6b2
--- /dev/null
+++ b/src/cmd/gofmt/testdata/stdin5.golden
@@ -0,0 +1,3 @@
+//gofmt -stdin
+
+i := 5 // Line comment without newline. \ No newline at end of file
diff --git a/src/cmd/gofmt/testdata/stdin5.input b/src/cmd/gofmt/testdata/stdin5.input
new file mode 100644
index 0000000..0a7c97d
--- /dev/null
+++ b/src/cmd/gofmt/testdata/stdin5.input
@@ -0,0 +1,3 @@
+//gofmt -stdin
+
+i :=5// Line comment without newline. \ No newline at end of file
diff --git a/src/cmd/gofmt/testdata/stdin6.golden b/src/cmd/gofmt/testdata/stdin6.golden
new file mode 100644
index 0000000..ffcea80
--- /dev/null
+++ b/src/cmd/gofmt/testdata/stdin6.golden
@@ -0,0 +1,19 @@
+ //gofmt -stdin
+
+ if err != nil {
+ source := strings.NewReader(`line 1.
+line 2.
+`)
+ return source
+ }
+
+ f := func(hat, tail string) {
+
+ fmt.Println(hat+`
+foo
+
+
+`+tail,
+ "more",
+ "and more")
+ }
diff --git a/src/cmd/gofmt/testdata/stdin6.input b/src/cmd/gofmt/testdata/stdin6.input
new file mode 100644
index 0000000..7833002
--- /dev/null
+++ b/src/cmd/gofmt/testdata/stdin6.input
@@ -0,0 +1,21 @@
+ //gofmt -stdin
+
+ if err != nil {
+ source := strings.NewReader(`line 1.
+line 2.
+`)
+ return source
+ }
+
+ f:=func( hat, tail string){
+
+
+
+ fmt. Println ( hat+ `
+foo
+
+
+`+ tail ,
+ "more" ,
+ "and more" )
+ }
diff --git a/src/cmd/gofmt/testdata/stdin7.golden b/src/cmd/gofmt/testdata/stdin7.golden
new file mode 100644
index 0000000..bbac713
--- /dev/null
+++ b/src/cmd/gofmt/testdata/stdin7.golden
@@ -0,0 +1,19 @@
+ //gofmt -stdin
+
+ if err != nil {
+ source := strings.NewReader(`line 1.
+line 2.
+`)
+ return source
+ }
+
+ f := func(hat, tail string) {
+
+ fmt.Println(hat+`
+ foo
+
+
+ `+tail,
+ "more",
+ "and more")
+ }
diff --git a/src/cmd/gofmt/testdata/stdin7.input b/src/cmd/gofmt/testdata/stdin7.input
new file mode 100644
index 0000000..fd772a3
--- /dev/null
+++ b/src/cmd/gofmt/testdata/stdin7.input
@@ -0,0 +1,21 @@
+ //gofmt -stdin
+
+ if err != nil {
+ source := strings.NewReader(`line 1.
+line 2.
+`)
+ return source
+ }
+
+ f:=func( hat, tail string){
+
+
+
+ fmt. Println ( hat+ `
+ foo
+
+
+ `+ tail ,
+ "more" ,
+ "and more" )
+ }
diff --git a/src/cmd/gofmt/testdata/tabs.golden b/src/cmd/gofmt/testdata/tabs.golden
new file mode 100644
index 0000000..287678c
--- /dev/null
+++ b/src/cmd/gofmt/testdata/tabs.golden
@@ -0,0 +1,33 @@
+// Copyright 2022 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.
+
+//gofmt
+
+package main
+
+var _ = []struct {
+ S string
+ Integer int
+}{
+ {
+ S: "Hello World",
+ Integer: 42,
+ },
+ {
+ S: "\t",
+ Integer: 42,
+ },
+ {
+ S: " ", // an actual <tab>
+ Integer: 42,
+ },
+ {
+ S: ` `, // an actual <tab>
+ Integer: 42,
+ },
+ {
+ S: "\u0009",
+ Integer: 42,
+ },
+}
diff --git a/src/cmd/gofmt/testdata/tabs.input b/src/cmd/gofmt/testdata/tabs.input
new file mode 100644
index 0000000..635be79
--- /dev/null
+++ b/src/cmd/gofmt/testdata/tabs.input
@@ -0,0 +1,33 @@
+// Copyright 2022 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.
+
+//gofmt
+
+package main
+
+var _ = []struct{
+ S string
+ Integer int
+}{
+ {
+ S: "Hello World",
+ Integer: 42,
+ },
+ {
+ S: "\t",
+ Integer: 42,
+ },
+ {
+ S: " ", // an actual <tab>
+ Integer: 42,
+ },
+ {
+ S: ` `, // an actual <tab>
+ Integer: 42,
+ },
+ {
+ S: "\u0009",
+ Integer: 42,
+ },
+}
diff --git a/src/cmd/gofmt/testdata/typealias.golden b/src/cmd/gofmt/testdata/typealias.golden
new file mode 100644
index 0000000..bbbbf32
--- /dev/null
+++ b/src/cmd/gofmt/testdata/typealias.golden
@@ -0,0 +1,24 @@
+package q
+
+import "p"
+
+type _ = int
+type a = struct{ x int }
+type b = p.B
+
+type (
+ _ = chan<- int
+ aa = interface{}
+ bb = p.BB
+)
+
+// TODO(gri) We may want to put the '=' into a separate column if
+// we have mixed (regular and alias) type declarations in a group.
+type (
+ _ chan<- int
+ _ = chan<- int
+ aa0 interface{}
+ aaa = interface{}
+ bb0 p.BB
+ bbb = p.BB
+)
diff --git a/src/cmd/gofmt/testdata/typealias.input b/src/cmd/gofmt/testdata/typealias.input
new file mode 100644
index 0000000..6e49328
--- /dev/null
+++ b/src/cmd/gofmt/testdata/typealias.input
@@ -0,0 +1,24 @@
+package q
+
+import "p"
+
+type _ = int
+type a = struct{ x int }
+type b = p.B
+
+type (
+ _ = chan<- int
+ aa = interface{}
+ bb = p.BB
+)
+
+// TODO(gri) We may want to put the '=' into a separate column if
+// we have mixed (regular and alias) type declarations in a group.
+type (
+ _ chan<- int
+ _ = chan<- int
+ aa0 interface{}
+ aaa = interface{}
+ bb0 p.BB
+ bbb = p.BB
+)
diff --git a/src/cmd/gofmt/testdata/typeparams.golden b/src/cmd/gofmt/testdata/typeparams.golden
new file mode 100644
index 0000000..d57a2ba
--- /dev/null
+++ b/src/cmd/gofmt/testdata/typeparams.golden
@@ -0,0 +1,35 @@
+// Copyright 2020 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.
+
+//gofmt
+
+package typeparams
+
+type T[P any] struct{}
+type T[P1, P2, P3 any] struct{}
+
+type T[P C] struct{}
+type T[P1, P2, P3 C] struct{}
+
+type T[P C[P]] struct{}
+type T[P1, P2, P3 C[P1, P2, P3]] struct{}
+
+func f[P any](x P)
+func f[P1, P2, P3 any](x1 P1, x2 P2, x3 P3) struct{}
+
+func f[P interface{}](x P)
+func f[P1, P2, P3 interface {
+ m1(P1)
+ ~P2 | ~P3
+}](x1 P1, x2 P2, x3 P3) struct{}
+func f[P any](T1[P], T2[P]) T3[P]
+
+func (x T[P]) m()
+func (T[P]) m(x T[P]) P
+
+func _() {
+ type _ []T[P]
+ var _ []T[P]
+ _ = []T[P]{}
+}
diff --git a/src/cmd/gofmt/testdata/typeparams.input b/src/cmd/gofmt/testdata/typeparams.input
new file mode 100644
index 0000000..775cf9e
--- /dev/null
+++ b/src/cmd/gofmt/testdata/typeparams.input
@@ -0,0 +1,32 @@
+// Copyright 2020 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.
+
+//gofmt
+
+package typeparams
+
+type T[ P any] struct{}
+type T[P1, P2, P3 any] struct{}
+
+type T[P C] struct{}
+type T[P1,P2, P3 C] struct{}
+
+type T[P C[P]] struct{}
+type T[P1, P2, P3 C[P1,P2,P3]] struct{}
+
+func f[P any](x P)
+func f[P1, P2, P3 any](x1 P1, x2 P2, x3 P3) struct{}
+
+func f[P interface{}](x P)
+func f[P1, P2, P3 interface{ m1(P1); ~P2|~P3 }](x1 P1, x2 P2, x3 P3) struct{}
+func f[P any](T1[P], T2[P]) T3[P]
+
+func (x T[P]) m()
+func ((T[P])) m(x T[P]) P
+
+func _() {
+ type _ []T[P]
+ var _ []T[P]
+ _ = []T[P]{}
+}
diff --git a/src/cmd/gofmt/testdata/typeswitch.golden b/src/cmd/gofmt/testdata/typeswitch.golden
new file mode 100644
index 0000000..3cf4dca
--- /dev/null
+++ b/src/cmd/gofmt/testdata/typeswitch.golden
@@ -0,0 +1,60 @@
+/*
+Parenthesized type switch expressions originally
+accepted by gofmt must continue to be rewritten
+into the correct unparenthesized form.
+
+Only type-switches that didn't declare a variable
+in the type switch type assertion and which
+contained only "expression-like" (named) types in their
+cases were permitted to have their type assertion parenthesized
+by go/parser (due to a weak predicate in the parser). All others
+were rejected always, either with a syntax error in the
+type switch header or in the case.
+
+See also issue 4470.
+*/
+package p
+
+func f() {
+ var x interface{}
+ switch x.(type) { // should remain the same
+ }
+ switch x.(type) { // should become: switch x.(type) {
+ }
+
+ switch x.(type) { // should remain the same
+ case int:
+ }
+ switch x.(type) { // should become: switch x.(type) {
+ case int:
+ }
+
+ switch x.(type) { // should remain the same
+ case []int:
+ }
+
+ // Parenthesized (x.(type)) in type switches containing cases
+ // with unnamed (literal) types were never permitted by gofmt;
+ // thus there won't be any code in the wild using this style if
+ // the code was gofmt-ed.
+ /*
+ switch (x.(type)) {
+ case []int:
+ }
+ */
+
+ switch t := x.(type) { // should remain the same
+ default:
+ _ = t
+ }
+
+ // Parenthesized (x.(type)) in type switches declaring a variable
+ // were never permitted by gofmt; thus there won't be any code in
+ // the wild using this style if the code was gofmt-ed.
+ /*
+ switch t := (x.(type)) {
+ default:
+ _ = t
+ }
+ */
+}
diff --git a/src/cmd/gofmt/testdata/typeswitch.input b/src/cmd/gofmt/testdata/typeswitch.input
new file mode 100644
index 0000000..992a772
--- /dev/null
+++ b/src/cmd/gofmt/testdata/typeswitch.input
@@ -0,0 +1,60 @@
+/*
+Parenthesized type switch expressions originally
+accepted by gofmt must continue to be rewritten
+into the correct unparenthesized form.
+
+Only type-switches that didn't declare a variable
+in the type switch type assertion and which
+contained only "expression-like" (named) types in their
+cases were permitted to have their type assertion parenthesized
+by go/parser (due to a weak predicate in the parser). All others
+were rejected always, either with a syntax error in the
+type switch header or in the case.
+
+See also issue 4470.
+*/
+package p
+
+func f() {
+ var x interface{}
+ switch x.(type) { // should remain the same
+ }
+ switch (x.(type)) { // should become: switch x.(type) {
+ }
+
+ switch x.(type) { // should remain the same
+ case int:
+ }
+ switch (x.(type)) { // should become: switch x.(type) {
+ case int:
+ }
+
+ switch x.(type) { // should remain the same
+ case []int:
+ }
+
+ // Parenthesized (x.(type)) in type switches containing cases
+ // with unnamed (literal) types were never permitted by gofmt;
+ // thus there won't be any code in the wild using this style if
+ // the code was gofmt-ed.
+ /*
+ switch (x.(type)) {
+ case []int:
+ }
+ */
+
+ switch t := x.(type) { // should remain the same
+ default:
+ _ = t
+ }
+
+ // Parenthesized (x.(type)) in type switches declaring a variable
+ // were never permitted by gofmt; thus there won't be any code in
+ // the wild using this style if the code was gofmt-ed.
+ /*
+ switch t := (x.(type)) {
+ default:
+ _ = t
+ }
+ */
+}