mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 14:54:47 +00:00
Support newtypes and unit tag union hash deriving
This commit is contained in:
parent
251b3865d9
commit
41c9985c53
2 changed files with 42 additions and 7 deletions
|
@ -201,6 +201,47 @@ fn two_field_record() {
|
|||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tag_one_label_no_payloads() {
|
||||
derive_test(Hash, v!([A]), |golden| {
|
||||
assert_snapshot!(golden, @r###"
|
||||
# derived for [A]
|
||||
# a, [A] -[[hash_[A 0](0)]]-> a | a has Hasher
|
||||
# a, [A] -[[hash_[A 0](0)]]-> a | a has Hasher
|
||||
# Specialization lambda sets:
|
||||
# @<1>: [[hash_[A 0](0)]]
|
||||
#Derived.hash_[A 0] =
|
||||
\#Derived.hasher, #Derived.union ->
|
||||
#Derived.discrHasher =
|
||||
Hash.hash #Derived.hasher (@tag_discriminant #Derived.union)
|
||||
when #Derived.union is
|
||||
A -> #Derived.discrHasher
|
||||
"###
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tag_one_label_newtype() {
|
||||
derive_test(Hash, v!([A v!(U8) v!(STR)]), |golden| {
|
||||
assert_snapshot!(golden, @r###"
|
||||
# derived for [A U8 Str]
|
||||
# a, [A a1 a2] -[[hash_[A 2](0)]]-> a | a has Hasher, a1 has Hash, a2 has Hash
|
||||
# a, [A a1 a2] -[[hash_[A 2](0)]]-> a | a has Hasher, a1 has Hash, a2 has Hash
|
||||
# Specialization lambda sets:
|
||||
# @<1>: [[hash_[A 2](0)]]
|
||||
#Derived.hash_[A 2] =
|
||||
\#Derived.hasher, #Derived.union ->
|
||||
#Derived.discrHasher =
|
||||
Hash.hash #Derived.hasher (@tag_discriminant #Derived.union)
|
||||
when #Derived.union is
|
||||
A #Derived.4 #Derived.5 ->
|
||||
Hash.hash (Hash.hash #Derived.discrHasher #Derived.4) #Derived.5
|
||||
"###
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tag_two_labels() {
|
||||
derive_test(Hash, v!([A v!(U8) v!(STR) v!(U16), B v!(STR)]), |golden| {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue