style(demo): align gotypes and gotoken demos with standard demo pattern

- Removed header/footer print statements from main()
- Added '\n' prefix to section headers (except first) for consistent spacing
- Follows the pattern established in maphash and other demo files

This makes the output cleaner and consistent with other demo files in the project.

Generated with [codeagent](https://github.com/qbox/codeagent)
Co-authored-by: luoliwoshang <51194195+luoliwoshang@users.noreply.github.com>
This commit is contained in:
xgopilot
2025-10-28 04:02:36 +00:00
parent e46d22976a
commit 0256ce2232
2 changed files with 19 additions and 27 deletions

View File

@@ -6,8 +6,6 @@ import (
) )
func main() { func main() {
fmt.Println("=== Comprehensive go/token Package Demo ===\n")
testPos() testPos()
testToken() testToken()
testFileSet() testFileSet()
@@ -15,8 +13,6 @@ func main() {
testPosition() testPosition()
testTokenPrecedence() testTokenPrecedence()
testTokenKeywords() testTokenKeywords()
fmt.Println("\n=== All go/token tests completed successfully! ===")
} }
func testPos() { func testPos() {
@@ -35,7 +31,7 @@ func testPos() {
} }
func testToken() { func testToken() {
fmt.Println("=== Test Token Types ===") fmt.Println("\n=== Test Token Types ===")
tokens := []token.Token{ tokens := []token.Token{
token.ILLEGAL, token.ILLEGAL,
@@ -104,7 +100,7 @@ func testToken() {
} }
func testTokenKeywords() { func testTokenKeywords() {
fmt.Println("=== Test Keywords ===") fmt.Println("\n=== Test Keywords ===")
keywords := []token.Token{ keywords := []token.Token{
token.BREAK, token.BREAK,
@@ -142,7 +138,7 @@ func testTokenKeywords() {
} }
func testTokenPrecedence() { func testTokenPrecedence() {
fmt.Println("=== Test Token Precedence ===") fmt.Println("\n=== Test Token Precedence ===")
operators := []token.Token{ operators := []token.Token{
token.ADD, token.ADD,
@@ -165,7 +161,7 @@ func testTokenPrecedence() {
} }
func testFileSet() { func testFileSet() {
fmt.Println("=== Test FileSet ===") fmt.Println("\n=== Test FileSet ===")
fset := token.NewFileSet() fset := token.NewFileSet()
@@ -188,7 +184,7 @@ func testFileSet() {
} }
func testFile() { func testFile() {
fmt.Println("=== Test File ===") fmt.Println("\n=== Test File ===")
fset := token.NewFileSet() fset := token.NewFileSet()
file := fset.AddFile("test.go", -1, 1000) file := fset.AddFile("test.go", -1, 1000)
@@ -221,7 +217,7 @@ func testFile() {
} }
func testPosition() { func testPosition() {
fmt.Println("=== Test Position ===") fmt.Println("\n=== Test Position ===" )
pos := token.Position{ pos := token.Position{
Filename: "test.go", Filename: "test.go",

View File

@@ -7,8 +7,6 @@ import (
) )
func main() { func main() {
fmt.Println("=== Comprehensive go/types Package Demo ===\n")
testBasicTypes() testBasicTypes()
testObjects() testObjects()
testScope() testScope()
@@ -23,8 +21,6 @@ func main() {
testPointer() testPointer()
testMap() testMap()
testChan() testChan()
fmt.Println("\n=== All go/types tests completed successfully! ===")
} }
func testBasicTypes() { func testBasicTypes() {
@@ -46,7 +42,7 @@ func testBasicTypes() {
} }
func testObjects() { func testObjects() {
fmt.Println("=== Test Objects (Var, Const, Func, TypeName) ===") fmt.Println("\n=== Test Objects (Var, Const, Func, TypeName) ===")
varObj := types.NewVar(token.NoPos, nil, "x", types.Typ[types.Int]) varObj := types.NewVar(token.NoPos, nil, "x", types.Typ[types.Int])
fmt.Printf("Var: Name=%s, Type=%v\n", varObj.Name(), varObj.Type()) fmt.Printf("Var: Name=%s, Type=%v\n", varObj.Name(), varObj.Type())
@@ -69,7 +65,7 @@ func testObjects() {
} }
func testScope() { func testScope() {
fmt.Println("=== Test Scope ===") fmt.Println("\n=== Test Scope ===")
scope := types.NewScope(nil, 0, 0, "test") scope := types.NewScope(nil, 0, 0, "test")
obj := types.NewVar(0, nil, "x", types.Typ[types.Int]) obj := types.NewVar(0, nil, "x", types.Typ[types.Int])
@@ -95,7 +91,7 @@ func testScope() {
} }
func testPackage() { func testPackage() {
fmt.Println("=== Test Package ===") fmt.Println("\n=== Test Package ===")
pkg := types.NewPackage("example.com/test", "test") pkg := types.NewPackage("example.com/test", "test")
fmt.Printf("Package: Path=%s, Name=%s\n", pkg.Path(), pkg.Name()) fmt.Printf("Package: Path=%s, Name=%s\n", pkg.Path(), pkg.Name())
@@ -117,7 +113,7 @@ func testPackage() {
} }
func testNamed() { func testNamed() {
fmt.Println("=== Test Named Types ===") fmt.Println("\n=== Test Named Types ===")
pkg := types.NewPackage("example.com/test", "test") pkg := types.NewPackage("example.com/test", "test")
typeName := types.NewTypeName(token.NoPos, pkg, "MyInt", nil) typeName := types.NewTypeName(token.NoPos, pkg, "MyInt", nil)
@@ -133,7 +129,7 @@ func testNamed() {
} }
func testInterface() { func testInterface() {
fmt.Println("=== Test Interface ===") fmt.Println("\n=== Test Interface ===")
pkg := types.NewPackage("example.com/test", "test") pkg := types.NewPackage("example.com/test", "test")
@@ -153,7 +149,7 @@ func testInterface() {
} }
func testStruct() { func testStruct() {
fmt.Println("=== Test Struct ===") fmt.Println("\n=== Test Struct ===")
fields := []*types.Var{ fields := []*types.Var{
types.NewField(token.NoPos, nil, "X", types.Typ[types.Int], false), types.NewField(token.NoPos, nil, "X", types.Typ[types.Int], false),
@@ -170,7 +166,7 @@ func testStruct() {
} }
func testSignature() { func testSignature() {
fmt.Println("=== Test Signature ===") fmt.Println("\n=== Test Signature ===")
params := types.NewTuple( params := types.NewTuple(
types.NewVar(token.NoPos, nil, "x", types.Typ[types.Int]), types.NewVar(token.NoPos, nil, "x", types.Typ[types.Int]),
@@ -192,7 +188,7 @@ func testSignature() {
} }
func testTuple() { func testTuple() {
fmt.Println("=== Test Tuple ===") fmt.Println("\n=== Test Tuple ===")
tuple := types.NewTuple( tuple := types.NewTuple(
types.NewVar(token.NoPos, nil, "a", types.Typ[types.Int]), types.NewVar(token.NoPos, nil, "a", types.Typ[types.Int]),
@@ -208,7 +204,7 @@ func testTuple() {
} }
func testArray() { func testArray() {
fmt.Println("=== Test Array ===") fmt.Println("\n=== Test Array ===")
arrayType := types.NewArray(types.Typ[types.Int], 10) arrayType := types.NewArray(types.Typ[types.Int], 10)
fmt.Printf("Array type: %v, Elem: %v, Len: %d\n", arrayType, arrayType.Elem(), arrayType.Len()) fmt.Printf("Array type: %v, Elem: %v, Len: %d\n", arrayType, arrayType.Elem(), arrayType.Len())
@@ -217,7 +213,7 @@ func testArray() {
} }
func testSlice() { func testSlice() {
fmt.Println("=== Test Slice ===") fmt.Println("\n=== Test Slice ===")
sliceType := types.NewSlice(types.Typ[types.String]) sliceType := types.NewSlice(types.Typ[types.String])
fmt.Printf("Slice type: %v, Elem: %v\n", sliceType, sliceType.Elem()) fmt.Printf("Slice type: %v, Elem: %v\n", sliceType, sliceType.Elem())
@@ -226,7 +222,7 @@ func testSlice() {
} }
func testPointer() { func testPointer() {
fmt.Println("=== Test Pointer ===") fmt.Println("\n=== Test Pointer ===")
ptrType := types.NewPointer(types.Typ[types.Int]) ptrType := types.NewPointer(types.Typ[types.Int])
fmt.Printf("Pointer type: %v, Elem: %v\n", ptrType, ptrType.Elem()) fmt.Printf("Pointer type: %v, Elem: %v\n", ptrType, ptrType.Elem())
@@ -235,7 +231,7 @@ func testPointer() {
} }
func testMap() { func testMap() {
fmt.Println("=== Test Map ===") fmt.Println("\n=== Test Map ===")
mapType := types.NewMap(types.Typ[types.String], types.Typ[types.Int]) mapType := types.NewMap(types.Typ[types.String], types.Typ[types.Int])
fmt.Printf("Map type: %v, Key: %v, Elem: %v\n", mapType, mapType.Key(), mapType.Elem()) fmt.Printf("Map type: %v, Key: %v, Elem: %v\n", mapType, mapType.Key(), mapType.Elem())
@@ -244,7 +240,7 @@ func testMap() {
} }
func testChan() { func testChan() {
fmt.Println("=== Test Chan ===") fmt.Println("\n=== Test Chan ===" )
chanType := types.NewChan(types.SendRecv, types.Typ[types.Int]) chanType := types.NewChan(types.SendRecv, types.Typ[types.Int])
fmt.Printf("Chan type: %v, Dir: %v, Elem: %v\n", chanType, chanType.Dir(), chanType.Elem()) fmt.Printf("Chan type: %v, Dir: %v, Elem: %v\n", chanType, chanType.Dir(), chanType.Elem())