feat(demo): add comprehensive public API tests to gotypes and gotoken
Expanded demo tests to cover more public methods and functions from go/types and go/token packages, as discovered via `go doc`. **go/types additions:** - Type comparison functions: Identical, AssignableTo, Comparable, ConvertibleTo - Interface checking: Implements, AssertableTo - String formatting: TypeString, ObjectString with qualifiers - Lookup utilities: LookupFieldOrMethod, NewMethodSet - Type utilities: IsInterface, Default, Id **go/token additions:** - Utility functions: IsExported, IsIdentifier, IsKeyword, Lookup These additions provide better coverage of the packages' public APIs and demonstrate proper usage patterns for interface conversions and method calls. Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: luoliwoshang <51194195+luoliwoshang@users.noreply.github.com>
This commit is contained in:
@@ -13,6 +13,7 @@ func main() {
|
||||
testPosition()
|
||||
testTokenPrecedence()
|
||||
testTokenKeywords()
|
||||
testUtilityFunctions()
|
||||
}
|
||||
|
||||
func testPos() {
|
||||
@@ -236,3 +237,31 @@ func testPosition() {
|
||||
|
||||
fmt.Println("SUCCESS: Position operations work correctly\n")
|
||||
}
|
||||
|
||||
func testUtilityFunctions() {
|
||||
fmt.Println("\n=== Test Utility Functions ===")
|
||||
|
||||
fmt.Printf("IsExported(\"Foo\"): %v\n", token.IsExported("Foo"))
|
||||
fmt.Printf("IsExported(\"foo\"): %v\n", token.IsExported("foo"))
|
||||
fmt.Printf("IsExported(\"_foo\"): %v\n", token.IsExported("_foo"))
|
||||
|
||||
fmt.Printf("IsIdentifier(\"foo\"): %v\n", token.IsIdentifier("foo"))
|
||||
fmt.Printf("IsIdentifier(\"foo123\"): %v\n", token.IsIdentifier("foo123"))
|
||||
fmt.Printf("IsIdentifier(\"123foo\"): %v\n", token.IsIdentifier("123foo"))
|
||||
fmt.Printf("IsIdentifier(\"foo-bar\"): %v\n", token.IsIdentifier("foo-bar"))
|
||||
|
||||
fmt.Printf("IsKeyword(\"func\"): %v\n", token.IsKeyword("func"))
|
||||
fmt.Printf("IsKeyword(\"if\"): %v\n", token.IsKeyword("if"))
|
||||
fmt.Printf("IsKeyword(\"foo\"): %v\n", token.IsKeyword("foo"))
|
||||
|
||||
lookupFunc := token.Lookup("func")
|
||||
fmt.Printf("Lookup(\"func\"): %s\n", lookupFunc)
|
||||
|
||||
lookupIdent := token.Lookup("myVar")
|
||||
fmt.Printf("Lookup(\"myVar\"): %s\n", lookupIdent)
|
||||
|
||||
lookupFor := token.Lookup("for")
|
||||
fmt.Printf("Lookup(\"for\"): %s\n", lookupFor)
|
||||
|
||||
fmt.Println("SUCCESS: Utility functions work correctly\n")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user