mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 14:54:47 +00:00
Merge remote-tracking branch 'origin/can-builtins-simplify' into list-range
This commit is contained in:
commit
f2c144f58c
55 changed files with 2303 additions and 1059 deletions
|
@ -320,6 +320,32 @@ fn list_walk_substraction() {
|
|||
assert_evals_to!(r#"List.walk [ 1, 2 ] Num.sub 1"#, 2, i64);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn list_walk_until_sum() {
|
||||
assert_evals_to!(
|
||||
r#"List.walkUntil [ 1, 2 ] (\a,b -> Continue (a + b)) 0"#,
|
||||
3,
|
||||
i64
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn list_walk_until_even_prefix_sum() {
|
||||
assert_evals_to!(
|
||||
r#"
|
||||
helper = \a, b ->
|
||||
if Num.isEven a then
|
||||
Continue (a + b)
|
||||
|
||||
else
|
||||
Stop b
|
||||
|
||||
List.walkUntil [ 2, 4, 8, 9 ] helper 0"#,
|
||||
2 + 4 + 8,
|
||||
i64
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn list_keep_if_empty_list_of_int() {
|
||||
assert_evals_to!(
|
||||
|
|
|
@ -404,6 +404,7 @@ mod gen_num {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn f64_sqrt_zero() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
|
|
|
@ -2276,3 +2276,23 @@ fn function_malformed_pattern() {
|
|||
i64
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "Hit an erroneous type when creating a layout for")]
|
||||
fn call_invalid_layout() {
|
||||
assert_llvm_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
f : I64 -> I64
|
||||
f = \x -> x
|
||||
|
||||
f {}
|
||||
"#
|
||||
),
|
||||
3,
|
||||
i64,
|
||||
|x| x,
|
||||
false,
|
||||
true
|
||||
);
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
use crate::assert_evals_to;
|
||||
use crate::assert_llvm_evals_to;
|
||||
use indoc::indoc;
|
||||
use roc_std::{RocList, RocStr};
|
||||
|
||||
#[test]
|
||||
fn applied_tag_nothing_ir() {
|
||||
|
@ -974,3 +975,61 @@ fn newtype_wrapper() {
|
|||
|x: &i64| *x
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn applied_tag_function() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
x : List [ Foo Str ]
|
||||
x = List.map [ "a", "b" ] Foo
|
||||
|
||||
x
|
||||
"#
|
||||
),
|
||||
RocList::from_slice(&[
|
||||
RocStr::from_slice("a".as_bytes()),
|
||||
RocStr::from_slice("b".as_bytes())
|
||||
]),
|
||||
RocList<RocStr>
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn applied_tag_function_result() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
x : List (Result Str *)
|
||||
x = List.map [ "a", "b" ] Ok
|
||||
|
||||
x
|
||||
"#
|
||||
),
|
||||
RocList::from_slice(&[
|
||||
(1, RocStr::from_slice("a".as_bytes())),
|
||||
(1, RocStr::from_slice("b".as_bytes()))
|
||||
]),
|
||||
RocList<(i64, RocStr)>
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn applied_tag_function_linked_list() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
ConsList a : [ Nil, Cons a (ConsList a) ]
|
||||
|
||||
x : List (ConsList Str)
|
||||
x = List.map2 [ "a", "b" ] [ Nil, Cons "c" Nil ] Cons
|
||||
|
||||
when List.first x is
|
||||
Ok (Cons "a" Nil) -> 1
|
||||
_ -> 0
|
||||
"#
|
||||
),
|
||||
1,
|
||||
i64
|
||||
);
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ pub fn helper<'a>(
|
|||
src: &str,
|
||||
stdlib: &'a roc_builtins::std::StdLib,
|
||||
leak: bool,
|
||||
ignore_problems: bool,
|
||||
context: &'a inkwell::context::Context,
|
||||
) -> (&'static str, String, Library) {
|
||||
use roc_gen::llvm::build::{build_proc, build_proc_header, Scope};
|
||||
|
@ -170,7 +171,7 @@ pub fn helper<'a>(
|
|||
println!("{}", lines.join("\n"));
|
||||
|
||||
// only crash at this point if there were no delayed_errors
|
||||
if delayed_errors.is_empty() {
|
||||
if delayed_errors.is_empty() && !ignore_problems {
|
||||
assert_eq!(0, 1, "Mistakes were made");
|
||||
}
|
||||
}
|
||||
|
@ -331,7 +332,7 @@ pub fn helper<'a>(
|
|||
|
||||
#[macro_export]
|
||||
macro_rules! assert_llvm_evals_to {
|
||||
($src:expr, $expected:expr, $ty:ty, $transform:expr, $leak:expr) => {
|
||||
($src:expr, $expected:expr, $ty:ty, $transform:expr, $leak:expr, $ignore_problems:expr) => {
|
||||
use bumpalo::Bump;
|
||||
use inkwell::context::Context;
|
||||
use roc_gen::run_jit_function;
|
||||
|
@ -343,7 +344,7 @@ macro_rules! assert_llvm_evals_to {
|
|||
let stdlib = arena.alloc(roc_builtins::std::standard_stdlib());
|
||||
|
||||
let (main_fn_name, errors, lib) =
|
||||
$crate::helpers::eval::helper(&arena, $src, stdlib, $leak, &context);
|
||||
$crate::helpers::eval::helper(&arena, $src, stdlib, $leak, $ignore_problems, &context);
|
||||
|
||||
let transform = |success| {
|
||||
let expected = $expected;
|
||||
|
@ -354,7 +355,7 @@ macro_rules! assert_llvm_evals_to {
|
|||
};
|
||||
|
||||
($src:expr, $expected:expr, $ty:ty, $transform:expr) => {
|
||||
assert_llvm_evals_to!($src, $expected, $ty, $transform, true);
|
||||
assert_llvm_evals_to!($src, $expected, $ty, $transform, true, false);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -375,7 +376,7 @@ macro_rules! assert_evals_to {
|
|||
// parsing the source, so that there's no chance their passing
|
||||
// or failing depends on leftover state from the previous one.
|
||||
{
|
||||
assert_llvm_evals_to!($src, $expected, $ty, $transform, $leak);
|
||||
assert_llvm_evals_to!($src, $expected, $ty, $transform, $leak, false);
|
||||
}
|
||||
{
|
||||
// NOTE at the moment, the optimized tests do the same thing
|
||||
|
@ -392,7 +393,7 @@ macro_rules! assert_non_opt_evals_to {
|
|||
($src:expr, $expected:expr, $ty:ty, $transform:expr) => {
|
||||
// Same as above, except with an additional transformation argument.
|
||||
{
|
||||
assert_llvm_evals_to!($src, $expected, $ty, $transform, true);
|
||||
assert_llvm_evals_to!($src, $expected, $ty, $transform, true, false);
|
||||
}
|
||||
};
|
||||
($src:expr, $expected:expr, $ty:ty, $transform:expr, $leak:expr) => {{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue