-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Norman Gehrsitz <[email protected]>
- Loading branch information
Showing
38 changed files
with
320 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package gci | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
"path" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/daixiang0/gci/pkg/gci/sections" | ||
"github.com/daixiang0/gci/pkg/io" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
var testFilesPath = "internal/testdata" | ||
|
||
func isTestInputFile(file os.FileInfo) bool { | ||
return !file.IsDir() && strings.HasSuffix(file.Name(), ".in.go") | ||
} | ||
|
||
func TestRun(t *testing.T) { | ||
testFiles, err := io.FindFilesForPath(testFilesPath, isTestInputFile) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
for _, testFile := range testFiles { | ||
fileBaseName := strings.TrimSuffix(testFile, ".in.go") | ||
t.Run(fileBaseName, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
gciCfg, err := initializeGciConfigFromYAML(fileBaseName + ".cfg.yaml") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
_, formattedFile, err := LoadFormatGoFile(io.File{fileBaseName + ".in.go"}, *gciCfg) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
expectedOutput, err := ioutil.ReadFile(fileBaseName + ".out.go") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
assert.Equal(t, string(expectedOutput), string(formattedFile), "output") | ||
assert.NoError(t, err) | ||
}) | ||
} | ||
} | ||
|
||
func TestInitGciConfigFromEmptyYAML(t *testing.T) { | ||
gciCfg, err := initializeGciConfigFromYAML(path.Join(testFilesPath, "defaultValues.cfg.yaml")) | ||
assert.NoError(t, err) | ||
_ = gciCfg | ||
assert.Equal(t, DefaultSections(), gciCfg.Sections) | ||
assert.Equal(t, DefaultSectionSeparators(), gciCfg.SectionSeparators) | ||
assert.False(t, gciCfg.Debug) | ||
assert.False(t, gciCfg.NoInlineComments) | ||
assert.False(t, gciCfg.NoPrefixComments) | ||
} | ||
|
||
func TestInitGciConfigFromYAML(t *testing.T) { | ||
gciCfg, err := initializeGciConfigFromYAML(path.Join(testFilesPath, "configTest.cfg.yaml")) | ||
assert.NoError(t, err) | ||
_ = gciCfg | ||
assert.Equal(t, SectionList{sections.DefaultSection{}}, gciCfg.Sections) | ||
assert.Equal(t, SectionList{sections.CommentLine{"---"}}, gciCfg.SectionSeparators) | ||
assert.False(t, gciCfg.Debug) | ||
assert.True(t, gciCfg.NoInlineComments) | ||
assert.True(t, gciCfg.NoPrefixComments) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
sections: | ||
- Standard | ||
- Default | ||
- Prefix(github.com/local) | ||
- Prefix(github.com/daixiang0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package main | ||
import ( | ||
"fmt" | ||
|
||
g "github.com/golang" | ||
|
||
"github.com/daixiang0/gci" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package main | ||
import ( | ||
"fmt" | ||
|
||
g "github.com/golang" | ||
|
||
"github.com/daixiang0/gci" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
sections: | ||
- Standard | ||
- Default | ||
- Prefix(github.com/local) | ||
- Prefix(github.com/daixiang0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" // https://pkg.go.dev/fmt | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" // https://pkg.go.dev/fmt | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
sections: | ||
- default | ||
sectionseparators: | ||
- comment(---) | ||
no-inlineComments: true | ||
no-prefixComments: true | ||
Debug: true |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
sections: | ||
- Standard | ||
- Default | ||
- Prefix(github.com/local) | ||
- Prefix(github.com/daixiang0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package main | ||
|
||
import ( | ||
// foo | ||
"fmt" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package main | ||
|
||
import ( | ||
// foo | ||
"fmt" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
sections: | ||
- Standard | ||
- Default | ||
- Prefix(github.com/local) | ||
- Prefix(github.com/daixiang0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package proc | ||
|
||
import ( | ||
"context" // in-line comment | ||
"fmt" | ||
"os" | ||
|
||
//nolint:depguard // A multi-line comment explaining why in | ||
// this one case it's OK to use os/exec even though depguard | ||
// is configured to force us to use dlib/exec instead. | ||
"os/exec" | ||
|
||
"golang.org/x/sys/unix" | ||
"github.com/local/dlib/dexec" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package proc | ||
|
||
import ( | ||
"context" // in-line comment | ||
"fmt" | ||
"os" | ||
//nolint:depguard // A multi-line comment explaining why in | ||
// this one case it's OK to use os/exec even though depguard | ||
// is configured to force us to use dlib/exec instead. | ||
"os/exec" | ||
|
||
"golang.org/x/sys/unix" | ||
|
||
"github.com/local/dlib/dexec" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
sections: | ||
- Standard | ||
- Default | ||
- Prefix(github.com/local) | ||
- Prefix(github.com/daixiang0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
sections: | ||
- Standard | ||
- Default | ||
- Prefix(github.com/local) | ||
- Prefix(github.com/daixiang0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/forbidden/pkg" //nolint:depguard | ||
|
||
_ "github.com/daixiang0/gci" //nolint:depguard | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/forbidden/pkg" //nolint:depguard | ||
|
||
_ "github.com/daixiang0/gci" //nolint:depguard | ||
) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
sections: | ||
- Standard | ||
- Default | ||
- Prefix(github.com/local) | ||
- Prefix(github.com/daixiang0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package main | ||
import ( | ||
"golang.org/x/tools" | ||
|
||
"fmt" | ||
|
||
"github.com/daixiang0/gci" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package main | ||
import ( | ||
"fmt" | ||
|
||
"golang.org/x/tools" | ||
|
||
"github.com/daixiang0/gci" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package proc | ||
|
||
import ( | ||
"context" // in-line comment | ||
|
||
//nolint:depguard // A multi-line comment explaining why in | ||
// this one case it's OK to use os/exec even though depguard | ||
// is configured to force us to use dlib/exec instead. | ||
"os/exec" | ||
) | ||
|
||
func main() { | ||
_ = context.Canceled | ||
_ = exec.ErrNotFound | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
sections: | ||
- Standard | ||
- Default | ||
- Prefix(github.com/local) | ||
- Prefix(github.com/daixiang0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"github.com/golang" // golang | ||
alias "github.com/daixiang0/gci" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/golang" // golang | ||
|
||
alias "github.com/daixiang0/gci" | ||
) |
5 changes: 5 additions & 0 deletions
5
pkg/gci/internal/testdata/with-above-comment-and-alias.cfg.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
sections: | ||
- Standard | ||
- Default | ||
- Prefix(github.com/local) | ||
- Prefix(github.com/daixiang0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package main | ||
import ( | ||
"fmt" | ||
// golang | ||
_ "github.com/golang" | ||
"github.com/daixiang0/gci" | ||
) |
9 changes: 9 additions & 0 deletions
9
pkg/gci/internal/testdata/with-above-comment-and-alias.out.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package main | ||
import ( | ||
"fmt" | ||
|
||
// golang | ||
_ "github.com/golang" | ||
|
||
"github.com/daixiang0/gci" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
sections: | ||
- Standard | ||
- Default | ||
- Prefix(github.com/local) | ||
- Prefix(github.com/daixiang0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package main | ||
import ( | ||
"fmt" | ||
g "github.com/golang" | ||
"github.com/daixiang0/gci" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package main | ||
import ( | ||
"fmt" | ||
|
||
g "github.com/golang" | ||
|
||
"github.com/daixiang0/gci" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
sections: | ||
- Standard | ||
- Default | ||
- Prefix(github.com/local) | ||
- Prefix(github.com/daixiang0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package main | ||
import ( | ||
"fmt" | ||
_ "github.com/golang" // golang | ||
"github.com/daixiang0/gci" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package main | ||
import ( | ||
"fmt" | ||
|
||
_ "github.com/golang" // golang | ||
|
||
"github.com/daixiang0/gci" | ||
) |