Files
herolib/lib/data/encoderhero/encoder_ignorepropery_test.v
Mahmoud-Emad ca95464115 refactor: Improve struct decoding and skip logic
- Refine `decode_struct` to handle data parsing and error messages
- Enhance `should_skip_field_decode` to cover more skip attribute variations
- Update constants and tests related to struct names
- Adjust `decode_value` to better handle optional types and existing keys
- Modify `decode_struct` to skip optional fields during decoding
2025-10-12 16:35:10 +03:00

58 lines
937 B
V

module encoderhero
pub struct MyStruct {
id int
name string
other ?&Remark @[skip]
}
pub struct Remark {
id int
}
fn test_encode_skip() ! {
mut o := MyStruct{
id: 1
name: 'test'
other: &Remark{
id: 123
}
}
script := encode[MyStruct](o)!
assert script.trim_space() == '!!define.my_struct id:1 name:test'
assert !script.contains('other')
o2 := decode[MyStruct](script)!
assert o2.id == 1
assert o2.name == 'test'
}
fn test_encode_skip_multiple_attrs() ! {
struct SkipTest {
id int
name string
skip1 string @[skip]
skip2 int @[other; skip]
skip3 bool @[skipdecode]
}
obj := SkipTest{
id: 1
name: 'test'
skip1: 'should not appear'
skip2: 999
skip3: true
}
script := encode[SkipTest](obj)!
assert script.contains('id:1')
assert script.contains('name:test')
assert !script.contains('skip1')
assert !script.contains('skip2')
assert script.contains('skip3')
}