From 2468296c2aa5b3297dac1edf0be1d7a8161550fb Mon Sep 17 00:00:00 2001 From: Mario Carrion Date: Mon, 24 Dec 2018 15:38:03 -0500 Subject: [PATCH] nitpicker: add more tests --- nitpicking_test.go | 32 ++++++++++++++++++++++++++++++++ testdata/imports_valid.go | 13 +++++++++++++ testdata/nitpicker_valid.go | 29 +++++++++++++++++++++++++++++ validator_test.go | 5 +++++ 4 files changed, 79 insertions(+) create mode 100644 testdata/imports_valid.go create mode 100644 testdata/nitpicker_valid.go diff --git a/nitpicking_test.go b/nitpicking_test.go index 551852f..f220c61 100644 --- a/nitpicking_test.go +++ b/nitpicking_test.go @@ -1 +1,33 @@ package nitpicking_test + +import ( + "path/filepath" + "testing" + + "github.com/MarioCarrion/nitpicking" +) + +func TestNitpicker_Validate(t *testing.T) { + tests := [...]struct { + name string + filename string + expectedError bool + }{ + { + "OK", + "nitpicker_valid.go", + false, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(ts *testing.T) { + n := nitpicking.Nitpicker{} + + if err := n.Validate(filepath.Join("testdata", tt.filename)); tt.expectedError != (err != nil) { + + ts.Fatalf("expected error %t, got %s", tt.expectedError, err) + } + }) + } +} diff --git a/testdata/imports_valid.go b/testdata/imports_valid.go new file mode 100644 index 0000000..cd34ac1 --- /dev/null +++ b/testdata/imports_valid.go @@ -0,0 +1,13 @@ +package testdata + +import ( + "fmt" + + "github.com/pkg/errors" + + "github.com/MarioCarrion/nitpicking" +) + +func ImportsValid() { + fmt.Println("%s", errors.New(""), nitpicking.Nitpicker{}) +} diff --git a/testdata/nitpicker_valid.go b/testdata/nitpicker_valid.go new file mode 100644 index 0000000..bcaf4da --- /dev/null +++ b/testdata/nitpicker_valid.go @@ -0,0 +1,29 @@ +package testdata + +import ( + "fmt" +) + +const ( + FirstConst = "1" +) + +const ( + SecondConst = "2" +) + +type ( + Example struct{} +) + +var ( + varOne = 1 +) + +func NitpickerValid() { + fmt.Println("") +} + +func (*Example) ExampleMethod() { + fmt.Println("") +} diff --git a/validator_test.go b/validator_test.go index abf8370..99c49b5 100644 --- a/validator_test.go +++ b/validator_test.go @@ -16,6 +16,11 @@ func TestImportsValidator_Validate(t *testing.T) { filename string expectedError bool }{ + { + "OK", + "imports_valid.go", + false, + }, { "Error: parenthesized declaration", "imports_paren.go",