-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package internal | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestImportsCode(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
code string | ||
want string | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "simple format", | ||
code: `package main | ||
import "fmt" | ||
func main(){ | ||
fmt.Println("hello")}`, | ||
want: `package main | ||
import "fmt" | ||
func main() { | ||
fmt.Println("hello") | ||
} | ||
`, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "invalid code", | ||
code: "invalid{", | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "already formatted", | ||
code: `package main | ||
import "fmt" | ||
func main() { | ||
fmt.Println("hello") | ||
}`, | ||
want: `package main | ||
import "fmt" | ||
func main() { | ||
fmt.Println("hello") | ||
} | ||
`, | ||
wantErr: false, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := ImportsCode(tt.code) | ||
if tt.wantErr { | ||
require.Error(t, err) | ||
return | ||
} | ||
require.NoError(t, err) | ||
require.Equal(t, tt.want, string(got)) | ||
}) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package version | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestVersion(t *testing.T) { | ||
t.Run("version", func(t *testing.T) { | ||
require.Equal(t, "v1.0.0", SemVer{Major: 1}.String()) | ||
}) | ||
|
||
t.Run("self version", func(t *testing.T) { | ||
require.Empty(t, SelfVersion()) | ||
}) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.