aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/serialization.tm60
1 files changed, 35 insertions, 25 deletions
diff --git a/test/serialization.tm b/test/serialization.tm
index b97b122f..18858d0e 100644
--- a/test/serialization.tm
+++ b/test/serialization.tm
@@ -6,72 +6,82 @@ enum MyEnum(Zero, One(x:Int), Two(x:Num, y:Text))
func main()
do
>> obj := Int64(123)
- >> bytes := obj.serialized()
- assert deserialize(bytes -> Int64) == obj
+ >> bytes : [Byte] = obj
+ >> roundtrip : Int64 = bytes
+ assert roundtrip == obj
do
>> obj := 5
- >> bytes := obj.serialized()
- assert deserialize(bytes -> Int) == obj
+ >> bytes : [Byte] = obj
+ >> roundtrip : Int = bytes
+ assert roundtrip == obj
do
>> obj := 9999999999999999999999999999999999999999999999999999
- >> bytes := obj.serialized()
- assert deserialize(bytes -> Int) == obj
+ >> bytes : [Byte] = obj
+ >> roundtrip : Int = bytes
+ assert roundtrip == obj
do
>> obj := "Héllo"
- >> bytes := obj.serialized()
- assert deserialize(bytes -> Text) == obj
+ >> bytes : [Byte] = obj
+ >> roundtrip : Text = bytes
+ assert roundtrip == obj
do
>> obj := [Int64(10), Int64(20), Int64(30)].reversed()
- >> bytes := obj.serialized()
- assert deserialize(bytes -> [Int64]) == obj
+ >> bytes : [Byte] = obj
+ >> roundtrip : [Int64] = bytes
+ assert roundtrip == obj
do
>> obj := yes
- >> bytes := obj.serialized()
- assert deserialize(bytes -> Bool) == obj
+ >> bytes : [Byte] = obj
+ >> roundtrip : Bool = bytes
+ assert roundtrip == obj
do
>> obj := @[10, 20]
- >> bytes := obj.serialized()
- >> roundtrip := deserialize(bytes -> @[Int])
+ >> bytes : [Byte] = obj
+ >> roundtrip : @[Int] = bytes
assert roundtrip != obj
assert roundtrip[] == obj[]
do
>> obj := {"A":10, "B":20; fallback={"C":30}}
- >> bytes := obj.serialized()
- >> roundtrip := deserialize(bytes -> {Text:Int})
+ >> bytes : [Byte] = obj
+ >> roundtrip : {Text:Int} = bytes
assert roundtrip == obj
assert roundtrip.fallback == obj.fallback
do
>> obj := @Foo("root")
>> obj.next = @Foo("abcdef", next=obj)
- >> bytes := obj.serialized()
- >> roundtrip := deserialize(bytes -> @Foo)
+ >> bytes : [Byte] = obj
+ >> roundtrip : @Foo = bytes
assert "$roundtrip" == "$obj"
do
>> obj := MyEnum.Two(123, "OKAY")
- >> bytes := obj.serialized()
+ >> bytes : [Byte] = obj
+ >> roundtrip : MyEnum = bytes
assert deserialize(bytes -> MyEnum) == obj
do
>> obj : Text? = "Hello"
- >> bytes := obj.serialized()
- assert deserialize(bytes -> Text?) == obj
+ >> bytes : [Byte] = obj
+ >> roundtrip : Text? = bytes
+ assert roundtrip == obj
do
>> obj : Num? = none
- >> bytes := obj.serialized()
- assert deserialize(bytes -> Num?) == obj
+ >> bytes : [Byte] = obj
+ >> roundtrip : Num? = bytes
+ assert roundtrip == obj
do
cases := [0, -1, 1, 10, 100000, 999999999999999999999999999]
for i in cases
- >> bytes := i.serialized()
- assert deserialize(bytes -> Int) == i
+ >> bytes : [Byte] = i
+ >> roundtrip : Int = bytes
+ assert roundtrip == i