-
Notifications
You must be signed in to change notification settings - Fork 280
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: add tests for isGenerated in the lint package
- Loading branch information
1 parent
3bead6f
commit 24d099a
Showing
2 changed files
with
31 additions
and
48 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,31 @@ | ||
package lint | ||
|
||
import "testing" | ||
|
||
// TestIsGenerated tests isGenerated function. | ||
func TestIsGenerated(t *testing.T) { //revive:disable-line:exported | ||
tests := []struct { | ||
source string | ||
generated bool | ||
}{ | ||
{"// Code Generated by some tool. DO NOT EDIT.", false}, | ||
{"// Code generated by some tool. DO NOT EDIT.", true}, | ||
{"// Code generated by some tool. DO NOT EDIT", false}, | ||
{"// Code generated DO NOT EDIT.", true}, | ||
{"// Code generated DO NOT EDIT.", false}, | ||
{"\t\t// Code generated by some tool. DO NOT EDIT.\npackage foo\n", false}, | ||
{"// Code generated by some tool. DO NOT EDIT.\npackage foo\n", true}, | ||
{"package foo\n// Code generated by some tool. DO NOT EDIT.\ntype foo int\n", true}, | ||
{"package foo\n // Code generated by some tool. DO NOT EDIT.\ntype foo int\n", false}, | ||
{"package foo\n// Code generated by some tool. DO NOT EDIT. \ntype foo int\n", false}, | ||
{"package foo\ntype foo int\n// Code generated by some tool. DO NOT EDIT.\n", true}, | ||
{"package foo\ntype foo int\n// Code generated by some tool. DO NOT EDIT.", true}, | ||
} | ||
|
||
for i, test := range tests { | ||
got := isGenerated([]byte(test.source)) | ||
if got != test.generated { | ||
t.Errorf("test %d, isGenerated() = %v, want %v", i, got, test.generated) | ||
} | ||
} | ||
} |
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