Derive encoding for tuples

This commit is contained in:
Ayaz Hafiz 2023-03-22 11:37:47 -05:00
parent e5fcb05a2d
commit 0b4a45c70d
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
2 changed files with 223 additions and 2 deletions

View file

@ -273,6 +273,29 @@ fn two_field_record() {
})
}
#[test]
fn two_field_tuple() {
derive_test(ToEncoder, v!((v!(U8), v!(STR),)), |golden| {
assert_snapshot!(golden, @r###"
# derived for ( U8, Str )*
# ( val, val1 )* -[[toEncoder_(arity:2)(0)]]-> Encoder fmt | fmt has EncoderFormatting, val has Encoding, val1 has Encoding
# ( val, val1 )a -[[toEncoder_(arity:2)(0)]]-> (List U8, fmt -[[custom(2) ( val, val1 )a]]-> List U8) | fmt has EncoderFormatting, val has Encoding, val1 has Encoding
# Specialization lambda sets:
# @<1>: [[toEncoder_(arity:2)(0)]]
# @<2>: [[custom(2) ( val, val1 )*]] | val has Encoding, val1 has Encoding
#Derived.toEncoder_(arity:2) =
\#Derived.tup ->
custom
\#Derived.bytes, #Derived.fmt ->
appendWith
#Derived.bytes
(tuple [toEncoder #Derived.tup.0, toEncoder #Derived.tup.1])
#Derived.fmt
"###
)
})
}
#[test]
#[ignore = "NOTE: this would never actually happen, because [] is uninhabited, and hence toEncoder can never be called with a value of []!
Rightfully it induces broken assertions in other parts of the compiler, so we ignore it."]