OLD | NEW |
1 // Copyright 2012 The Go Authors. All rights reserved. | 1 // Copyright 2012 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package format | 5 package format |
6 | 6 |
7 import ( | 7 import ( |
8 "bytes" | 8 "bytes" |
9 "go/parser" | 9 "go/parser" |
10 "go/token" | 10 "go/token" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 | 80 |
81 // statement lists | 81 // statement lists |
82 "x := 0", | 82 "x := 0", |
83 "f(a, b, c)\nvar x int = f(1, 2, 3)", | 83 "f(a, b, c)\nvar x int = f(1, 2, 3)", |
84 | 84 |
85 // indentation, leading and trailing space | 85 // indentation, leading and trailing space |
86 "\tx := 0\n\tgo f()", | 86 "\tx := 0\n\tgo f()", |
87 "\tx := 0\n\tgo f()\n\n\n", | 87 "\tx := 0\n\tgo f()\n\n\n", |
88 "\n\t\t\n\n\tx := 0\n\tgo f()\n\n\n", | 88 "\n\t\t\n\n\tx := 0\n\tgo f()\n\n\n", |
89 "\n\t\t\n\n\t\t\tx := 0\n\t\t\tgo f()\n\n\n", | 89 "\n\t\t\n\n\t\t\tx := 0\n\t\t\tgo f()\n\n\n", |
90 » "\n\t\t\n\n\t\t\tx := 0\n\t\t\tconst s = `\nfoo\n`\n\n\n", // no indenta
tion inside raw strings | 90 » "\n\t\t\n\n\t\t\tx := 0\n\t\t\tconst s = `\nfoo\n`\n\n\n", // no ind
entation added inside raw strings |
| 91 » "\n\t\t\n\n\t\t\tx := 0\n\t\t\tconst s = `\n\t\tfoo\n`\n\n\n", // no ind
entation removed inside raw strings |
| 92 |
| 93 » // comments |
| 94 » "i := 5 /* Comment */", // Issue 5551. |
91 | 95 |
92 // erroneous programs | 96 // erroneous programs |
93 "ERROR1 + 2 +", | 97 "ERROR1 + 2 +", |
94 "ERRORx := 0", | 98 "ERRORx := 0", |
95 } | 99 } |
96 | 100 |
97 func String(s string) (string, error) { | 101 func String(s string) (string, error) { |
98 res, err := Source([]byte(s)) | 102 res, err := Source([]byte(s)) |
99 if err != nil { | 103 if err != nil { |
100 return "", err | 104 return "", err |
(...skipping 14 matching lines...) Expand all Loading... |
115 // test expected to succeed | 119 // test expected to succeed |
116 res, err := String(src) | 120 res, err := String(src) |
117 if err != nil { | 121 if err != nil { |
118 t.Errorf("formatting failed (%s):\n%q", err, src
) | 122 t.Errorf("formatting failed (%s):\n%q", err, src
) |
119 } else if res != src { | 123 } else if res != src { |
120 t.Errorf("formatting incorrect:\nsource: %q\nres
ult: %q", src, res) | 124 t.Errorf("formatting incorrect:\nsource: %q\nres
ult: %q", src, res) |
121 } | 125 } |
122 } | 126 } |
123 } | 127 } |
124 } | 128 } |
OLD | NEW |