Skip to content

Commit

Permalink
Add test for a file without code.
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Krivak committed May 23, 2021
1 parent 5e050a6 commit 17fccac
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
42 changes: 42 additions & 0 deletions godot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,25 @@ func TestFix(t *testing.T) {
assertEqualContent(t, string(content), string(fixed))
})

t.Run("no code", func(t *testing.T) {
testFile := filepath.Join("testdata", "nocode", "main.go")
fset := token.NewFileSet()
f, err := parser.ParseFile(fset, testFile, nil, parser.ParseComments)
if err != nil {
t.Fatalf("Failed to parse input file: %v", err)
}
content, err := ioutil.ReadFile(testFile)
if err != nil {
t.Fatalf("Failed to read input file: %v", err)
}

fixed, err := Fix(testFile, f, fset, Settings{})
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
assertEqualContent(t, string(content), string(fixed))
})

testFile := filepath.Join("testdata", "check", "main.go")
fset := token.NewFileSet()
file, err := parser.ParseFile(fset, testFile, nil, parser.ParseComments)
Expand Down Expand Up @@ -282,6 +301,29 @@ func TestReplace(t *testing.T) {
assertEqualContent(t, string(content), string(fixed))
})

t.Run("no code", func(t *testing.T) {
testFile := filepath.Join("testdata", "nocode", "main.go")
fset := token.NewFileSet()
f, err := parser.ParseFile(fset, testFile, nil, parser.ParseComments)
if err != nil {
t.Fatalf("Failed to parse input file: %v", err)
}
content, err := ioutil.ReadFile(testFile)
if err != nil {
t.Fatalf("Failed to read input file: %v", err)
}

err = Replace(testFile, f, fset, Settings{})
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
fixed, err := ioutil.ReadFile(testFile)
if err != nil {
t.Fatalf("Failed to read fixed file: %v", err)
}
assertEqualContent(t, string(content), string(fixed))
})

testFile := filepath.Join("testdata", "check", "main.go")
fset := token.NewFileSet()
file, err := parser.ParseFile(fset, testFile, nil, parser.ParseComments)
Expand Down
1 change: 1 addition & 0 deletions testdata/nocode/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package nocode

0 comments on commit 17fccac

Please sign in to comment.