pandalee99 commented on code in PR #2553:
URL: https://github.com/apache/fory/pull/2553#discussion_r2315864275


##########
go/fory/codegen_tests/validation_test.go:
##########
@@ -0,0 +1,83 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package codegen_tests
+
+import (
+       "fmt"
+       "testing"
+
+       "github.com/apache/fory/go/fory"
+)
+
+//go:generate go run ../codegen/main.go -pkg . -type "ValidationDemo"
+
+func TestValidationDemo(t *testing.T) {
+       fmt.Println("=== 代码生成验证演示 ===")
+
+       // 1. 创建实例
+       original := &ValidationDemo{
+               A: 12345,         // int32
+               B: "Hello Fory!", // string
+               C: 98765,         // int64
+       }
+
+       fmt.Printf("1. 原始数据:\n")
+       fmt.Printf("   A (int32):  %d\n", original.A)
+       fmt.Printf("   B (string): %s\n", original.B)
+       fmt.Printf("   C (int64):  %d\n", original.C)
+
+       // 2. 序列化 (生成的代码)
+       f := fory.NewFory(true)
+       data, err := f.Marshal(original)
+       if err != nil {
+               t.Fatalf("序列化失败: %v", err)
+       }
+
+       fmt.Printf("\n2. 序列化结果:\n")
+       fmt.Printf("   数据长度: %d 字节\n", len(data))
+       fmt.Printf("   二进制数据: %x\n", data)
+
+       // 3. 反序列化 (生成的代码)
+       var result *ValidationDemo
+       err = f.Unmarshal(data, &result)
+       if err != nil {
+               t.Fatalf("反序列化失败: %v", err)
+       }
+
+       fmt.Printf("\n3. 反序列化结果:\n")
+       fmt.Printf("   A (int32):  %d\n", result.A)
+       fmt.Printf("   B (string): %s\n", result.B)
+       fmt.Printf("   C (int64):  %d\n", result.C)
+
+       // 4. 验证
+       fmt.Printf("\n4. 验证结果:\n")
+       aMatch := result.A == original.A
+       bMatch := result.B == original.B
+       cMatch := result.C == original.C
+
+       fmt.Printf("   A 匹配: %t (%d == %d)\n", aMatch, result.A, original.A)
+       fmt.Printf("   B 匹配: %t (%s == %s)\n", bMatch, result.B, original.B)
+       fmt.Printf("   C 匹配: %t (%d == %d)\n", cMatch, result.C, original.C)
+
+       if aMatch && bMatch && cMatch {

Review Comment:
   This testing method is unreasonable. Please refer to other testing documents



##########
go/fory/codegen/main.go:
##########
@@ -0,0 +1,806 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package main

Review Comment:
   I think the name of this file needs to be modified



##########
go/fory/codegen_tests/structs.go:
##########
@@ -0,0 +1,25 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package codegen_tests
+
+// 验证用的基本结构体 (只包含基本类型,因为PR1只支持基本类型)

Review Comment:
   It is more appropriate to use English annotations



##########
go/fory/go.mod:
##########
@@ -17,10 +17,31 @@
 
 module github.com/apache/fory/go/fory
 
-go 1.13
+go 1.23.0
+
+toolchain go1.24.6
 
 require (
-       github.com/davecgh/go-spew v1.1.1 // indirect
        github.com/spaolacci/murmur3 v1.1.0
        github.com/stretchr/testify v1.7.0
 )
+
+require (
+       github.com/davecgh/go-spew v1.1.1 // indirect
+       github.com/google/go-cmp v0.6.0 // indirect
+       github.com/pmezard/go-difflib v1.0.0 // indirect
+       github.com/stretchr/objx v0.1.0 // indirect
+       github.com/yuin/goldmark v1.4.13 // indirect
+       golang.org/x/crypto v0.41.0 // indirect
+       golang.org/x/mod v0.27.0 // indirect

Review Comment:
   This import method seems not elegant enough



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to