Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
42a854b7
Commit
42a854b7
authored
Dec 06, 2012
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gofmt: test rewrite of (x.(type)) -> x.(type)
R=rsc CC=golang-dev
https://golang.org/cl/6867062
parent
48567318
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
122 additions
and
1 deletion
+122
-1
src/cmd/gofmt/gofmt_test.go
src/cmd/gofmt/gofmt_test.go
+2
-1
src/cmd/gofmt/testdata/typeswitch.golden
src/cmd/gofmt/testdata/typeswitch.golden
+60
-0
src/cmd/gofmt/testdata/typeswitch.input
src/cmd/gofmt/testdata/typeswitch.input
+60
-0
No files found.
src/cmd/gofmt/gofmt_test.go
View file @
42a854b7
...
...
@@ -83,7 +83,8 @@ var tests = []struct {
{
"testdata/stdin*.input"
,
"-stdin"
},
{
"testdata/comments.input"
,
""
},
{
"testdata/import.input"
,
""
},
{
"testdata/crlf.input"
,
""
},
// test case for issue 3961; see also TestCRLF
{
"testdata/crlf.input"
,
""
},
// test case for issue 3961; see also TestCRLF
{
"testdata/typeswitch.input"
,
""
},
// test case for issue 4470
}
func
TestRewrite
(
t
*
testing
.
T
)
{
...
...
src/cmd/gofmt/testdata/typeswitch.golden
0 → 100644
View file @
42a854b7
/*
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 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
}
*/
}
src/cmd/gofmt/testdata/typeswitch.input
0 → 100644
View file @
42a854b7
/*
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 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
}
*/
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment