-
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 <norman.gehrsitz@gmx.de>
- Loading branch information
Showing
47 changed files
with
388 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" | ||
) |
2 changes: 2 additions & 0 deletions
2
pkg/gci/internal/testdata/comment-whithout-whitespace.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,2 @@ | ||
sections: | ||
- Default |
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 proc | ||
|
||
import ( | ||
"context"// no separating whitespace here //nolint:confusion | ||
) |
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 proc | ||
|
||
import ( | ||
"context" // no separating whitespace here //nolint:confusion | ||
) |
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,5 @@ | ||
sections: | ||
- comment( Do not forget to run Gci) | ||
- default | ||
sectionseparators: [] | ||
no-prefixComments: true |
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 ( | ||
//Do not forget to run Gci | ||
"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 ( | ||
// Do not forget to run Gci | ||
|
||
"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,8 @@ | ||
sections: | ||
- comment( Std imports):std:comment( Std imports) | ||
- comment( Github):prefix(github.com):comment( Github) | ||
sectionseparators: | ||
- newline | ||
- comment( --------------------------) | ||
- newline | ||
no-prefixComments: true |
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,16 @@ | ||
package proc | ||
|
||
import ( | ||
// Std imports | ||
"os" | ||
"context" // is required | ||
"fmt" | ||
// Std imports | ||
|
||
// -------------------------- | ||
|
||
// Github | ||
"github.com/local/dlib/dexec" | ||
"github.com/daixiang0/gci" | ||
// Github | ||
) |
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,16 @@ | ||
package proc | ||
|
||
import ( | ||
// Std imports | ||
"context" // is required | ||
"fmt" | ||
"os" | ||
// Std imports | ||
|
||
// -------------------------- | ||
|
||
// Github | ||
"github.com/daixiang0/gci" | ||
"github.com/local/dlib/dexec" | ||
// Github | ||
) |
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" | ||
) |
Oops, something went wrong.