-
-
Notifications
You must be signed in to change notification settings - Fork 561
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use doc.IsPredeclared() and token.IsKeyword() for codegen.fixReserved…
…Go() (#3599) * Add test for codegen.fixReservedGo() * Use doc.IsPredeclared() and token.IsKeyword() for codegen.fixReservedGo(). * Add isPackage --------- Co-authored-by: Raphael Simon <[email protected]>
- Loading branch information
Showing
3 changed files
with
35 additions
and
63 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
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,26 @@ | ||
package codegen | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestFixReservedGo(t *testing.T) { | ||
cases := map[string]struct { | ||
w string | ||
want string | ||
}{ | ||
"predeclared type": {w: "bool", want: "bool_"}, | ||
"predeclared constant": {w: "true", want: "true_"}, | ||
"predeclared zero value": {w: "nil", want: "nil_"}, | ||
"predeclared function": {w: "append", want: "append_"}, | ||
"non predeclared identifier": {w: "foo", want: "foo"}, | ||
"package": {w: "fmt", want: "fmt_"}, | ||
} | ||
for k, tc := range cases { | ||
t.Run(k, func(t *testing.T) { | ||
assert.Equal(t, tc.want, fixReservedGo(tc.w)) | ||
}) | ||
} | ||
} |
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