Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
d7f1f53e
Commit
d7f1f53e
authored
Jul 08, 2009
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
printer_test: first cut
R=rsc DELTA=169 (168 added, 0 deleted, 1 changed) OCL=31319 CL=31321
parent
7c534e1b
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
170 additions
and
1 deletion
+170
-1
Makefile
src/pkg/go/printer/Makefile
+2
-1
golden1.go
src/pkg/go/printer/data/golden1.go
+25
-0
golden1.x
src/pkg/go/printer/data/golden1.x
+3
-0
source1.go
src/pkg/go/printer/data/source1.go
+26
-0
printer_test.go
src/pkg/go/printer/printer_test.go
+114
-0
No files found.
src/pkg/go/printer/Makefile
View file @
d7f1f53e
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
# Use of this source code is governed by a BSD-style
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
# license that can be found in the LICENSE file.
# DO NOT EDIT. Automatically generated by gobuild.
# DO NOT EDIT. Automatically generated by gobuild.
# gobuild -m >Makefile
# gobuild -m >Makefile
...
@@ -20,7 +21,7 @@ test: packages
...
@@ -20,7 +21,7 @@ test: packages
coverage
:
packages
coverage
:
packages
gotest
gotest
6cov
-g
`
pwd
`
|
grep
-v
'_test\.go:'
6cov
-g
$
$(pwd)
|
grep
-v
'_test\.go:'
%.$O
:
%.go
%.$O
:
%.go
$(GC)
-I_obj
$*
.go
$(GC)
-I_obj
$*
.go
...
...
src/pkg/go/printer/data/golden1.go
0 → 100644
View file @
d7f1f53e
package
main
import
"fmt"
// fmt
const
c0
=
0
// zero
const
(
c1
=
iota
;
// c1
c2
// c2
)
type
T
struct
{
a
,
b
,
c
int
// 3 fields
}
var
x
int
// x
var
()
func
f0
()
{
const
pi
=
3.14
;
var
s1
struct
{}
var
s2
struct
{}
=
struct
{}{};
x
:=
pi
}
src/pkg/go/printer/data/golden1.x
0 → 100644
View file @
d7f1f53e
package
main
type
T
struct
src/pkg/go/printer/data/source1.go
0 → 100644
View file @
d7f1f53e
package
main
import
"fmt"
// fmt
const
c0
=
0
;
// zero
const
(
c1
=
iota
;
// c1
c2
;
// c2
)
type
T
struct
{
a
,
b
,
c
int
// 3 fields
}
var
x
int
;
// x
var
()
func
f0
()
{
const
pi
=
3.14
;
// pi
var
s1
struct
{}
var
s2
struct
{}
=
struct
{}{};
x
:=
pi
;
}
src/pkg/go/printer/printer_test.go
0 → 100644
View file @
d7f1f53e
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
printer
import
(
"bytes"
;
"io"
;
"go/ast"
;
"go/parser"
;
"go/printer"
;
"os"
;
"path"
;
"tabwriter"
;
"testing"
;
)
const
(
tabwidth
=
4
;
padding
=
1
;
tabchar
=
' '
;
)
func
lineString
(
text
[]
byte
,
i
int
)
string
{
i0
:=
i
;
for
i
<
len
(
text
)
&&
text
[
i
]
!=
'\n'
{
i
++
;
}
return
string
(
text
[
i0
:
i
]);
}
func
check
(
t
*
testing
.
T
,
source
,
golden
string
,
exports
bool
)
{
// get source
src
,
err
:=
io
.
ReadFile
(
source
);
if
err
!=
nil
{
t
.
Error
(
err
);
return
;
}
// parse source
prog
,
err
:=
parser
.
Parse
(
src
,
parser
.
ParseComments
);
if
err
!=
nil
{
t
.
Error
(
err
);
return
;
}
// filter exports if necessary
if
exports
{
ast
.
FilterExports
(
prog
);
// ignore result
}
// format source
var
buf
bytes
.
Buffer
;
w
:=
tabwriter
.
NewWriter
(
&
buf
,
tabwidth
,
padding
,
tabchar
,
0
);
Fprint
(
w
,
prog
,
0
);
w
.
Flush
();
res
:=
buf
.
Data
();
// get golden
gld
,
err
:=
io
.
ReadFile
(
golden
);
if
err
!=
nil
{
t
.
Error
(
err
);
return
;
}
// compare lengths
if
len
(
res
)
!=
len
(
gld
)
{
t
.
Errorf
(
"len = %d, expected %d (= len(%s))"
,
len
(
res
),
len
(
gld
),
golden
);
}
// compare contents
for
i
,
line
,
offs
:=
0
,
1
,
0
;
i
<
len
(
res
)
&&
i
<
len
(
gld
);
i
++
{
ch
:=
res
[
i
];
if
ch
!=
gld
[
i
]
{
t
.
Errorf
(
"%s:%d:%d: %s"
,
source
,
line
,
i
-
offs
+
1
,
lineString
(
res
,
offs
));
t
.
Errorf
(
"%s:%d:%d: %s"
,
golden
,
line
,
i
-
offs
+
1
,
lineString
(
gld
,
offs
));
t
.
Error
();
return
;
}
if
ch
==
'\n'
{
line
++
;
offs
=
i
+
1
;
}
}
}
const
dataDir
=
"data"
;
type
entry
struct
{
source
,
golden
string
;
exports
bool
;
}
// Use gofmt to create/update the respective golden files:
//
// gofmt source.go > golden.go
// gofmt -x source.go > golden.x
//
var
data
=
[]
entry
{
entry
{
"source1.go"
,
"golden1.go"
,
false
},
entry
{
"source1.go"
,
"golden1.x"
,
true
},
}
func
Test
(
t
*
testing
.
T
)
{
for
_
,
e
:=
range
data
{
check
(
t
,
path
.
Join
(
dataDir
,
e
.
source
),
path
.
Join
(
dataDir
,
e
.
golden
),
e
.
exports
);
}
}
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