Update derive tests

This commit is contained in:
Ayaz Hafiz 2022-12-12 15:06:32 -06:00
parent 6de816a9fc
commit 1e120653ff
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
3 changed files with 82 additions and 104 deletions

View file

@ -103,9 +103,9 @@ fn list() {
# Specialization lambda sets:
# @<1>: [[custom(3)]]
#Derived.decoder_list =
Decode.custom
custom
\#Derived.bytes, #Derived.fmt ->
Decode.decodeWith #Derived.bytes (Decode.list Decode.decoder) #Derived.fmt
decodeWith #Derived.bytes (list decoder) #Derived.fmt
"###
)
})
@ -121,21 +121,18 @@ fn record_2_fields() {
# Specialization lambda sets:
# @<1>: [[custom(22)]]
#Derived.decoder_{first,second} =
Decode.custom
custom
\#Derived.bytes3, #Derived.fmt3 ->
Decode.decodeWith
decodeWith
#Derived.bytes3
(Decode.record
(record
{ second: Err NoField, first: Err NoField }
\#Derived.stateRecord2, #Derived.field ->
when #Derived.field is
"first" ->
Keep (Decode.custom
Keep (custom
\#Derived.bytes, #Derived.fmt ->
when Decode.decodeWith
#Derived.bytes
Decode.decoder
#Derived.fmt is
when decodeWith #Derived.bytes decoder #Derived.fmt is
#Derived.rec ->
{
result: when #Derived.rec.result is
@ -145,12 +142,9 @@ fn record_2_fields() {
rest: #Derived.rec.rest
})
"second" ->
Keep (Decode.custom
Keep (custom
\#Derived.bytes2, #Derived.fmt2 ->
when Decode.decodeWith
#Derived.bytes2
Decode.decoder
#Derived.fmt2 is
when decodeWith #Derived.bytes2 decoder #Derived.fmt2 is
#Derived.rec2 ->
{
result: when #Derived.rec2.result is

View file

@ -187,9 +187,9 @@ fn empty_record() {
# @<2>: [[custom(2) {}]]
#Derived.toEncoder_{} =
\#Derived.rcd ->
Encode.custom
custom
\#Derived.bytes, #Derived.fmt ->
Encode.appendWith #Derived.bytes (Encode.record []) #Derived.fmt
appendWith #Derived.bytes (record []) #Derived.fmt
"###
)
})
@ -207,9 +207,9 @@ fn zero_field_record() {
# @<2>: [[custom(2) {}]]
#Derived.toEncoder_{} =
\#Derived.rcd ->
Encode.custom
custom
\#Derived.bytes, #Derived.fmt ->
Encode.appendWith #Derived.bytes (Encode.record []) #Derived.fmt
appendWith #Derived.bytes (record []) #Derived.fmt
"###
)
})
@ -227,11 +227,11 @@ fn one_field_record() {
# @<2>: [[custom(2) { a : val }]] | val has Encoding
#Derived.toEncoder_{a} =
\#Derived.rcd ->
Encode.custom
custom
\#Derived.bytes, #Derived.fmt ->
Encode.appendWith
appendWith
#Derived.bytes
(Encode.record [{ value: Encode.toEncoder #Derived.rcd.a, key: "a" }])
(record [{ value: toEncoder #Derived.rcd.a, key: "a" }])
#Derived.fmt
"###
)
@ -250,14 +250,14 @@ fn two_field_record() {
# @<2>: [[custom(2) { a : val, b : val1 }]] | val has Encoding, val1 has Encoding
#Derived.toEncoder_{a,b} =
\#Derived.rcd ->
Encode.custom
custom
\#Derived.bytes, #Derived.fmt ->
Encode.appendWith
appendWith
#Derived.bytes
(Encode.record
(record
[
{ value: Encode.toEncoder #Derived.rcd.a, key: "a" },
{ value: Encode.toEncoder #Derived.rcd.b, key: "b" },
{ value: toEncoder #Derived.rcd.a, key: "a" },
{ value: toEncoder #Derived.rcd.b, key: "b" },
])
#Derived.fmt
"###
@ -290,12 +290,12 @@ fn tag_one_label_zero_args() {
# @<2>: [[custom(2) [A]]]
#Derived.toEncoder_[A 0] =
\#Derived.tag ->
Encode.custom
custom
\#Derived.bytes, #Derived.fmt ->
Encode.appendWith
appendWith
#Derived.bytes
(when #Derived.tag is
A -> Encode.tag "A" [])
A -> tag "A" [])
#Derived.fmt
"###
)
@ -314,18 +314,13 @@ fn tag_one_label_two_args() {
# @<2>: [[custom(4) [A val val1]]] | val has Encoding, val1 has Encoding
#Derived.toEncoder_[A 2] =
\#Derived.tag ->
Encode.custom
custom
\#Derived.bytes, #Derived.fmt ->
Encode.appendWith
appendWith
#Derived.bytes
(when #Derived.tag is
A #Derived.2 #Derived.3 ->
Encode.tag
"A"
[
Encode.toEncoder #Derived.2,
Encode.toEncoder #Derived.3,
])
tag "A" [toEncoder #Derived.2, toEncoder #Derived.3])
#Derived.fmt
"###
)
@ -339,30 +334,30 @@ fn tag_two_labels() {
v!([A v!(U8) v!(STR) v!(U16), B v!(STR)]),
|golden| {
assert_snapshot!(golden, @r###"
# derived for [A U8 Str U16, B Str]
# [A val val1 val1, B val1] -[[toEncoder_[A 3,B 1](0)]]-> Encoder fmt | fmt has EncoderFormatting, val has Encoding, val1 has Encoding
# [A val val1 val1, B val1] -[[toEncoder_[A 3,B 1](0)]]-> (List U8, fmt -[[custom(6) [A val val1 val1, B val1]]]-> List U8) | fmt has EncoderFormatting, val has Encoding, val1 has Encoding
# Specialization lambda sets:
# @<1>: [[toEncoder_[A 3,B 1](0)]]
# @<2>: [[custom(6) [A val val1 val1, B val1]]] | val has Encoding, val1 has Encoding
#Derived.toEncoder_[A 3,B 1] =
\#Derived.tag ->
Encode.custom
\#Derived.bytes, #Derived.fmt ->
Encode.appendWith
#Derived.bytes
(when #Derived.tag is
A #Derived.2 #Derived.3 #Derived.4 ->
Encode.tag
"A"
[
Encode.toEncoder #Derived.2,
Encode.toEncoder #Derived.3,
Encode.toEncoder #Derived.4,
]
B #Derived.5 -> Encode.tag "B" [Encode.toEncoder #Derived.5])
#Derived.fmt
"###
# derived for [A U8 Str U16, B Str]
# [A val val1 val1, B val1] -[[toEncoder_[A 3,B 1](0)]]-> Encoder fmt | fmt has EncoderFormatting, val has Encoding, val1 has Encoding
# [A val val1 val1, B val1] -[[toEncoder_[A 3,B 1](0)]]-> (List U8, fmt -[[custom(6) [A val val1 val1, B val1]]]-> List U8) | fmt has EncoderFormatting, val has Encoding, val1 has Encoding
# Specialization lambda sets:
# @<1>: [[toEncoder_[A 3,B 1](0)]]
# @<2>: [[custom(6) [A val val1 val1, B val1]]] | val has Encoding, val1 has Encoding
#Derived.toEncoder_[A 3,B 1] =
\#Derived.tag ->
custom
\#Derived.bytes, #Derived.fmt ->
appendWith
#Derived.bytes
(when #Derived.tag is
A #Derived.2 #Derived.3 #Derived.4 ->
tag
"A"
[
toEncoder #Derived.2,
toEncoder #Derived.3,
toEncoder #Derived.4,
]
B #Derived.5 -> tag "B" [toEncoder #Derived.5])
#Derived.fmt
"###
)
},
)
@ -375,29 +370,24 @@ fn recursive_tag_union() {
v!([Nil, Cons v!(U8) v!(^lst) ] as lst),
|golden| {
assert_snapshot!(golden, @r###"
# derived for [Cons U8 $rec, Nil] as $rec
# [Cons val val1, Nil] -[[toEncoder_[Cons 2,Nil 0](0)]]-> Encoder fmt | fmt has EncoderFormatting, val has Encoding, val1 has Encoding
# [Cons val val1, Nil] -[[toEncoder_[Cons 2,Nil 0](0)]]-> (List U8, fmt -[[custom(4) [Cons val val1, Nil]]]-> List U8) | fmt has EncoderFormatting, val has Encoding, val1 has Encoding
# Specialization lambda sets:
# @<1>: [[toEncoder_[Cons 2,Nil 0](0)]]
# @<2>: [[custom(4) [Cons val val1, Nil]]] | val has Encoding, val1 has Encoding
#Derived.toEncoder_[Cons 2,Nil 0] =
\#Derived.tag ->
Encode.custom
\#Derived.bytes, #Derived.fmt ->
Encode.appendWith
#Derived.bytes
(when #Derived.tag is
Cons #Derived.2 #Derived.3 ->
Encode.tag
"Cons"
[
Encode.toEncoder #Derived.2,
Encode.toEncoder #Derived.3,
]
Nil -> Encode.tag "Nil" [])
#Derived.fmt
"###
# derived for [Cons U8 $rec, Nil] as $rec
# [Cons val val1, Nil] -[[toEncoder_[Cons 2,Nil 0](0)]]-> Encoder fmt | fmt has EncoderFormatting, val has Encoding, val1 has Encoding
# [Cons val val1, Nil] -[[toEncoder_[Cons 2,Nil 0](0)]]-> (List U8, fmt -[[custom(4) [Cons val val1, Nil]]]-> List U8) | fmt has EncoderFormatting, val has Encoding, val1 has Encoding
# Specialization lambda sets:
# @<1>: [[toEncoder_[Cons 2,Nil 0](0)]]
# @<2>: [[custom(4) [Cons val val1, Nil]]] | val has Encoding, val1 has Encoding
#Derived.toEncoder_[Cons 2,Nil 0] =
\#Derived.tag ->
custom
\#Derived.bytes, #Derived.fmt ->
appendWith
#Derived.bytes
(when #Derived.tag is
Cons #Derived.2 #Derived.3 ->
tag "Cons" [toEncoder #Derived.2, toEncoder #Derived.3]
Nil -> tag "Nil" [])
#Derived.fmt
"###
)
},
)
@ -415,13 +405,11 @@ fn list() {
# @<2>: [[custom(4) (List val)]] | val has Encoding
#Derived.toEncoder_list =
\#Derived.lst ->
Encode.custom
custom
\#Derived.bytes, #Derived.fmt ->
Encode.appendWith
appendWith
#Derived.bytes
(Encode.list
#Derived.lst
\#Derived.elem -> Encode.toEncoder #Derived.elem)
(list #Derived.lst \#Derived.elem -> toEncoder #Derived.elem)
#Derived.fmt
"###
)

View file

@ -178,7 +178,7 @@ fn one_field_record() {
# Specialization lambda sets:
# @<1>: [[hash_{a}(0)]]
#Derived.hash_{a} =
\#Derived.hasher, #Derived.rcd -> Hash.hash #Derived.hasher #Derived.rcd.a
\#Derived.hasher, #Derived.rcd -> hash #Derived.hasher #Derived.rcd.a
"###
)
})
@ -195,7 +195,7 @@ fn two_field_record() {
# @<1>: [[hash_{a,b}(0)]]
#Derived.hash_{a,b} =
\#Derived.hasher, #Derived.rcd ->
Hash.hash (Hash.hash #Derived.hasher #Derived.rcd.a) #Derived.rcd.b
hash (hash #Derived.hasher #Derived.rcd.a) #Derived.rcd.b
"###
)
})
@ -227,7 +227,7 @@ fn tag_one_label_newtype() {
# @<1>: [[hash_[A 2](0)]]
#Derived.hash_[A 2] =
\#Derived.hasher, A #Derived.2 #Derived.3 ->
Hash.hash (Hash.hash #Derived.hasher #Derived.2) #Derived.3
hash (hash #Derived.hasher #Derived.2) #Derived.3
"###
)
})
@ -246,12 +246,10 @@ fn tag_two_labels() {
\#Derived.hasher, #Derived.union ->
when #Derived.union is
A #Derived.3 #Derived.4 #Derived.5 ->
Hash.hash
(Hash.hash
(Hash.hash (Hash.addU8 #Derived.hasher 0) #Derived.3)
#Derived.4)
hash
(hash (hash (addU8 #Derived.hasher 0) #Derived.3) #Derived.4)
#Derived.5
B #Derived.6 -> Hash.hash (Hash.addU8 #Derived.hasher 1) #Derived.6
B #Derived.6 -> hash (addU8 #Derived.hasher 1) #Derived.6
"###
)
})
@ -269,8 +267,8 @@ fn tag_two_labels_no_payloads() {
#Derived.hash_[A 0,B 0] =
\#Derived.hasher, #Derived.union ->
when #Derived.union is
A -> Hash.addU8 #Derived.hasher 0
B -> Hash.addU8 #Derived.hasher 1
A -> addU8 #Derived.hasher 0
B -> addU8 #Derived.hasher 1
"###
)
})
@ -289,10 +287,8 @@ fn recursive_tag_union() {
\#Derived.hasher, #Derived.union ->
when #Derived.union is
Cons #Derived.3 #Derived.4 ->
Hash.hash
(Hash.hash (Hash.addU8 #Derived.hasher 0) #Derived.3)
#Derived.4
Nil -> Hash.addU8 #Derived.hasher 1
hash (hash (addU8 #Derived.hasher 0) #Derived.3) #Derived.4
Nil -> addU8 #Derived.hasher 1
"###
)
})