Add decoding record derive key tests

This commit is contained in:
Ayaz Hafiz 2022-08-15 10:59:42 -05:00
parent 07cac2b4ce
commit 68441479b8
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
4 changed files with 35 additions and 8 deletions

View file

@ -5,6 +5,7 @@
#![allow(non_snake_case)]
use crate::{
test_key_eq, test_key_neq,
util::{check_immediate, derive_test},
v,
};
@ -14,6 +15,34 @@ use roc_types::subs::Variable;
use roc_derive_key::DeriveBuiltin::Decoder;
test_key_eq! {
Decoder,
same_record:
v!({ a: v!(U8), }), v!({ a: v!(U8), })
same_record_fields_diff_types:
v!({ a: v!(U8), }), v!({ a: v!(STR), })
same_record_fields_any_order:
v!({ a: v!(U8), b: v!(U8), c: v!(U8), }),
v!({ c: v!(U8), a: v!(U8), b: v!(U8), })
explicit_empty_record_and_implicit_empty_record:
v!(EMPTY_RECORD), v!({})
list_list_diff_types:
v!(Symbol::LIST_LIST v!(STR)), v!(Symbol::LIST_LIST v!(U8))
str_str:
v!(Symbol::STR_STR), v!(Symbol::STR_STR)
}
test_key_neq! {
Decoder,
different_record_fields:
v!({ a: v!(U8), }), v!({ b: v!(U8), })
record_empty_vs_nonempty:
v!(EMPTY_RECORD), v!({ a: v!(U8), })
}
#[test]
fn immediates() {
check_immediate(Decoder, v!(U8), Symbol::DECODE_U8);

View file

@ -7,7 +7,7 @@
use insta::assert_snapshot;
use crate::{
test_hash_eq, test_hash_neq,
test_key_eq, test_key_neq,
util::{check_immediate, derive_test},
v,
};
@ -17,7 +17,7 @@ use roc_types::subs::Variable;
// {{{ hash tests
test_hash_eq! {
test_key_eq! {
ToEncoder,
same_record:
@ -70,7 +70,7 @@ test_hash_eq! {
v!(@Symbol::BOOL_BOOL => v!([ True, False ])), v!(Symbol::UNDERSCORE => v!([False, True]))
}
test_hash_neq! {
test_key_neq! {
ToEncoder,
different_record_fields:

View file

@ -178,7 +178,7 @@ where
}
#[macro_export]
macro_rules! test_hash_eq {
macro_rules! test_key_eq {
($builtin:expr, $($name:ident: $synth1:expr, $synth2:expr)*) => {$(
#[test]
fn $name() {
@ -188,7 +188,7 @@ macro_rules! test_hash_eq {
}
#[macro_export]
macro_rules! test_hash_neq {
macro_rules! test_key_neq {
($builtin:expr, $($name:ident: $synth1:expr, $synth2:expr)*) => {$(
#[test]
fn $name() {