Skip to content

Commit

Permalink
Increase test coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Krivak committed Oct 26, 2020
1 parent 3d59659 commit bd073f1
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
17 changes: 17 additions & 0 deletions checks_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
package godot

import (
"go/ast"
"testing"
)

func TestCheckComments(t *testing.T) {
// Check only case with empty input, other cases are checked in TestRun

comments := []comment{
{ast: nil},
{ast: &ast.CommentGroup{List: nil}},
}
issues, err := checkComments(nil, comments, Settings{})
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
if len(issues) > 0 {
t.Fatalf("Unexpected issues: %d", len(issues))
}
}

func TestCheckPeriod(t *testing.T) {
testCases := []struct {
name string
Expand Down
18 changes: 9 additions & 9 deletions godot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestRun(t *testing.T) {
}
}
}
issues, err := Run(f, fset, Settings{Scope: tt.scope, Period: true})
issues, err := Run(f, fset, Settings{Scope: tt.scope, Period: true, Capital: true})
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
Expand All @@ -81,15 +81,15 @@ func TestFix(t *testing.T) {

t.Run("file not found", func(t *testing.T) {
path := filepath.Join("testdata", "not-exists.go")
_, err := Fix(path, nil, nil, Settings{Period: true})
_, err := Fix(path, nil, nil, Settings{})
if err == nil {
t.Fatal("Expected error, got nil")
}
})

t.Run("empty file", func(t *testing.T) {
path := filepath.Join("testdata", "empty.go")
fixed, err := Fix(path, nil, nil, Settings{Period: true})
fixed, err := Fix(path, nil, nil, Settings{})
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
Expand All @@ -101,7 +101,7 @@ func TestFix(t *testing.T) {
t.Run("scope: decl", func(t *testing.T) {
expected := strings.ReplaceAll(string(content), "[DECL]", "[DECL].")

fixed, err := Fix(testFile, file, fset, Settings{Scope: DeclScope, Period: true})
fixed, err := Fix(testFile, file, fset, Settings{Scope: DeclScope, Period: true, Capital: true})
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
Expand All @@ -113,7 +113,7 @@ func TestFix(t *testing.T) {
expected := strings.ReplaceAll(string(content), "[DECL]", "[DECL].")
expected = strings.ReplaceAll(expected, "[TOP]", "[TOP].")

fixed, err := Fix(testFile, file, fset, Settings{Scope: TopLevelScope, Period: true})
fixed, err := Fix(testFile, file, fset, Settings{Scope: TopLevelScope, Period: true, Capital: true})
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
Expand All @@ -126,7 +126,7 @@ func TestFix(t *testing.T) {
expected = strings.ReplaceAll(expected, "[TOP]", "[TOP].")
expected = strings.ReplaceAll(expected, "[ALL]", "[ALL].")

fixed, err := Fix(testFile, file, fset, Settings{Scope: AllScope, Period: true})
fixed, err := Fix(testFile, file, fset, Settings{Scope: AllScope, Period: true, Capital: true})
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
Expand Down Expand Up @@ -154,7 +154,7 @@ func TestReplace(t *testing.T) {

t.Run("file not found", func(t *testing.T) {
path := filepath.Join("testdata", "not-exists.go")
err := Replace(path, nil, nil, Settings{Period: true})
err := Replace(path, nil, nil, Settings{})
if err == nil {
t.Fatal("Expected error, got nil")
}
Expand All @@ -166,7 +166,7 @@ func TestReplace(t *testing.T) {
}()
expected := strings.ReplaceAll(string(content), "[DECL]", "[DECL].")

err := Replace(testFile, file, fset, Settings{Scope: DeclScope, Period: true})
err := Replace(testFile, file, fset, Settings{Scope: DeclScope, Period: true, Capital: true})
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
Expand All @@ -186,7 +186,7 @@ func TestReplace(t *testing.T) {
expected = strings.ReplaceAll(expected, "[TOP]", "[TOP].")
expected = strings.ReplaceAll(expected, "[ALL]", "[ALL].")

err := Replace(testFile, file, fset, Settings{Scope: AllScope, Period: true})
err := Replace(testFile, file, fset, Settings{Scope: AllScope, Period: true, Capital: true})
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion testdata/check/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func Sum(a, b int) int {
a++
b++

return a + b // inline comment [ALL]
return a + b // Inline comment [ALL]
}

// Declaration multiline comment
Expand Down
2 changes: 1 addition & 1 deletion testdata/get/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ func Example() { // top level inline comment [ALL]
fmt.Println("hello, world")
}

prn() // inline comment [ALL]
prn() // Inline comment [ALL]
}

0 comments on commit bd073f1

Please sign in to comment.