mirror of
https://github.com/golang/go
synced 2024-11-18 19:54:44 -07:00
1fc30e1f4c
In an effort to be idiomatic, I made the regtest func signature func(context.Context, testing.T, *Env), despite the fact that Env already has a Context and a T. This just ended up causing more confusion, as it's not clear which Context or T to use. Remove this and just use the fields on Env. Change-Id: I54da1fdfe6ce17a67601b2af8640d4d2ea676e8c Reviewed-on: https://go-review.googlesource.com/c/tools/+/225157 Run-TryBot: Robert Findley <rfindley@google.com> Reviewed-by: Rebecca Stambler <rstambler@golang.org> Reviewed-by: Heschi Kreinick <heschi@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
93 lines
1.6 KiB
Go
93 lines
1.6 KiB
Go
package regtest
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
const unformattedProgram = `
|
|
-- main.go --
|
|
package main
|
|
import "fmt"
|
|
func main( ) {
|
|
fmt.Println("Hello World.")
|
|
}
|
|
-- main.go.golden --
|
|
package main
|
|
|
|
import "fmt"
|
|
|
|
func main() {
|
|
fmt.Println("Hello World.")
|
|
}
|
|
`
|
|
|
|
func TestFormatting(t *testing.T) {
|
|
runner.Run(t, unformattedProgram, func(env *Env) {
|
|
env.OpenFile("main.go")
|
|
env.FormatBuffer("main.go")
|
|
got := env.E.BufferText("main.go")
|
|
want := env.ReadWorkspaceFile("main.go.golden")
|
|
if got != want {
|
|
t.Errorf("\n## got formatted file:\n%s\n## want:\n%s", got, want)
|
|
}
|
|
})
|
|
}
|
|
|
|
const disorganizedProgram = `
|
|
-- main.go --
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"errors"
|
|
)
|
|
func main( ) {
|
|
fmt.Println(errors.New("bad"))
|
|
}
|
|
-- main.go.organized --
|
|
package main
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
)
|
|
func main( ) {
|
|
fmt.Println(errors.New("bad"))
|
|
}
|
|
-- main.go.formatted --
|
|
package main
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
)
|
|
|
|
func main() {
|
|
fmt.Println(errors.New("bad"))
|
|
}
|
|
`
|
|
|
|
func TestOrganizeImports(t *testing.T) {
|
|
runner.Run(t, disorganizedProgram, func(env *Env) {
|
|
env.OpenFile("main.go")
|
|
env.OrganizeImports("main.go")
|
|
got := env.E.BufferText("main.go")
|
|
want := env.ReadWorkspaceFile("main.go.organized")
|
|
if got != want {
|
|
t.Errorf("\n## got formatted file:\n%s\n## want:\n%s", got, want)
|
|
}
|
|
})
|
|
}
|
|
|
|
func TestFormattingOnSave(t *testing.T) {
|
|
runner.Run(t, disorganizedProgram, func(env *Env) {
|
|
env.OpenFile("main.go")
|
|
env.SaveBuffer("main.go")
|
|
got := env.E.BufferText("main.go")
|
|
want := env.ReadWorkspaceFile("main.go.formatted")
|
|
if got != want {
|
|
t.Errorf("\n## got formatted file:\n%s\n## want:\n%s", got, want)
|
|
}
|
|
})
|
|
}
|