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
75187e5c
Commit
75187e5c
authored
Feb 01, 2010
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update printer tests to use new syntax
R=rsc CC=golang-dev
https://golang.org/cl/198048
parent
2a5d30fb
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
466 additions
and
590 deletions
+466
-590
src/pkg/go/printer/printer_test.go
src/pkg/go/printer/printer_test.go
+2
-11
src/pkg/go/printer/testdata/comments.input
src/pkg/go/printer/testdata/comments.input
+34
-34
src/pkg/go/printer/testdata/declarations.golden
src/pkg/go/printer/testdata/declarations.golden
+6
-63
src/pkg/go/printer/testdata/declarations.input
src/pkg/go/printer/testdata/declarations.input
+166
-224
src/pkg/go/printer/testdata/expressions.golden
src/pkg/go/printer/testdata/expressions.golden
+1
-1
src/pkg/go/printer/testdata/expressions.input
src/pkg/go/printer/testdata/expressions.input
+197
-197
src/pkg/go/printer/testdata/expressions.raw
src/pkg/go/printer/testdata/expressions.raw
+1
-1
src/pkg/go/printer/testdata/linebreaks.input
src/pkg/go/printer/testdata/linebreaks.input
+26
-26
src/pkg/go/printer/testdata/statements.input
src/pkg/go/printer/testdata/statements.input
+33
-33
No files found.
src/pkg/go/printer/printer_test.go
View file @
75187e5c
...
@@ -6,12 +6,10 @@ package printer
...
@@ -6,12 +6,10 @@ package printer
import
(
import
(
"bytes"
"bytes"
oldParser
"exp/parser"
"flag"
"flag"
"io/ioutil"
"io/ioutil"
"go/ast"
"go/ast"
"go/parser"
"go/parser"
"os"
"path"
"path"
"testing"
"testing"
)
)
...
@@ -40,19 +38,12 @@ type checkMode uint
...
@@ -40,19 +38,12 @@ type checkMode uint
const
(
const
(
export
checkMode
=
1
<<
iota
export
checkMode
=
1
<<
iota
rawFormat
rawFormat
oldSyntax
)
)
func
check
(
t
*
testing
.
T
,
source
,
golden
string
,
mode
checkMode
)
{
func
check
(
t
*
testing
.
T
,
source
,
golden
string
,
mode
checkMode
)
{
// parse source
// parse source
var
prog
*
ast
.
File
prog
,
err
:=
parser
.
ParseFile
(
source
,
nil
,
nil
,
parser
.
ParseComments
)
var
err
os
.
Error
if
mode
&
oldSyntax
!=
0
{
prog
,
err
=
oldParser
.
ParseFile
(
source
,
nil
,
parser
.
ParseComments
)
}
else
{
prog
,
err
=
parser
.
ParseFile
(
source
,
nil
,
nil
,
parser
.
ParseComments
)
}
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Error
(
err
)
t
.
Error
(
err
)
return
return
...
@@ -136,7 +127,7 @@ func Test(t *testing.T) {
...
@@ -136,7 +127,7 @@ func Test(t *testing.T) {
for
_
,
e
:=
range
data
{
for
_
,
e
:=
range
data
{
source
:=
path
.
Join
(
dataDir
,
e
.
source
)
source
:=
path
.
Join
(
dataDir
,
e
.
source
)
golden
:=
path
.
Join
(
dataDir
,
e
.
golden
)
golden
:=
path
.
Join
(
dataDir
,
e
.
golden
)
check
(
t
,
source
,
golden
,
e
.
mode
|
oldSyntax
)
check
(
t
,
source
,
golden
,
e
.
mode
)
// TODO(gri) check that golden is idempotent
// TODO(gri) check that golden is idempotent
//check(t, golden, golden, e.mode);
//check(t, golden, golden, e.mode);
}
}
...
...
src/pkg/go/printer/testdata/comments.input
View file @
75187e5c
...
@@ -8,10 +8,10 @@ package main
...
@@ -8,10 +8,10 @@ package main
import
"fmt"
//
fmt
import
"fmt"
//
fmt
const
c0
=
0
;
//
zero
const
c0
=
0
//
zero
const
(
const
(
c1
=
iota
;
//
c1
c1
=
iota
//
c1
c2
;
//
c2
c2
//
c2
)
)
...
@@ -20,21 +20,21 @@ type SZ struct {}
...
@@ -20,21 +20,21 @@ type SZ struct {}
//
The
S0
struct
;
no
field
is
exported
.
//
The
S0
struct
;
no
field
is
exported
.
type
S0
struct
{
type
S0
struct
{
int
;
int
x
,
y
,
z
int
;
//
3
unexported
fields
x
,
y
,
z
int
//
3
unexported
fields
}
}
//
The
S1
struct
;
some
fields
are
not
exported
.
//
The
S1
struct
;
some
fields
are
not
exported
.
type
S1
struct
{
type
S1
struct
{
S0
;
S0
A
,
B
,
C
float
;
//
3
exported
fields
A
,
B
,
C
float
//
3
exported
fields
D
,
b
,
c
int
;
//
2
unexported
fields
D
,
b
,
c
int
//
2
unexported
fields
}
}
//
The
S2
struct
;
all
fields
are
exported
.
//
The
S2
struct
;
all
fields
are
exported
.
type
S2
struct
{
type
S2
struct
{
S1
;
S1
A
,
B
,
C
float
;
//
3
exported
fields
A
,
B
,
C
float
//
3
exported
fields
}
}
//
The
IZ
interface
;
it
is
empty
.
//
The
IZ
interface
;
it
is
empty
.
...
@@ -42,21 +42,21 @@ type SZ interface {}
...
@@ -42,21 +42,21 @@ type SZ interface {}
//
The
I0
interface
;
no
method
is
exported
.
//
The
I0
interface
;
no
method
is
exported
.
type
I0
interface
{
type
I0
interface
{
f
(
x
int
)
int
;
//
unexported
method
f
(
x
int
)
int
//
unexported
method
}
}
//
The
I1
interface
;
some
methods
are
not
exported
.
//
The
I1
interface
;
some
methods
are
not
exported
.
type
I1
interface
{
type
I1
interface
{
I0
;
I0
F
(
x
float
)
float
;
//
exported
methods
F
(
x
float
)
float
//
exported
methods
g
(
x
int
)
int
;
//
unexported
method
g
(
x
int
)
int
//
unexported
method
}
}
//
The
I2
interface
;
all
methods
are
exported
.
//
The
I2
interface
;
all
methods
are
exported
.
type
I2
interface
{
type
I2
interface
{
I0
;
I0
F
(
x
float
)
float
;
//
exported
method
F
(
x
float
)
float
//
exported
method
G
(
x
float
)
float
;
//
exported
method
G
(
x
float
)
float
//
exported
method
}
}
//
This
comment
group
should
be
separated
//
This
comment
group
should
be
separated
...
@@ -65,29 +65,29 @@ type I2 interface {
...
@@ -65,29 +65,29 @@ type I2 interface {
//
This
comment
should
NOT
be
associated
with
the
next
declaration
.
//
This
comment
should
NOT
be
associated
with
the
next
declaration
.
var
x
int
;
//
x
var
x
int
//
x
var
()
var
()
//
This
comment
SHOULD
be
associated
with
the
next
declaration
.
//
This
comment
SHOULD
be
associated
with
the
next
declaration
.
func
f0
()
{
func
f0
()
{
const
pi
=
3.14
;
//
pi
const
pi
=
3.14
//
pi
var
s1
struct
{}
/*
an
empty
struct
*/
/*
foo
*/
var
s1
struct
{}
/*
an
empty
struct
*/
/*
foo
*/
//
a
struct
constructor
//
a
struct
constructor
//
--------------------
//
--------------------
var
s2
struct
{}
=
struct
{}{}
;
var
s2
struct
{}
=
struct
{}{}
x
:=
pi
;
x
:=
pi
}
}
//
//
//
NO
SPACE
HERE
//
NO
SPACE
HERE
//
//
func
f1
()
{
func
f1
()
{
f0
()
;
f0
()
/*
1
*/
/*
1
*/
//
2
//
2
/*
3
*/
/*
3
*/
/*
4
*/
/*
4
*/
f0
()
;
f0
()
}
}
...
@@ -98,9 +98,9 @@ func _() {
...
@@ -98,9 +98,9 @@ func _() {
func
abs
(
x
int
)
int
{
func
abs
(
x
int
)
int
{
if
x
<
0
{
//
the
tab
printed
before
this
comment
's // must not affect the remaining lines
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 // this statement should be properly indented
}
}
return x
;
return x
}
}
...
@@ -120,7 +120,7 @@ func typeswitch(x interface{}) {
...
@@ -120,7 +120,7 @@ func typeswitch(x interface{}) {
switch v0, ok := x.(int); x.(type) {
switch v0, ok := x.(int); x.(type) {
case byte: // this comment should be on the same line as the keyword
case byte: // this comment should be on the same line as the keyword
// this comment should be normally indented
// this comment should be normally indented
_ = 0
;
_ = 0
case bool, int, float:
case bool, int, float:
// this comment should be indented
// this comment should be indented
case string:
case string:
...
@@ -284,14 +284,14 @@ func _(/* this */x/* is *//* an */ int) {
...
@@ -284,14 +284,14 @@ func _(/* this */x/* is *//* an */ int) {
// Line comments with tabs
// Line comments with tabs
func _() {
func _() {
var finput *bufio.Reader
;
// input file
var finput *bufio.Reader // input file
var stderr *bufio.Writer
;
var stderr *bufio.Writer
var ftable *bufio.Writer
;
// y.go file
var ftable *bufio.Writer // y.go file
var foutput *bufio.Writer
;
// y.output file
var foutput *bufio.Writer // y.output file
var oflag string
;
// -o [y.go] - y.go file
var oflag string // -o [y.go] - y.go file
var vflag string
;
// -v [y.output] - y.output file
var vflag string // -v [y.output] - y.output file
var lflag bool
;
// -l - disable line directives
var lflag bool // -l - disable line directives
}
}
...
...
src/pkg/go/printer/testdata/declarations.golden
View file @
75187e5c
...
@@ -40,19 +40,15 @@ import _ "fmt"
...
@@ -40,19 +40,15 @@ import _ "fmt"
import
_
"fmt"
import
_
"fmt"
import
_
"fmt"
import
_
"fmt"
//
make
sure
a
comment
doesn
't cause semicolons to be inserted
import _ "foo" // a comment
import // a comment
"bar"
import
"foo"
//
a
comment
import
"foo"
//
a
comment
import
"bar"
//
a
comment
import
"bar"
//
a
comment
import
(
import
(
_ "foo"
+ // a comment
_
"foo"
// a comment
//
a
comment
"bar" +
"bar"
"foo" +
// a comment
"foo"
//
a
comment
"bar" // a comment
"bar"
//
a
comment
)
)
//
a
case
that
caused
problems
in
the
past
(
comment
placement
)
//
a
case
that
caused
problems
in
the
past
(
comment
placement
)
...
@@ -492,62 +488,9 @@ func _() int { type T struct{} }
...
@@ -492,62 +488,9 @@ func _() int { type T struct{} }
//
making
function
declarations
safe
for
new
semicolon
rules
//
making
function
declarations
safe
for
new
semicolon
rules
func
_
()
{
/*
one
-
line
func
*/
}
func
_
()
{
/*
one
-
line
func
*/
}
func _() {
// opening "{" must move up
func
_
()
{
/*
one
-
line
func
*/
}
/*
one
-
line
func
*/
}
func _() { // opening "{" must move up
// multi-line func
// in the following declarations, a comment must not
// introduce a newline and thus cause a semicolon to
// be inserted
const _ T = x // comment
const _ = x // comment
type _ T // comment
type _ struct // comment
{
}
type _ interface // comment
{
}
type _ * // comment
T
type _ [ // comment
]T
type _ [ // comment
10]T
type _ chan // comment
T
type _ map // comment
[T]T
var _ T // comment
var _ T = x // comment
var _ struct // comment
{
}
var _ interface // comment
{
}
var _ * // comment
T
var _ [ // comment
]T
var _ [ // comment
10]T
var _ chan // comment
T
var _ map // comment
[T]T
var _ = x // comment
}
//
ellipsis
parameters
//
ellipsis
parameters
func
_
(...)
func
_
(...)
...
...
src/pkg/go/printer/testdata/declarations.input
View file @
75187e5c
...
@@ -13,16 +13,16 @@ import (
...
@@ -13,16 +13,16 @@ import (
import
_
"io"
import
_
"io"
import
(
import
(
"io"
;
"io"
"io"
;
"io"
"io"
;
"io"
)
)
import
(
import
(
"io"
;
"io"
aLongRename
"io"
;
aLongRename
"io"
b
"io"
;
b
"io"
)
)
//
no
newlines
between
consecutive
single
imports
,
but
//
no
newlines
between
consecutive
single
imports
,
but
...
@@ -40,17 +40,11 @@ import _ "fmt"
...
@@ -40,17 +40,11 @@ import _ "fmt"
import
_
"fmt"
import
_
"fmt"
import
_
"fmt"
import
_
"fmt"
//
make
sure
a
comment
doesn
't cause semicolons to be inserted
import _ // a comment
"foo"
import // a comment
"bar"
import
"foo"
//
a
comment
import
"foo"
//
a
comment
import
"bar"
//
a
comment
import
"bar"
//
a
comment
import
(
import
(
_ // a comment
_
"foo"
"foo"
//
a
comment
//
a
comment
"bar"
"bar"
"foo"
//
a
comment
"foo"
//
a
comment
...
@@ -59,35 +53,35 @@ import (
...
@@ -59,35 +53,35 @@ import (
//
a
case
that
caused
problems
in
the
past
(
comment
placement
)
//
a
case
that
caused
problems
in
the
past
(
comment
placement
)
import
(
import
(
. "fmt"
;
.
"fmt"
"io"
;
"io"
"malloc"
;
// for the malloc count test only
"malloc"
//
for
the
malloc
count
test
only
"math"
;
"math"
"strings"
;
"strings"
"testing"
;
"testing"
)
)
//
at
least
one
empty
line
between
declarations
of
different
kind
//
at
least
one
empty
line
between
declarations
of
different
kind
import
_
"io"
import
_
"io"
var _ int
;
var
_
int
func
_
()
{
func
_
()
{
//
the
following
decls
need
a
semicolon
at
the
end
//
the
following
decls
need
a
semicolon
at
the
end
type _ int
;
type
_
int
type _ *int
;
type
_
*
int
type _ []int
;
type
_
[]
int
type _ map[string]int
;
type
_
map
[
string
]
int
type _ chan int
;
type
_
chan
int
type _ func() int
;
type
_
func
()
int
var _ int
;
var
_
int
var _ *int
;
var
_
*
int
var _ []int
;
var
_
[]
int
var _ map[string]int
;
var
_
map
[
string
]
int
var _ chan int
;
var
_
chan
int
var _ func() int
;
var
_
func
()
int
//
the
following
decls
don
't need a semicolon at the end
//
the
following
decls
don
't need a semicolon at the end
type _ struct{}
type _ struct{}
...
@@ -122,116 +116,116 @@ func _() {
...
@@ -122,116 +116,116 @@ func _() {
// don'
t
lose
blank
lines
in
grouped
declarations
// don'
t
lose
blank
lines
in
grouped
declarations
const
(
const
(
_ int = 0
;
_
int
=
0
_ float = 1
;
_
float
=
1
_ string = "foo"
;
_
string
=
"foo"
_ = iota
;
_
=
iota
_
;
_
//
a
comment
//
a
comment
_
;
_
_
;
_
)
)
type
(
type
(
_ int
;
_
int
_ struct {}
;
_
struct
{}
_ interface{}
;
_
interface
{}
//
a
comment
//
a
comment
_ map[string]int
;
_
map
[
string
]
int
)
)
var
(
var
(
_ int = 0
;
_
int
=
0
_ float = 1
;
_
float
=
1
_ string = "foo"
;
_
string
=
"foo"
_ bool
;
_
bool
//
a
comment
//
a
comment
_ bool
;
_
bool
)
)
//
don
't lose blank lines in this struct
//
don
't lose blank lines in this struct
type _ struct {
type _ struct {
String struct {
String struct {
Str
,
Len
int
;
Str, Len int
}
;
}
Slice struct {
Slice struct {
Array
,
Len
,
Cap
int
;
Array, Len, Cap int
}
;
}
Eface struct {
Eface struct {
Typ
,
Ptr
int
;
Typ, Ptr int
}
;
}
UncommonType struct {
UncommonType struct {
Name
,
PkgPath
int
;
Name, PkgPath int
}
;
}
CommonType struct {
CommonType struct {
Size
,
Hash
,
Alg
,
Align
,
FieldAlign
,
String
,
UncommonType
int
;
Size, Hash, Alg, Align, FieldAlign, String, UncommonType int
}
;
}
Type struct {
Type struct {
Typ
,
Ptr
int
;
Typ, Ptr int
}
;
}
StructField struct {
StructField struct {
Name
,
PkgPath
,
Typ
,
Tag
,
Offset
int
;
Name, PkgPath, Typ, Tag, Offset int
}
;
}
StructType struct {
StructType struct {
Fields
int
;
Fields int
}
;
}
PtrType struct {
PtrType struct {
Elem
int
;
Elem int
}
;
}
SliceType struct {
SliceType struct {
Elem
int
;
Elem int
}
;
}
ArrayType struct {
ArrayType struct {
Elem
,
Len
int
;
Elem, Len int
}
;
}
Stktop struct {
Stktop struct {
Stackguard
,
Stackbase
,
Gobuf
int
;
Stackguard, Stackbase, Gobuf int
}
;
}
Gobuf struct {
Gobuf struct {
Sp
,
Pc
,
G
int
;
Sp, Pc, G int
}
;
}
G struct {
G struct {
Stackbase
,
Sched
,
Status
,
Alllink
int
;
Stackbase, Sched, Status, Alllink int
}
;
}
}
}
// no tabs for single or ungrouped decls
// no tabs for single or ungrouped decls
func _() {
func _() {
const
xxxxxx
=
0
;
const xxxxxx = 0
type
x
int
;
type x int
var
xxx
int
;
var xxx int
var
yyyy
float
=
3.14
;
var yyyy float = 3.14
var
zzzzz
=
"bar"
;
var zzzzz = "bar"
const (
const (
xxxxxx
=
0
;
xxxxxx = 0
)
)
type (
type (
x
int
;
x int
)
)
var (
var (
xxx
int
;
xxx int
)
)
var (
var (
yyyy
float
=
3.14
;
yyyy float = 3.14
)
)
var (
var (
zzzzz
=
"bar"
;
zzzzz = "bar"
)
)
}
}
...
@@ -239,79 +233,79 @@ func _() {
...
@@ -239,79 +233,79 @@ func _() {
func _() {
func _() {
// no entry has a type
// no entry has a type
const (
const (
zzzzzz
=
1
;
zzzzzz = 1
z
=
2
;
z = 2
zzz
=
3
;
zzz = 3
)
)
// some entries have a type
// some entries have a type
const (
const (
xxxxxx
=
1
;
xxxxxx = 1
x
=
2
;
x = 2
xxx
=
3
;
xxx = 3
yyyyyyyy
float
=
iota
;
yyyyyyyy float = iota
yyyy
=
"bar"
;
yyyy = "bar"
yyy
;
yyy
yy
=
2
;
yy = 2
)
)
}
}
func _() {
func _() {
// no entry has a type
// no entry has a type
var (
var (
zzzzzz
=
1
;
zzzzzz = 1
z
=
2
;
z = 2
zzz
=
3
;
zzz = 3
)
)
// no entry has a value
// no entry has a value
var (
var (
_
int
;
_ int
_
float
;
_ float
_
string
;
_ string
_
int
;
//
comment
_ int // comment
_
float
;
//
comment
_ float // comment
_
string
;
//
comment
_ string // comment
)
)
// some entries have a type
// some entries have a type
var (
var (
xxxxxx
int
;
xxxxxx int
x
float
;
x float
xxx
string
;
xxx string
yyyyyyyy
int
=
1234
;
yyyyyyyy int = 1234
y
float
=
3.14
;
y float = 3.14
yyyy
=
"bar"
;
yyyy = "bar"
yyy
string
=
"foo"
;
yyy string = "foo"
)
)
// mixed entries - all comments should be aligned
// mixed entries - all comments should be aligned
var (
var (
a
,
b
,
c
int
;
a, b, c int
x
=
10
;
x = 10
d
int
;
//
comment
d int // comment
y
=
20
;
//
comment
y = 20 // comment
f
,
ff
,
fff
,
ffff
int
=
0
,
1
,
2
,
3
;
//
comment
f, ff, fff, ffff int = 0, 1, 2, 3 // comment
)
)
// respect original line breaks
// respect original line breaks
var _ = []T {
var _ = []T {
T{0x20, "Telugu"},
T{0x20, "Telugu"},
}
;
}
var _ = []T {
var _ = []T {
// respect original line breaks
// respect original line breaks
T{0x20, "Telugu"},
T{0x20, "Telugu"},
}
;
}
}
}
func _() {
func _() {
type (
type (
xxxxxx
int
;
xxxxxx int
x
float
;
x float
xxx
string
;
xxx string
xxxxx
[]
x
;
xxxxx []x
xx
struct
{}
;
xx struct{}
xxxxxxx struct {
xxxxxxx struct {
_
,
_
int
;
_, _ int
_
float
;
_ float
}
;
}
xxxx
chan
<-
string
;
xxxx chan<- string
)
)
}
}
...
@@ -326,16 +320,16 @@ type _ struct{
...
@@ -326,16 +320,16 @@ type _ struct{
}
}
type _ struct { // this comment must not change indentation
type _ struct { // this comment must not change indentation
f
int
;
f int
f
,
ff
,
fff
,
ffff
int
;
f, ff, fff, ffff int
}
}
type _ struct {
type _ struct {
string
;
string
}
}
type _ struct {
type _ struct {
string
;
//
comment
string // comment
}
}
type _ struct {
type _ struct {
...
@@ -347,38 +341,38 @@ type _ struct {
...
@@ -347,38 +341,38 @@ type _ struct {
}
}
type _ struct {
type _ struct {
f
int
;
f int
}
}
type _ struct {
type _ struct {
f
int
;
//
comment
f int // comment
}
}
type _ struct {
type _ struct {
f
int
"tag"
;
f int "tag"
}
}
type _ struct {
type _ struct {
f
int
"tag"
;
//
comment
f int "tag" // comment
}
}
type _ struct {
type _ struct {
bool
;
bool
a
,
b
,
c
int
;
a, b, c int
int
"tag"
;
int "tag"
ES
;
//
comment
ES // comment
float
"tag"
;
//
comment
float "tag" // comment
f
int
;
//
comment
f int // comment
f
,
ff
,
fff
,
ffff
int
;
//
comment
f, ff, fff, ffff int // comment
g
float
"tag"
;
g float "tag"
h
float
"tag"
;
//
comment
h float "tag" // comment
}
}
// difficult cases
// difficult cases
type _ struct {
type _ struct {
bool
;
//
comment
bool // comment
text
[]
byte
;
//
comment
text []byte // comment
}
}
...
@@ -387,38 +381,38 @@ type _ struct {
...
@@ -387,38 +381,38 @@ type _ struct {
type EI interface{}
type EI interface{}
type _ interface {
type _ interface {
EI
;
EI
}
}
type _ interface {
type _ interface {
f
()
;
f()
fffff
()
;
fffff()
}
}
type _ interface {
type _ interface {
EI
;
EI
f
()
;
f()
fffffg
()
;
fffffg()
}
}
type _ interface { // this comment must not change indentation
type _ interface { // this comment must not change indentation
EI
;
//
here
's a comment
EI // here'
s
a
comment
f()
;
// no blank between identifier and ()
f
()
//
no
blank
between
identifier
and
()
fffff()
;
// no blank between identifier and ()
fffff
()
//
no
blank
between
identifier
and
()
gggggggggggg(x, y, z int) ()
;
// hurray
gggggggggggg
(
x
,
y
,
z
int
)
()
//
hurray
}
}
//
formatting
of
variable
declarations
//
formatting
of
variable
declarations
func
_
()
{
func
_
()
{
type day struct { n int; short, long string }
;
type
day
struct
{
n
int
;
short
,
long
string
}
var
(
var
(
Sunday = day{ 0, "SUN", "Sunday" }
;
Sunday
=
day
{
0
,
"SUN"
,
"Sunday"
}
Monday = day{ 1, "MON", "Monday" }
;
Monday
=
day
{
1
,
"MON"
,
"Monday"
}
Tuesday = day{ 2, "TUE", "Tuesday" }
;
Tuesday
=
day
{
2
,
"TUE"
,
"Tuesday"
}
Wednesday = day{ 3, "WED", "Wednesday" }
;
Wednesday
=
day
{
3
,
"WED"
,
"Wednesday"
}
Thursday = day{ 4, "THU", "Thursday" }
;
Thursday
=
day
{
4
,
"THU"
,
"Thursday"
}
Friday = day{ 5, "FRI", "Friday" }
;
Friday
=
day
{
5
,
"FRI"
,
"Friday"
}
Saturday = day{ 6, "SAT", "Saturday" }
;
Saturday
=
day
{
6
,
"SAT"
,
"Saturday"
}
)
)
}
}
...
@@ -469,7 +463,7 @@ func _() {
...
@@ -469,7 +463,7 @@ func _() {
func
_
()
{
func
_
()
{
var
_
=
T
{
var
_
=
T
{
a // must introduce trailing comma
a
,
//
must
introduce
trailing
comma
}
}
}
}
...
@@ -484,7 +478,7 @@ func _() {}
...
@@ -484,7 +478,7 @@ func _() {}
func
_
()
{}
func
_
()
{}
func
_
()
{
func
_
()
{
f(1, 2, 3)
;
f
(
1
,
2
,
3
)
}
}
func
_
(
x
int
)
int
{
func
_
(
x
int
)
int
{
return
x
+
1
return
x
+
1
...
@@ -495,62 +489,10 @@ func _() int {
...
@@ -495,62 +489,10 @@ func _() int {
//
making
function
declarations
safe
for
new
semicolon
rules
//
making
function
declarations
safe
for
new
semicolon
rules
func _()
func
_
()
{
/*
one
-
line
func
*/
}
{ /* one-line func */ }
func
_
()
{
func _() // opening "{" must move up
/*
one
-
line
func
*/
}
{ /* one-line func */ }
func _() // opening "{" must move up
// multi-line func
{
// in the following declarations, a comment must not
// introduce a newline and thus cause a semicolon to
// be inserted
const _ // comment
T = x;
const _ // comment
= x;
type _ // comment
T;
type _ // comment
struct {};
type _ // comment
interface {};
type _ // comment
*T;
type _ // comment
[]T;
type _ // comment
[10]T;
type _ // comment
chan T;
type _ // comment
map[T]T;
var _ // comment
T;
var _ // comment
T = x;
var _ // comment
struct {};
var _ // comment
interface {};
var _ // comment
*T;
var _ // comment
[]T;
var _ // comment
[10]T;
var _ // comment
chan T;
var _ // comment
map[T]T;
var _ // comment
= x;
}
//
ellipsis
parameters
//
ellipsis
parameters
...
...
src/pkg/go/printer/testdata/expressions.golden
View file @
75187e5c
...
@@ -302,7 +302,7 @@ func _() {
...
@@ -302,7 +302,7 @@ func _() {
_
=
a
+
//
comment
_
=
a
+
//
comment
b
+
//
comment
b
+
//
comment
c
c
_
=
"a"
+
//
comment
_
=
"a"
+
"b"
+
//
comment
"b"
+
//
comment
"c"
"c"
_
=
"ba0408"
+
"7265717569726564"
//
field
71
,
encoding
2
,
string
"required"
_
=
"ba0408"
+
"7265717569726564"
//
field
71
,
encoding
2
,
string
"required"
...
...
src/pkg/go/printer/testdata/expressions.input
View file @
75187e5c
...
@@ -9,227 +9,227 @@ type T struct {
...
@@ -9,227 +9,227 @@ type T struct {
}
}
var
(
var
(
a
,
b
,
c
,
d
,
e
int
;
a
,
b
,
c
,
d
,
e
int
under_bar
int
;
under_bar
int
longIdentifier1
,
longIdentifier2
,
longIdentifier3
int
;
longIdentifier1
,
longIdentifier2
,
longIdentifier3
int
t0
,
t1
,
t2
T
;
t0
,
t1
,
t2
T
s
string
;
s
string
p
*
int
;
p
*
int
)
)
func
_
()
{
func
_
()
{
//
no
spaces
around
simple
or
parenthesized
expressions
//
no
spaces
around
simple
or
parenthesized
expressions
_
=
a
+
b
;
_
=
a
+
b
_
=
a
+
b
+
c
;
_
=
a
+
b
+
c
_
=
a
+
b
-
c
;
_
=
a
+
b
-
c
_
=
a
-
b
-
c
;
_
=
a
-
b
-
c
_
=
a
+(
b
*
c
)
;
_
=
a
+(
b
*
c
)
_
=
a
+(
b
/
c
)
;
_
=
a
+(
b
/
c
)
_
=
a
-(
b
%
c
)
;
_
=
a
-(
b
%
c
)
_
=
1
+
a
;
_
=
1
+
a
_
=
a
+
1
;
_
=
a
+
1
_
=
a
+
b
+
1
;
_
=
a
+
b
+
1
_
=
s
[
1
:
2
]
;
_
=
s
[
1
:
2
]
_
=
s
[
a
:
b
]
;
_
=
s
[
a
:
b
]
_
=
s
[
0
:
len
(
s
)]
;
_
=
s
[
0
:
len
(
s
)]
_
=
s
[
0
]<<
1
;
_
=
s
[
0
]<<
1
_
=
(
s
[
0
]<<
1
)&
0xf
;
_
=
(
s
[
0
]<<
1
)&
0xf
_
=
s
[
0
]
<<
2
|
s
[
1
]
>>
4
;
_
=
s
[
0
]
<<
2
|
s
[
1
]
>>
4
_
=
"foo"
+
s
;
_
=
"foo"
+
s
_
=
s
+
"foo"
;
_
=
s
+
"foo"
_
=
'a'
+
'b'
;
_
=
'a'
+
'b'
_
=
len
(
s
)/
2
;
_
=
len
(
s
)/
2
_
=
len
(
t0
.
x
)/
a
;
_
=
len
(
t0
.
x
)/
a
//
spaces
around
expressions
of
different
precedence
or
expressions
containing
spaces
//
spaces
around
expressions
of
different
precedence
or
expressions
containing
spaces
_
=
a
+
-
b
;
_
=
a
+
-
b
_
=
a
-
^
b
;
_
=
a
-
^
b
_
=
a
/
*
p
;
_
=
a
/
*
p
_
=
a
+
b
*
c
;
_
=
a
+
b
*
c
_
=
1
+
b
*
c
;
_
=
1
+
b
*
c
_
=
a
+
2
*
c
;
_
=
a
+
2
*
c
_
=
a
+
c
*
2
;
_
=
a
+
c
*
2
_
=
1
+
2
*
3
;
_
=
1
+
2
*
3
_
=
s
[
1
:
2
*
3
]
;
_
=
s
[
1
:
2
*
3
]
_
=
s
[
a
:
b
-
c
]
;
_
=
s
[
a
:
b
-
c
]
_
=
s
[
0
:]
;
_
=
s
[
0
:]
_
=
s
[
a
+
b
]
;
_
=
s
[
a
+
b
]
_
=
s
[
a
+
b
:]
;
_
=
s
[
a
+
b
:]
_
=
a
[
a
<<
b
+
1
]
;
_
=
a
[
a
<<
b
+
1
]
_
=
a
[
a
<<
b
+
1
:]
;
_
=
a
[
a
<<
b
+
1
:]
_
=
s
[
a
+
b
:
len
(
s
)]
;
_
=
s
[
a
+
b
:
len
(
s
)]
_
=
s
[
len
(
s
)
:
-
a
]
;
_
=
s
[
len
(
s
)
:
-
a
]
_
=
s
[
a
:
len
(
s
)+
1
]
;
_
=
s
[
a
:
len
(
s
)+
1
]
_
=
s
[
a
:
len
(
s
)+
1
]+
s
;
_
=
s
[
a
:
len
(
s
)+
1
]+
s
//
spaces
around
operators
with
equal
or
lower
precedence
than
comparisons
//
spaces
around
operators
with
equal
or
lower
precedence
than
comparisons
_
=
a
==
b
;
_
=
a
==
b
_
=
a
!= b
;
_
=
a
!= b
_
=
a
>
b
;
_
=
a
>
b
_
=
a
>=
b
;
_
=
a
>=
b
_
=
a
<
b
;
_
=
a
<
b
_
=
a
<=
b
;
_
=
a
<=
b
_
=
a
<
b
&&
c
>
d
;
_
=
a
<
b
&&
c
>
d
_
=
a
<
b
||
c
>
d
;
_
=
a
<
b
||
c
>
d
//
spaces
around
"long"
operands
//
spaces
around
"long"
operands
_
=
a
+
longIdentifier1
;
_
=
a
+
longIdentifier1
_
=
longIdentifier1
+
a
;
_
=
longIdentifier1
+
a
_
=
longIdentifier1
+
longIdentifier2
*
longIdentifier3
;
_
=
longIdentifier1
+
longIdentifier2
*
longIdentifier3
_
=
s
+
"a longer string"
;
_
=
s
+
"a longer string"
//
some
selected
cases
//
some
selected
cases
_
=
a
+
t0
.
x
;
_
=
a
+
t0
.
x
_
=
a
+
t0
.
x
+
t1
.
x
*
t2
.
x
;
_
=
a
+
t0
.
x
+
t1
.
x
*
t2
.
x
_
=
a
+
b
+
c
+
d
+
e
+
2
*
3
;
_
=
a
+
b
+
c
+
d
+
e
+
2
*
3
_
=
a
+
b
+
c
+
2
*
3
+
d
+
e
;
_
=
a
+
b
+
c
+
2
*
3
+
d
+
e
_
=
(
a
+
b
+
c
)*
2
;
_
=
(
a
+
b
+
c
)*
2
_
=
a
-
b
+
c
-
d
+
(
a
+
b
+
c
)
+
d
&
e
;
_
=
a
-
b
+
c
-
d
+
(
a
+
b
+
c
)
+
d
&
e
_
=
under_bar
-
1
;
_
=
under_bar
-
1
_
=
Open
(
dpath
+
"/file"
,
O_WRONLY
|
O_CREAT
,
0666
)
;
_
=
Open
(
dpath
+
"/file"
,
O_WRONLY
|
O_CREAT
,
0666
)
_
=
int
(
c0
&
_Mask4
)<<
18
|
int
(
c1
&
_Maskx
)<<
12
|
int
(
c2
&
_Maskx
)<<
6
|
int
(
c3
&
_Maskx
)
;
_
=
int
(
c0
&
_Mask4
)<<
18
|
int
(
c1
&
_Maskx
)<<
12
|
int
(
c2
&
_Maskx
)<<
6
|
int
(
c3
&
_Maskx
)
}
}
func
_
()
{
func
_
()
{
a
+
b
;
a
+
b
a
+
b
+
c
;
a
+
b
+
c
a
+
b
*
c
;
a
+
b
*
c
a
+(
b
*
c
)
;
a
+(
b
*
c
)
(
a
+
b
)*
c
;
(
a
+
b
)*
c
a
+(
b
*
c
*
d
)
;
a
+(
b
*
c
*
d
)
a
+(
b
*
c
+
d
)
;
a
+(
b
*
c
+
d
)
1
<<
x
;
1
<<
x
-
1
<<
x
;
-
1
<<
x
1
<<
x
-
1
;
1
<<
x
-
1
-
1
<<
x
-
1
;
-
1
<<
x
-
1
f
(
a
+
b
)
;
f
(
a
+
b
)
f
(
a
+
b
+
c
)
;
f
(
a
+
b
+
c
)
f
(
a
+
b
*
c
)
;
f
(
a
+
b
*
c
)
f
(
a
+(
b
*
c
))
;
f
(
a
+(
b
*
c
))
f
(
1
<<
x
-
1
,
1
<<
x
-
2
)
;
f
(
1
<<
x
-
1
,
1
<<
x
-
2
)
1
<<
d
.
logWindowSize
-
1
;
1
<<
d
.
logWindowSize
-
1
buf
=
make
(
x
,
2
*
cap
(
b
.
buf
)
+
n
)
;
buf
=
make
(
x
,
2
*
cap
(
b
.
buf
)
+
n
)
dst
[
i
*
3
+
2
]
=
dbuf
[
0
]<<
2
;
dst
[
i
*
3
+
2
]
=
dbuf
[
0
]<<
2
dst
[
i
*
3
+
2
]
=
dbuf
[
0
]<<
2
|
dbuf
[
1
]>>
4
;
dst
[
i
*
3
+
2
]
=
dbuf
[
0
]<<
2
|
dbuf
[
1
]>>
4
b
.
buf
=
b
.
buf
[
0
:
b
.
off
+
m
+
n
]
;
b
.
buf
=
b
.
buf
[
0
:
b
.
off
+
m
+
n
]
b
.
buf
=
b
.
buf
[
0
:
b
.
off
+
m
*
n
]
;
b
.
buf
=
b
.
buf
[
0
:
b
.
off
+
m
*
n
]
f
(
b
.
buf
[
0
:
b
.
off
+
m
+
n
])
;
f
(
b
.
buf
[
0
:
b
.
off
+
m
+
n
])
signed
+=
' '
*
8
;
signed
+=
' '
*
8
tw
.
octal
(
header
[
148
:
155
],
chksum
)
;
tw
.
octal
(
header
[
148
:
155
],
chksum
)
x
>
0
&&
i
>=
0
;
x
>
0
&&
i
>=
0
x1
,
x0
:=
x
>>
w2
,
x
&
m2
;
x1
,
x0
:=
x
>>
w2
,
x
&
m2
z0
=
t1
<<
w2
+
t0
;
z0
=
t1
<<
w2
+
t0
z1
=
(
t1
+
t0
>>
w2
)>>
w2
;
z1
=
(
t1
+
t0
>>
w2
)>>
w2
q1
,
r1
:=
x1
/
d1
,
x1
%
d1
;
q1
,
r1
:=
x1
/
d1
,
x1
%
d1
r1
=
r1
*
b2
|
x0
>>
w2
;
r1
=
r1
*
b2
|
x0
>>
w2
x1
=
(
x1
<<
z
)|(
x0
>>(
uint
(
w
)-
z
))
;
x1
=
(
x1
<<
z
)|(
x0
>>(
uint
(
w
)-
z
))
x1
=
x1
<<
z
|
x0
>>(
uint
(
w
)-
z
)
;
x1
=
x1
<<
z
|
x0
>>(
uint
(
w
)-
z
)
buf
[
0
:
len
(
buf
)+
1
]
;
buf
[
0
:
len
(
buf
)+
1
]
buf
[
0
:
n
+
1
]
;
buf
[
0
:
n
+
1
]
a
,
b
=
b
,
a
;
a
,
b
=
b
,
a
a
=
b
+
c
;
a
=
b
+
c
a
=
b
*
c
+
d
;
a
=
b
*
c
+
d
a
*
b
+
c
;
a
*
b
+
c
a
-
b
-
c
;
a
-
b
-
c
a
-(
b
-
c
)
;
a
-(
b
-
c
)
a
-
b
*
c
;
a
-
b
*
c
a
-(
b
*
c
)
;
a
-(
b
*
c
)
a
*
b
/
c
;
a
*
b
/
c
a
/
*
b
;
a
/
*
b
x
[
a
|^
b
]
;
x
[
a
|^
b
]
x
[
a
/
*
b
]
;
x
[
a
/
*
b
]
a
&
^
b
;
a
&
^
b
a
+
+
b
;
a
+
+
b
a
-
-
b
;
a
-
-
b
x
[
a
*-
b
]
;
x
[
a
*-
b
]
x
[
a
+
+
b
]
;
x
[
a
+
+
b
]
x
^
y
^
z
;
x
^
y
^
z
b
[
a
>>
24
]
^
b
[(
a
>>
16
)&
0xFF
]
^
b
[(
a
>>
8
)&
0xFF
]
^
b
[
a
&
0xFF
]
;
b
[
a
>>
24
]
^
b
[(
a
>>
16
)&
0xFF
]
^
b
[(
a
>>
8
)&
0xFF
]
^
b
[
a
&
0xFF
]
len
(
longVariableName
)*
2
;
len
(
longVariableName
)*
2
token
(
matchType
+
xlength
<<
lengthShift
+
xoffset
)
;
token
(
matchType
+
xlength
<<
lengthShift
+
xoffset
)
}
}
func
_
()
{
func
_
()
{
_
=
T
{}
;
_
=
T
{}
_
=
struct
{}{}
;
_
=
struct
{}{}
_
=
[
10
]
T
{}
;
_
=
[
10
]
T
{}
_
=
[...]
T
{}
;
_
=
[...]
T
{}
_
=
[]
T
{}
;
_
=
[]
T
{}
_
=
map
[
int
]
T
{}
;
_
=
map
[
int
]
T
{}
_
=
(
T
){}
;
_
=
(
T
){}
_
=
(
struct
{}){}
;
_
=
(
struct
{}){}
_
=
([
10
]
T
){}
;
_
=
([
10
]
T
){}
_
=
([...]
T
){}
;
_
=
([...]
T
){}
_
=
([]
T
){}
;
_
=
([]
T
){}
_
=
(
map
[
int
]
T
){}
;
_
=
(
map
[
int
]
T
){}
}
}
//
one
-
line
structs
/
interfaces
in
composite
literals
(
up
to
a
threshold
)
//
one
-
line
structs
/
interfaces
in
composite
literals
(
up
to
a
threshold
)
func
_
()
{
func
_
()
{
_
=
struct
{}{}
;
_
=
struct
{}{}
_
=
struct
{
x
int
}{
0
}
;
_
=
struct
{
x
int
}{
0
}
_
=
struct
{
x
,
y
,
z
int
}{
0
,
1
,
2
}
;
_
=
struct
{
x
,
y
,
z
int
}{
0
,
1
,
2
}
_
=
struct
{
int
}{
0
}
;
_
=
struct
{
int
}{
0
}
_
=
struct
{
s
struct
{
int
}
}{
struct
{
int
}{
0
}}
;
//
compositeLit
context
not
propagated
=>
multiLine
result
_
=
struct
{
s
struct
{
int
}
}{
struct
{
int
}{
0
}}
//
compositeLit
context
not
propagated
=>
multiLine
result
}
}
func
_
()
{
func
_
()
{
//
do
not
modify
literals
//
do
not
modify
literals
_
=
"tab1 tab2 tab3 end"
;
//
string
contains
3
tabs
_
=
"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
_
=
"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
_
=
""
//
this
comment
should
be
aligned
with
the
one
on
the
previous
line
_
=
``
;
_
=
``
_
=
`
_
=
`
`
;
`
_
=
`
foo
_
=
`
foo
bar
`
;
bar
`
}
}
func
_
()
{
func
_
()
{
//
one
-
line
function
literals
//
one
-
line
function
literals
_
=
func
()
{}
;
_
=
func
()
{}
_
=
func
()
int
{
_
=
func
()
int
{
return
0
;
return
0
}
;
}
_
=
func
(
x
,
y
int
)
bool
{
_
=
func
(
x
,
y
int
)
bool
{
return
x
<
y
return
x
<
y
}
;
}
f
(
func
()
{})
;
f
(
func
()
{})
f
(
func
()
int
{
f
(
func
()
int
{
return
0
;
return
0
})
;
})
f
(
func
(
x
,
y
int
)
bool
{
f
(
func
(
x
,
y
int
)
bool
{
return
x
<
y
return
x
<
y
})
;
})
}
}
func
_
()
{
func
_
()
{
//
do
not
add
extra
indentation
to
multi
-
line
string
lists
//
do
not
add
extra
indentation
to
multi
-
line
string
lists
_
=
"foo"
+
"bar"
;
_
=
"foo"
+
"bar"
_
=
"foo"
+
_
=
"foo"
+
"bar"
+
"bar"
+
"bah"
;
"bah"
_
=
[]
string
{
_
=
[]
string
{
"abc"
+
"abc"
+
"def"
,
"def"
,
...
@@ -262,13 +262,13 @@ func _() {
...
@@ -262,13 +262,13 @@ func _() {
_
=
F1
+
_
=
F1
+
`
string
=
"%s"
;`
+
`
string
=
"%s"
;`
+
`
ptr
=
*;`
+
`
ptr
=
*;`
+
`
datafmt
.
T2
=
s
[
"-"
p
"-"
];`
;
`
datafmt
.
T2
=
s
[
"-"
p
"-"
];`
_
=
_
=
`
datafmt
"datafmt"
;`
+
`
datafmt
"datafmt"
;`
+
`
default
=
"%v"
;`
+
`
default
=
"%v"
;`
+
`
array
=
*;`
+
`
array
=
*;`
+
`
datafmt
.
T3
=
s
{
" "
a
a
/
","
};`
;
`
datafmt
.
T3
=
s
{
" "
a
a
/
","
};`
_
=
`
datafmt
"datafmt"
;`
+
_
=
`
datafmt
"datafmt"
;`
+
`
default
=
"%v"
;`
+
`
default
=
"%v"
;`
+
...
@@ -281,36 +281,36 @@ func _() {
...
@@ -281,36 +281,36 @@ func _() {
//
respect
source
lines
in
multi
-
line
expressions
//
respect
source
lines
in
multi
-
line
expressions
_
=
a
+
_
=
a
+
b
+
b
+
c
;
c
_
=
a
<
b
||
_
=
a
<
b
||
b
<
a
;
b
<
a
_
=
"933262154439441526816992388562667004907159682643816214685929"
+
_
=
"933262154439441526816992388562667004907159682643816214685929"
+
"638952175999932299156089414639761565182862536979208272237582"
+
"638952175999932299156089414639761565182862536979208272237582"
+
"51185210916864000000000000000000000000"
;
//
100
!
"51185210916864000000000000000000000000"
//
100
!
_
=
"170141183460469231731687303715884105727"
;
//
prime
_
=
"170141183460469231731687303715884105727"
//
prime
}
}
//
Alignment
after
overlong
lines
//
Alignment
after
overlong
lines
const
(
const
(
_
=
"991"
;
_
=
"991"
_
=
"2432902008176640000"
;
//
20
!
_
=
"2432902008176640000"
//
20
!
_
=
"933262154439441526816992388562667004907159682643816214685929"
+
_
=
"933262154439441526816992388562667004907159682643816214685929"
+
"638952175999932299156089414639761565182862536979208272237582"
+
"638952175999932299156089414639761565182862536979208272237582"
+
"51185210916864000000000000000000000000"
;
//
100
!
"51185210916864000000000000000000000000"
//
100
!
_
=
"170141183460469231731687303715884105727"
;
//
prime
_
=
"170141183460469231731687303715884105727"
//
prime
)
)
//
Correct
placement
of
operators
and
comments
in
multi
-
line
expressions
//
Correct
placement
of
operators
and
comments
in
multi
-
line
expressions
func
_
()
{
func
_
()
{
_
=
a
//
comment
_
=
a
+
//
comment
+
b
+
//
comment
b
+
//
comment
c
;
c
_
=
"a"
//
comment
_
=
"a"
+
"b"
//
comment
"b"
+
//
comment
"c"
;
"c"
_
=
"ba0408"
"7265717569726564"
//
field
71
,
encoding
2
,
string
"required"
_
=
"ba0408"
+
"7265717569726564"
//
field
71
,
encoding
2
,
string
"required"
}
}
...
@@ -318,26 +318,26 @@ func _() {
...
@@ -318,26 +318,26 @@ func _() {
func
_
()
{
func
_
()
{
f
(
1
,
f
(
1
,
2
,
2
,
3
)
;
3
)
f
(
1
,
f
(
1
,
2
,
2
,
3
3
,
)
;
)
//
TODO
(
gri
)
the
cases
below
are
not
correct
yet
//
TODO
(
gri
)
the
cases
below
are
not
correct
yet
f
(
1
,
f
(
1
,
2
,
2
,
3
)
;
//
comment
3
)
//
comment
f
(
1
,
f
(
1
,
2
,
2
,
3
//
comment
3
,
//
comment
)
;
)
f
(
1
,
f
(
1
,
2
,
2
,
3
)
;
//
comment
3
)//
comment
f
(
1
,
f
(
1
,
2
,
2
,
3
//
comment
3
,
//
comment
)
;
)
}
}
...
@@ -359,8 +359,8 @@ func (p *parser) charClass() {
...
@@ -359,8 +359,8 @@ func (p *parser) charClass() {
//
respect
source
lines
in
multi
-
line
expressions
//
respect
source
lines
in
multi
-
line
expressions
if
cc
.
negate
&&
len
(
cc
.
ranges
)
==
2
&&
if
cc
.
negate
&&
len
(
cc
.
ranges
)
==
2
&&
cc
.
ranges
[
0
]
==
'\n'
&&
cc
.
ranges
[
1
]
==
'\n'
{
cc
.
ranges
[
0
]
==
'\n'
&&
cc
.
ranges
[
1
]
==
'\n'
{
nl
:=
new
(
_NotNl
)
;
nl
:=
new
(
_NotNl
)
p
.
re
.
add
(
nl
)
;
p
.
re
.
add
(
nl
)
}
}
}
}
...
...
src/pkg/go/printer/testdata/expressions.raw
View file @
75187e5c
...
@@ -302,7 +302,7 @@ func _() {
...
@@ -302,7 +302,7 @@ func _() {
_
=
a
+
//
comment
_
=
a
+
//
comment
b
+
//
comment
b
+
//
comment
c
c
_
=
"a"
+
//
comment
_
=
"a"
+
"b"
+
//
comment
"b"
+
//
comment
"c"
"c"
_
=
"ba0408"
+
"7265717569726564"
//
field
71
,
encoding
2
,
string
"required"
_
=
"ba0408"
+
"7265717569726564"
//
field
71
,
encoding
2
,
string
"required"
...
...
src/pkg/go/printer/testdata/linebreaks.input
View file @
75187e5c
...
@@ -5,23 +5,23 @@
...
@@ -5,23 +5,23 @@
package
linebreaks
package
linebreaks
import
(
import
(
"bytes"
;
"bytes"
"fmt"
;
"fmt"
"io"
;
"io"
"os"
;
"os"
"reflect"
;
"reflect"
"strings"
;
"strings"
"testing"
;
"testing"
)
)
type
writerTestEntry
struct
{
type
writerTestEntry
struct
{
header
*
Header
;
header
*
Header
contents
string
;
contents
string
}
}
type
writerTest
struct
{
type
writerTest
struct
{
file
string
;
//
filename
of
expected
output
file
string
//
filename
of
expected
output
entries
[]*
writerTestEntry
;
entries
[]*
writerTestEntry
}
}
var
writerTests
=
[]*
writerTest
{
var
writerTests
=
[]*
writerTest
{
...
@@ -83,8 +83,8 @@ var writerTests = []*writerTest{
...
@@ -83,8 +83,8 @@ var writerTests = []*writerTest{
}
}
type
untarTest
struct
{
type
untarTest
struct
{
file
string
;
file
string
headers
[]*
Header
;
headers
[]*
Header
}
}
var
untarTests
=
[]*
untarTest
{
var
untarTests
=
[]*
untarTest
{
...
@@ -186,36 +186,36 @@ func usage() {
...
@@ -186,36 +186,36 @@ func usage() {
fmt
.
Fprintf
(
os
.
Stderr
,
fmt
.
Fprintf
(
os
.
Stderr
,
//
TODO
(
gri
):
the
2
nd
string
of
this
string
list
should
not
be
indented
//
TODO
(
gri
):
the
2
nd
string
of
this
string
list
should
not
be
indented
"usage: godoc package [name ...]
\n
"
+
"usage: godoc package [name ...]
\n
"
+
" godoc -http=:6060
\n
"
)
;
" godoc -http=:6060
\n
"
)
flag
.
PrintDefaults
()
;
flag
.
PrintDefaults
()
os
.
Exit
(
2
)
;
os
.
Exit
(
2
)
}
}
func
TestReader
(
t
*
testing
.
T
)
{
func
TestReader
(
t
*
testing
.
T
)
{
testLoop
:
testLoop
:
for
i
,
test
:=
range
untarTests
{
for
i
,
test
:=
range
untarTests
{
f
,
err
:=
os
.
Open
(
test
.
file
,
os
.
O_RDONLY
,
0444
)
;
f
,
err
:=
os
.
Open
(
test
.
file
,
os
.
O_RDONLY
,
0444
)
if
err
!= nil {
if
err
!= nil {
t
.
Errorf
(
"test %d: Unexpected error: %v"
,
i
,
err
)
;
t
.
Errorf
(
"test %d: Unexpected error: %v"
,
i
,
err
)
continue
continue
}
}
tr
:=
NewReader
(
f
)
;
tr
:=
NewReader
(
f
)
for
j
,
header
:=
range
test
.
headers
{
for
j
,
header
:=
range
test
.
headers
{
hdr
,
err
:=
tr
.
Next
()
;
hdr
,
err
:=
tr
.
Next
()
if
err
!= nil || hdr == nil {
if
err
!= nil || hdr == nil {
t
.
Errorf
(
"test %d, entry %d: Didn't get entry: %v"
,
i
,
j
,
err
)
;
t
.
Errorf
(
"test %d, entry %d: Didn't get entry: %v"
,
i
,
j
,
err
)
f
.
Close
()
;
f
.
Close
()
continue
testLoop
continue
testLoop
}
}
if
!reflect.DeepEqual(hdr, header) {
if
!reflect.DeepEqual(hdr, header) {
t
.
Errorf
(
"test %d, entry %d: Incorrect header:
\n
have %+v
\n
want %+v"
,
t
.
Errorf
(
"test %d, entry %d: Incorrect header:
\n
have %+v
\n
want %+v"
,
i
,
j
,
*
hdr
,
*
header
)
;
i
,
j
,
*
hdr
,
*
header
)
}
}
}
}
hdr
,
err
:=
tr
.
Next
()
;
hdr
,
err
:=
tr
.
Next
()
if
hdr
!= nil || err != nil {
if
hdr
!= nil || err != nil {
t
.
Errorf
(
"test %d: Unexpected entry or error: hdr=%v err=%v"
,
i
,
err
)
;
t
.
Errorf
(
"test %d: Unexpected entry or error: hdr=%v err=%v"
,
i
,
err
)
}
}
f
.
Close
()
;
f
.
Close
()
}
}
}
}
src/pkg/go/printer/testdata/statements.input
View file @
75187e5c
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
package
statements
package
statements
var
expr
bool
;
var
expr
bool
func
use
(
x
interface
{})
{}
func
use
(
x
interface
{})
{}
...
@@ -44,34 +44,34 @@ func _() {
...
@@ -44,34 +44,34 @@ func _() {
switch
x
:=
0
;
x
{
switch
x
:=
0
;
x
{
case
1
:
case
1
:
use
(
x
)
;
use
(
x
)
use
(
x
)
;
//
followed
by
an
empty
line
use
(
x
)
//
followed
by
an
empty
line
case
2
:
//
followed
by
an
empty
line
case
2
:
//
followed
by
an
empty
line
use
(
x
)
;
//
followed
by
an
empty
line
use
(
x
)
//
followed
by
an
empty
line
case
3
:
//
no
empty
lines
case
3
:
//
no
empty
lines
use
(
x
)
;
use
(
x
)
use
(
x
)
;
use
(
x
)
}
}
switch
x
{
switch
x
{
case
0
:
case
0
:
use
(
x
)
;
use
(
x
)
case
1
:
//
this
comment
should
have
no
effect
on
the
previous
or
next
line
case
1
:
//
this
comment
should
have
no
effect
on
the
previous
or
next
line
use
(
x
)
;
use
(
x
)
}
}
switch
x
:=
0
;
x
{
switch
x
:=
0
;
x
{
case
1
:
case
1
:
x
=
0
;
x
=
0
//
this
comment
should
be
indented
//
this
comment
should
be
indented
case
2
:
case
2
:
x
=
0
;
x
=
0
//
this
comment
should
not
be
indented
,
it
is
aligned
with
the
next
case
//
this
comment
should
not
be
indented
,
it
is
aligned
with
the
next
case
case
3
:
case
3
:
x
=
0
;
x
=
0
/*
indented
comment
/*
indented
comment
aligned
aligned
aligned
aligned
...
@@ -79,7 +79,7 @@ func _() {
...
@@ -79,7 +79,7 @@ func _() {
//
bla
//
bla
/*
and
more
*/
/*
and
more
*/
case
4
:
case
4
:
x
=
0
;
x
=
0
/*
not
indented
comment
/*
not
indented
comment
aligned
aligned
aligned
aligned
...
@@ -115,28 +115,28 @@ func _() {
...
@@ -115,28 +115,28 @@ func _() {
//
line
at
a
time
.
//
line
at
a
time
.
func
_
()
{
func
_
()
{
const
_
=
0
;
const
_
=
0
const
_
=
1
;
const
_
=
1
type
_
int
;
type
_
int
type
_
float
;
type
_
float
var
_
=
0
;
var
_
=
0
var
x
=
1
;
var
x
=
1
//
Each
use
(
x
)
call
below
should
have
at
most
one
empty
line
before
and
after
.
//
Each
use
(
x
)
call
below
should
have
at
most
one
empty
line
before
and
after
.
use
(
x
)
;
use
(
x
)
if
x
<
x
{
if
x
<
x
{
use
(
x
)
;
use
(
x
)
}
else
{
}
else
{
use
(
x
)
;
use
(
x
)
}
}
}
}
...
@@ -155,21 +155,21 @@ func _() {
...
@@ -155,21 +155,21 @@ func _() {
func
_
()
{
func
_
()
{
L
:
_
=
0
;
L
:
_
=
0
}
}
func
_
()
{
func
_
()
{
//
this
comment
should
be
indented
//
this
comment
should
be
indented
L
:
_
=
0
;
L
:
_
=
0
}
}
func
_
()
{
func
_
()
{
for
{
for
{
L1
:
_
=
0
;
L1
:
_
=
0
L2
:
L2
:
_
=
0
;
_
=
0
}
}
}
}
...
@@ -177,25 +177,25 @@ func _() {
...
@@ -177,25 +177,25 @@ func _() {
func
_
()
{
func
_
()
{
//
this
comment
should
be
indented
//
this
comment
should
be
indented
for
{
for
{
L1
:
_
=
0
;
L1
:
_
=
0
L2
:
L2
:
_
=
0
;
_
=
0
}
}
}
}
func
_
()
{
func
_
()
{
if
{
if
{
_
=
0
;
_
=
0
}
}
_
=
0
;
//
the
indentation
here
should
not
be
affected
by
the
long
label
name
_
=
0
//
the
indentation
here
should
not
be
affected
by
the
long
label
name
AnOverlongLabel
:
AnOverlongLabel
:
_
=
0
;
_
=
0
if
{
if
{
_
=
0
;
_
=
0
}
}
_
=
0
;
_
=
0
L
:
_
=
0
;
L
:
_
=
0
}
}
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