2024-11-29 15:09:12 -08:00
|
|
|
|
2024-12-07 13:04:25 -08:00
|
|
|
struct Foo(name:Text, next=none:@Foo)
|
2024-11-29 15:09:12 -08:00
|
|
|
|
|
|
|
enum MyEnum(Zero, One(x:Int), Two(x:Num, y:Text))
|
|
|
|
|
|
|
|
func main():
|
|
|
|
do:
|
|
|
|
>> obj := Int64(123)
|
2024-11-29 16:39:17 -08:00
|
|
|
>> bytes := obj:serialized()
|
2024-11-29 16:57:50 -08:00
|
|
|
>> deserialize(bytes -> Int64) == obj
|
2024-11-29 15:09:12 -08:00
|
|
|
= yes
|
|
|
|
|
|
|
|
do:
|
|
|
|
>> obj := 5
|
2024-11-29 16:39:17 -08:00
|
|
|
>> bytes := obj:serialized()
|
2024-11-29 16:57:50 -08:00
|
|
|
>> deserialize(bytes -> Int) == obj
|
2024-11-29 15:09:12 -08:00
|
|
|
= yes
|
|
|
|
|
|
|
|
do:
|
|
|
|
>> obj := 9999999999999999999999999999999999999999999999999999
|
2024-11-29 16:39:17 -08:00
|
|
|
>> bytes := obj:serialized()
|
2024-11-29 16:57:50 -08:00
|
|
|
>> deserialize(bytes -> Int) == obj
|
2024-11-29 15:09:12 -08:00
|
|
|
= yes
|
|
|
|
|
|
|
|
do:
|
|
|
|
>> obj := "Héllo"
|
2024-11-29 16:39:17 -08:00
|
|
|
>> bytes := obj:serialized()
|
2024-11-29 16:57:50 -08:00
|
|
|
>> deserialize(bytes -> Text)
|
|
|
|
>> deserialize(bytes -> Text) == obj
|
2024-11-29 15:09:12 -08:00
|
|
|
= yes
|
|
|
|
|
|
|
|
do:
|
|
|
|
>> obj := [Int64(10), Int64(20), Int64(30)]:reversed()
|
2024-11-29 16:39:17 -08:00
|
|
|
>> bytes := obj:serialized()
|
2024-11-29 16:57:50 -08:00
|
|
|
>> deserialize(bytes -> [Int64]) == obj
|
2024-11-29 15:09:12 -08:00
|
|
|
= yes
|
|
|
|
|
|
|
|
do:
|
|
|
|
>> obj := yes
|
2024-11-29 16:39:17 -08:00
|
|
|
>> bytes := obj:serialized()
|
2024-11-29 16:57:50 -08:00
|
|
|
>> deserialize(bytes -> Bool) == obj
|
2024-11-29 15:09:12 -08:00
|
|
|
= yes
|
|
|
|
|
|
|
|
do:
|
|
|
|
>> obj := @[10, 20]
|
2024-11-29 16:39:17 -08:00
|
|
|
>> bytes := obj:serialized()
|
2024-11-29 16:57:50 -08:00
|
|
|
>> roundtrip := deserialize(bytes -> @[Int])
|
2024-11-29 15:09:12 -08:00
|
|
|
>> roundtrip == obj
|
|
|
|
= no
|
|
|
|
>> roundtrip[] == obj[]
|
|
|
|
= yes
|
|
|
|
|
|
|
|
do:
|
2025-01-12 13:49:58 -08:00
|
|
|
>> obj := {"A"=10, "B"=20; fallback={"C"=30}}
|
2024-11-29 16:39:17 -08:00
|
|
|
>> bytes := obj:serialized()
|
2025-04-02 13:14:20 -07:00
|
|
|
>> deserialize(bytes -> {Text=Int}) == obj
|
2024-11-29 15:09:12 -08:00
|
|
|
= yes
|
|
|
|
|
|
|
|
do:
|
|
|
|
>> obj := @Foo("root")
|
|
|
|
>> obj.next = @Foo("abcdef", next=obj)
|
2024-11-29 16:39:17 -08:00
|
|
|
>> bytes := obj:serialized()
|
2024-11-29 16:57:50 -08:00
|
|
|
>> deserialize(bytes -> @Foo)
|
2025-03-25 12:40:59 -07:00
|
|
|
# = @Foo(name="root", next=@Foo(name="abcdef", next=@~1))
|
2024-11-29 15:09:12 -08:00
|
|
|
|
|
|
|
do:
|
|
|
|
>> obj := MyEnum.Two(123, "OKAY")
|
2024-11-29 16:39:17 -08:00
|
|
|
>> bytes := obj:serialized()
|
2024-11-29 16:57:50 -08:00
|
|
|
>> deserialize(bytes -> MyEnum) == obj
|
2024-11-29 15:09:12 -08:00
|
|
|
= yes
|
|
|
|
|
|
|
|
do:
|
|
|
|
>> obj := "Hello"?
|
2024-11-29 16:39:17 -08:00
|
|
|
>> bytes := obj:serialized()
|
2024-11-29 16:57:50 -08:00
|
|
|
>> deserialize(bytes -> Text?) == obj
|
2024-11-29 15:09:12 -08:00
|
|
|
= yes
|
|
|
|
|
|
|
|
do:
|
|
|
|
>> obj := {10, 20, 30}
|
2024-11-29 16:39:17 -08:00
|
|
|
>> bytes := obj:serialized()
|
2024-11-29 16:57:50 -08:00
|
|
|
>> deserialize(bytes -> {Int}) == obj
|
2024-11-29 15:09:12 -08:00
|
|
|
= yes
|
|
|
|
|
|
|
|
do:
|
2024-12-07 13:04:25 -08:00
|
|
|
>> obj := none:Num
|
2024-11-29 16:39:17 -08:00
|
|
|
>> bytes := obj:serialized()
|
2024-11-29 16:57:50 -08:00
|
|
|
>> deserialize(bytes -> Num?) == obj
|
2024-11-29 15:09:12 -08:00
|
|
|
= yes
|
|
|
|
|
2024-11-29 16:34:31 -08:00
|
|
|
do:
|
|
|
|
cases := [0, -1, 1, 10, 100000, 999999999999999999999999999]
|
|
|
|
for i in cases:
|
2024-11-29 16:39:17 -08:00
|
|
|
>> bytes := i:serialized()
|
2024-11-29 16:57:50 -08:00
|
|
|
>> deserialize(bytes -> Int) == i
|
2024-11-29 16:34:31 -08:00
|
|
|
= yes
|