Merge test_dev, test_wasm, and test_wasm_util into test_gen

This commit is contained in:
Brendan Hansknecht 2021-11-08 19:31:20 -08:00
parent cba0f07992
commit 360974398a
32 changed files with 2417 additions and 6571 deletions

View file

@ -1,196 +1,218 @@
#[cfg(test)]
mod gen_compare {
use crate::assert_evals_to;
// use crate::assert_wasm_evals_to as assert_evals_to;
use indoc::indoc;
#![cfg(not(feature = "gen-wasm"))]
#[test]
fn eq_i64() {
assert_evals_to!(
indoc!(
r#"
#[cfg(feature = "gen-llvm")]
use crate::helpers::llvm::assert_evals_to;
#[cfg(feature = "gen-dev")]
use crate::helpers::dev::assert_evals_to;
// #[cfg(feature = "gen-wasm")]
// use crate::helpers::wasm::assert_evals_to;
// use crate::assert_wasm_evals_to as assert_evals_to;
use indoc::indoc;
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
fn eq_i64() {
assert_evals_to!(
indoc!(
r#"
i : I64
i = 1
i == i
"#
),
true,
bool
);
}
),
true,
bool
);
}
#[test]
fn neq_i64() {
assert_evals_to!(
indoc!(
r#"
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn neq_i64() {
assert_evals_to!(
indoc!(
r#"
i : I64
i = 1
i != i
"#
),
false,
bool
);
}
),
false,
bool
);
}
#[test]
fn eq_u64() {
assert_evals_to!(
indoc!(
r#"
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
fn eq_u64() {
assert_evals_to!(
indoc!(
r#"
i : U64
i = 1
i == i
"#
),
true,
bool
);
}
),
true,
bool
);
}
#[test]
fn neq_u64() {
assert_evals_to!(
indoc!(
r#"
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn neq_u64() {
assert_evals_to!(
indoc!(
r#"
i : U64
i = 1
i != i
"#
),
false,
bool
);
}
),
false,
bool
);
}
#[test]
fn eq_f64() {
assert_evals_to!(
indoc!(
r#"
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn eq_f64() {
assert_evals_to!(
indoc!(
r#"
i : F64
i = 1
i == i
"#
),
true,
bool
);
}
),
true,
bool
);
}
#[test]
fn neq_f64() {
assert_evals_to!(
indoc!(
r#"
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn neq_f64() {
assert_evals_to!(
indoc!(
r#"
i : F64
i = 1
i != i
"#
),
false,
bool
);
}
),
false,
bool
);
}
#[test]
fn eq_bool_tag() {
assert_evals_to!(
indoc!(
r#"
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn eq_bool_tag() {
assert_evals_to!(
indoc!(
r#"
true : Bool
true = True
true == True
"#
),
true,
bool
);
}
),
true,
bool
);
}
#[test]
fn neq_bool_tag() {
assert_evals_to!(
indoc!(
r#"
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn neq_bool_tag() {
assert_evals_to!(
indoc!(
r#"
true : Bool
true = True
true == False
"#
),
false,
bool
);
}
),
false,
bool
);
}
#[test]
fn empty_record() {
assert_evals_to!("{} == {}", true, bool);
assert_evals_to!("{} != {}", false, bool);
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn empty_record() {
assert_evals_to!("{} == {}", true, bool);
assert_evals_to!("{} != {}", false, bool);
}
#[test]
fn unit() {
assert_evals_to!("Unit == Unit", true, bool);
assert_evals_to!("Unit != Unit", false, bool);
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn unit() {
assert_evals_to!("Unit == Unit", true, bool);
assert_evals_to!("Unit != Unit", false, bool);
}
#[test]
fn newtype() {
assert_evals_to!("Identity 42 == Identity 42", true, bool);
assert_evals_to!("Identity 42 != Identity 42", false, bool);
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn newtype() {
assert_evals_to!("Identity 42 == Identity 42", true, bool);
assert_evals_to!("Identity 42 != Identity 42", false, bool);
}
#[test]
fn small_str() {
assert_evals_to!("\"aaa\" == \"aaa\"", true, bool);
assert_evals_to!("\"aaa\" == \"bbb\"", false, bool);
assert_evals_to!("\"aaa\" != \"aaa\"", false, bool);
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn small_str() {
assert_evals_to!("\"aaa\" == \"aaa\"", true, bool);
assert_evals_to!("\"aaa\" == \"bbb\"", false, bool);
assert_evals_to!("\"aaa\" != \"aaa\"", false, bool);
}
#[test]
fn large_str() {
assert_evals_to!(
indoc!(
r#"
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn large_str() {
assert_evals_to!(
indoc!(
r#"
x = "Unicode can represent text values which span multiple languages"
y = "Unicode can represent text values which span multiple languages"
x == y
"#
),
true,
bool
);
),
true,
bool
);
assert_evals_to!(
indoc!(
r#"
assert_evals_to!(
indoc!(
r#"
x = "Unicode can represent text values which span multiple languages"
y = "Here are some valid Roc strings"
x != y
"#
),
true,
bool
);
}
),
true,
bool
);
}
#[test]
fn eq_result_tag_true() {
assert_evals_to!(
indoc!(
r#"
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn eq_result_tag_true() {
assert_evals_to!(
indoc!(
r#"
x : Result I64 I64
x = Ok 1
@ -199,17 +221,18 @@ mod gen_compare {
x == y
"#
),
true,
bool
);
}
),
true,
bool
);
}
#[test]
fn eq_result_tag_false() {
assert_evals_to!(
indoc!(
r#"
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn eq_result_tag_false() {
assert_evals_to!(
indoc!(
r#"
x : Result I64 I64
x = Ok 1
@ -218,17 +241,18 @@ mod gen_compare {
x == y
"#
),
false,
bool
);
}
),
false,
bool
);
}
#[test]
fn eq_expr() {
assert_evals_to!(
indoc!(
r#"
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn eq_expr() {
assert_evals_to!(
indoc!(
r#"
Expr : [ Add Expr Expr, Mul Expr Expr, Val I64, Var I64 ]
x : Expr
@ -239,17 +263,18 @@ mod gen_compare {
x == y
"#
),
true,
bool
);
}
),
true,
bool
);
}
#[test]
fn eq_linked_list() {
assert_evals_to!(
indoc!(
r#"
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn eq_linked_list() {
assert_evals_to!(
indoc!(
r#"
LinkedList a : [ Nil, Cons a (LinkedList a) ]
x : LinkedList I64
@ -260,14 +285,14 @@ mod gen_compare {
x == y
"#
),
true,
bool
);
),
true,
bool
);
assert_evals_to!(
indoc!(
r#"
assert_evals_to!(
indoc!(
r#"
LinkedList a : [ Nil, Cons a (LinkedList a) ]
x : LinkedList I64
@ -278,14 +303,14 @@ mod gen_compare {
x == y
"#
),
true,
bool
);
),
true,
bool
);
assert_evals_to!(
indoc!(
r#"
assert_evals_to!(
indoc!(
r#"
LinkedList a : [ Nil, Cons a (LinkedList a) ]
x : LinkedList I64
@ -296,17 +321,18 @@ mod gen_compare {
x == y
"#
),
true,
bool
);
}
),
true,
bool
);
}
#[test]
fn eq_linked_list_false() {
assert_evals_to!(
indoc!(
r#"
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn eq_linked_list_false() {
assert_evals_to!(
indoc!(
r#"
LinkedList a : [ Nil, Cons a (LinkedList a) ]
x : LinkedList I64
@ -317,17 +343,18 @@ mod gen_compare {
y == x
"#
),
false,
bool
);
}
),
false,
bool
);
}
#[test]
fn eq_nullable_expr() {
assert_evals_to!(
indoc!(
r#"
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn eq_nullable_expr() {
assert_evals_to!(
indoc!(
r#"
Expr : [ Add Expr Expr, Mul Expr Expr, Val I64, Empty ]
x : Expr
@ -338,17 +365,18 @@ mod gen_compare {
x != y
"#
),
true,
bool
);
}
),
true,
bool
);
}
#[test]
fn eq_rosetree() {
assert_evals_to!(
indoc!(
r#"
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn eq_rosetree() {
assert_evals_to!(
indoc!(
r#"
Rose a : [ Rose (List (Rose a)) ]
x : Rose I64
@ -359,14 +387,14 @@ mod gen_compare {
x == y
"#
),
true,
bool
);
),
true,
bool
);
assert_evals_to!(
indoc!(
r#"
assert_evals_to!(
indoc!(
r#"
Rose a : [ Rose (List (Rose a)) ]
x : Rose I64
@ -377,20 +405,21 @@ mod gen_compare {
x != y
"#
),
false,
bool
);
}
),
false,
bool
);
}
#[test]
#[ignore]
fn rosetree_with_tag() {
// currently stack overflows in type checking
#[test]
#[cfg(any(feature = "gen-llvm"))]
#[ignore]
fn rosetree_with_tag() {
// currently stack overflows in type checking
assert_evals_to!(
indoc!(
r#"
assert_evals_to!(
indoc!(
r#"
Rose a : [ Rose (Result (List (Rose a)) I64) ]
x : Rose I64
@ -401,53 +430,60 @@ mod gen_compare {
x == y
"#
),
true,
bool
);
}
),
true,
bool
);
}
#[test]
fn list_eq_empty() {
assert_evals_to!("[] == []", true, bool);
assert_evals_to!("[] != []", false, bool);
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn list_eq_empty() {
assert_evals_to!("[] == []", true, bool);
assert_evals_to!("[] != []", false, bool);
}
#[test]
fn list_eq_by_length() {
assert_evals_to!("[1] == []", false, bool);
assert_evals_to!("[] == [1]", false, bool);
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn list_eq_by_length() {
assert_evals_to!("[1] == []", false, bool);
assert_evals_to!("[] == [1]", false, bool);
}
#[test]
fn list_eq_compare_pointwise() {
assert_evals_to!("[1] == [1]", true, bool);
assert_evals_to!("[2] == [1]", false, bool);
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn list_eq_compare_pointwise() {
assert_evals_to!("[1] == [1]", true, bool);
assert_evals_to!("[2] == [1]", false, bool);
}
#[test]
fn list_eq_nested() {
assert_evals_to!("[[1]] == [[1]]", true, bool);
assert_evals_to!("[[2]] == [[1]]", false, bool);
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn list_eq_nested() {
assert_evals_to!("[[1]] == [[1]]", true, bool);
assert_evals_to!("[[2]] == [[1]]", false, bool);
}
#[test]
fn list_neq_compare_pointwise() {
assert_evals_to!("[1] != [1]", false, bool);
assert_evals_to!("[2] != [1]", true, bool);
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn list_neq_compare_pointwise() {
assert_evals_to!("[1] != [1]", false, bool);
assert_evals_to!("[2] != [1]", true, bool);
}
#[test]
fn list_neq_nested() {
assert_evals_to!("[[1]] != [[1]]", false, bool);
assert_evals_to!("[[2]] != [[1]]", true, bool);
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn list_neq_nested() {
assert_evals_to!("[[1]] != [[1]]", false, bool);
assert_evals_to!("[[2]] != [[1]]", true, bool);
}
#[test]
fn compare_union_same_content() {
assert_evals_to!(
indoc!(
r#"
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn compare_union_same_content() {
assert_evals_to!(
indoc!(
r#"
Foo : [ A I64, B I64 ]
a : Foo
@ -458,17 +494,18 @@ mod gen_compare {
a == b
"#
),
false,
bool
);
}
),
false,
bool
);
}
#[test]
fn compare_recursive_union_same_content() {
assert_evals_to!(
indoc!(
r#"
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn compare_recursive_union_same_content() {
assert_evals_to!(
indoc!(
r#"
Expr : [ Add Expr Expr, Mul Expr Expr, Val1 I64, Val2 I64 ]
v1 : Expr
@ -479,17 +516,18 @@ mod gen_compare {
v1 == v2
"#
),
false,
bool
);
}
),
false,
bool
);
}
#[test]
fn compare_nullable_recursive_union_same_content() {
assert_evals_to!(
indoc!(
r#"
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn compare_nullable_recursive_union_same_content() {
assert_evals_to!(
indoc!(
r#"
Expr : [ Add Expr Expr, Mul Expr Expr, Val1 I64, Val2 I64, Empty ]
v1 : Expr
@ -500,9 +538,8 @@ mod gen_compare {
v1 == v2
"#
),
false,
bool
);
}
),
false,
bool
);
}