This repository has been archived on 2023-11-08. You can view files and clone it, but cannot push or open issues/pull-requests.
imp/format/format_test.go

66 lines
1.1 KiB
Go

package format
import (
"bytes"
"errors"
"testing"
"github.com/matryer/is"
)
func TestSource(t *testing.T) {
module := "foo.bar"
assert := is.New(t)
_, err := Source(noImports, module)
assert.True(errors.Is(err, ErrNoImports)) // Should get error for no imports
_, err = Source(fakeImports, module)
assert.True(errors.Is(err, ErrNoImports)) // Should get error for no "real" imports
formatted, err := Source(before, module)
assert.NoErr(err) // Should be able to format before block
assert.True(bytes.Equal(formatted, after)) // Formatted should match after block
}
var (
noImports = []byte(`package main
func main() {}`)
fakeImports = []byte(`package main
func main() {
s := "import \"fmt\""
_ = s
}`)
before = []byte(`package main
import (
"foo.bar/baz"
"net/http"
"github.com/peterbourgon/ff/v3"
"io"
"os"
"github.com/matryer/is"
"foo.bar/bux"
)
func main() {}`)
after = []byte(`package main
import (
"io"
"net/http"
"os"
"foo.bar/baz"
"foo.bar/bux"
"github.com/matryer/is"
"github.com/peterbourgon/ff/v3"
)
func main() {}`)
)