MCPcopy Create free account
hub / github.com/apache/fory / TestValidationDemo

Function TestValidationDemo

go/fory/tests/generator_test.go:30–63  ·  view source on GitHub ↗

go:generate fory -file structs.go

(t *testing.T)

Source from the content-addressed store, hash-verified

28//go:generate fory -file structs.go
29
30func TestValidationDemo(t *testing.T) {
31 // 1. Create test instance
32 original := &ValidationDemo{
33 A: 12345, // int32
34 B: "Hello Fory!", // string
35 C: 98765, // int64
36 D: 3.14159, // float64
37 E: true, // bool
38 }
39
40 // Validate original data structure
41 assert.Equal(t, int32(12345), original.A, "Original A should be 12345")
42 assert.Equal(t, "Hello Fory!", original.B, "Original B should be 'Hello Fory!'")
43 assert.Equal(t, int64(98765), original.C, "Original C should be 98765")
44 assert.Equal(t, 3.14159, original.D, "Original D should be 3.14159")
45 assert.Equal(t, true, original.E, "Original E should be true")
46
47 // 2. SerializeWithCallback using generated code
48 f := fory.NewFory(fory.WithXlang(false), fory.WithCompatible(false), fory.WithRefTracking(true))
49 data, err := f.Marshal(original)
50 require.NoError(t, err, "Serialization should not fail")
51 require.NotEmpty(t, data, "Serialized data should not be empty")
52 assert.Greater(t, len(data), 0, "Serialized data should have positive length")
53
54 // 3. DeserializeWithCallbackBuffers using generated code
55 var result *ValidationDemo
56 err = f.Unmarshal(data, &result)
57 require.NoError(t, err, "Deserialization should not fail")
58 require.NotNil(t, result, "Deserialized result should not be nil")
59
60 // 4. Verify that serializer is properly registered and can be retrieved
61 validationSerializer := NewSerializerFor_ValidationDemo()
62 assert.NotNil(t, validationSerializer, "Serializer should not be nil")
63}
64
65func TestSliceDemo(t *testing.T) {
66 // 1. Create test instance with various slice types

Callers

nothing calls this directly

Calls 7

MarshalMethod · 0.95
UnmarshalMethod · 0.95
GreaterMethod · 0.80
int32Function · 0.50
int64Function · 0.50
EqualMethod · 0.45

Tested by

no test coverage detected