go/gcexportdata: make example portable to MS Windows, 2nd attempt

(The first was go-review.googlesource.com/c/31813)

Fixes issue golang/go#17565

Change-Id: I61c124e041af689913aedebdde654197c5526228
Reviewed-on: https://go-review.googlesource.com/32034
Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
Alan Donovan 2016-10-25 16:43:39 -04:00
parent 17d0fe57ec
commit 0db92ca630
1 changed files with 9 additions and 5 deletions

View File

@ -52,9 +52,8 @@ func ExampleRead() {
println := pkg.Scope().Lookup("Println") println := pkg.Scope().Lookup("Println")
posn := fset.Position(println.Pos()) posn := fset.Position(println.Pos())
posn.Line = 123 // make example deterministic posn.Line = 123 // make example deterministic
posn.Filename = filepath.ToSlash(posn.Filename) // make example deterministic
fmt.Printf("Println type: %s\n", println.Type()) fmt.Printf("Println type: %s\n", println.Type())
fmt.Printf("Println location: %s\n", posn) fmt.Printf("Println location: %s\n", slashify(posn))
// Output: // Output:
// //
@ -95,7 +94,7 @@ const TwoPi = 2 * math.Pi
pi.Name(), pi.Name(),
pi.Type(), pi.Type(),
pi.(*types.Const).Val(), pi.(*types.Const).Val(),
fset.Position(pi.Pos())) slashify(fset.Position(pi.Pos())))
// object in source package // object in source package
twopi := pkg.Scope().Lookup("TwoPi") twopi := pkg.Scope().Lookup("TwoPi")
@ -103,10 +102,15 @@ const TwoPi = 2 * math.Pi
twopi.Name(), twopi.Name(),
twopi.Type(), twopi.Type(),
twopi.(*types.Const).Val(), twopi.(*types.Const).Val(),
fset.Position(twopi.Pos())) slashify(fset.Position(twopi.Pos())))
// Output: // Output:
// //
// const math.Pi untyped float = 3.14159 // $GOROOT/src/math/const.go:11:1 // const math.Pi untyped float = 3.14159 // $GOROOT/src/math/const.go:11:1
// const TwoPi untyped float = 6.28319 // twopi.go:5:7 // const TwoPi untyped float = 6.28319 // twopi.go:5:7
} }
func slashify(posn token.Position) token.Position {
posn.Filename = filepath.ToSlash(posn.Filename) // for MS Windows portability
return posn
}