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

Function TestSetFieldSerializationCompatible

go/fory/struct_test.go:404–449  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

402}
403
404func TestSetFieldSerializationCompatible(t *testing.T) {
405 f := New(WithXlang(true), WithCompatible(true))
406 err := f.RegisterStruct(SetFieldsStruct{}, 1002)
407 require.NoError(t, err, "register struct error")
408
409 // Create test object with Set and Map fields
410 obj := SetFieldsStruct{
411 SetField: NewSet[string](),
412 NullableSet: NewSet[string](),
413 MapField: map[string]bool{"key1": true, "key2": true},
414 NullableMap: map[string]bool{"nk1": true},
415 }
416 obj.SetField.Add("x", "y")
417 obj.NullableSet.Add("m", "n")
418
419 // Serialize
420 data, err := f.Serialize(&obj)
421 require.NoError(t, err, "Serialize failed")
422 t.Logf("Serialized %d bytes", len(data))
423
424 // Deserialize
425 var result any
426 err = testDeserialize(t, f, data, &result)
427 require.NoError(t, err, "Deserialize failed")
428
429 resultObj := result.(*SetFieldsStruct)
430
431 // Verify SetField
432 require.Equal(t, 2, len(resultObj.SetField), "SetField length mismatch")
433 require.True(t, resultObj.SetField.Contains("x"), "SetField should contain 'x'")
434 require.True(t, resultObj.SetField.Contains("y"), "SetField should contain 'y'")
435
436 // Verify NullableSet
437 require.Equal(t, 2, len(resultObj.NullableSet), "NullableSet length mismatch")
438 require.True(t, resultObj.NullableSet.Contains("m"), "NullableSet should contain 'm'")
439 require.True(t, resultObj.NullableSet.Contains("n"), "NullableSet should contain 'n'")
440
441 // Verify MapField
442 require.Equal(t, 2, len(resultObj.MapField), "MapField length mismatch")
443 require.True(t, resultObj.MapField["key1"])
444 require.True(t, resultObj.MapField["key2"])
445
446 // Verify NullableMap
447 require.Equal(t, 1, len(resultObj.NullableMap), "NullableMap length mismatch")
448 require.True(t, resultObj.NullableMap["nk1"])
449}
450
451func TestSetFieldTypeId(t *testing.T) {
452 // Test that Set fields have the correct TypeId in fingerprint

Callers

nothing calls this directly

Calls 9

WithXlangFunction · 0.85
WithCompatibleFunction · 0.85
testDeserializeFunction · 0.85
NewFunction · 0.70
RegisterStructMethod · 0.45
AddMethod · 0.45
SerializeMethod · 0.45
EqualMethod · 0.45
ContainsMethod · 0.45

Tested by

no test coverage detected