Merge branch 'main' into specialize-exprs

This commit is contained in:
Agus Zubiaga 2024-11-23 01:48:51 -03:00
commit 2e96aca0fd
No known key found for this signature in database
797 changed files with 17394 additions and 12632 deletions

View file

@ -371,10 +371,10 @@ fn list_map_try_err() {
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn list_split() {
fn list_split_at() {
assert_evals_to!(
r"
list = List.split [1, 2, 3] 0
list = List.splitAt [1, 2, 3] 0
list.before
",
RocList::<i64>::from_slice(&[]),
@ -382,7 +382,7 @@ fn list_split() {
);
assert_evals_to!(
r"
list = List.split [1, 2, 3] 0
list = List.splitAt [1, 2, 3] 0
list.others
",
RocList::from_slice(&[1, 2, 3]),
@ -390,13 +390,13 @@ fn list_split() {
);
assert_evals_to!(
r"
List.split [1, 2, 3] 1
List.splitAt [1, 2, 3] 1
",
(RocList::from_slice(&[1]), RocList::from_slice(&[2, 3])),
(RocList<i64>, RocList<i64>,)
);
assert_evals_to!(
"List.split [1, 2, 3] 3",
"List.splitAt [1, 2, 3] 3",
(
RocList::from_slice(&[1, 2, 3]),
RocList::<i64>::from_slice(&[]),
@ -404,7 +404,7 @@ fn list_split() {
(RocList<i64>, RocList<i64>,)
);
assert_evals_to!(
"List.split [1, 2, 3] 4",
"List.splitAt [1, 2, 3] 4",
(
RocList::from_slice(&[1, 2, 3]),
RocList::<i64>::from_slice(&[]),
@ -412,7 +412,7 @@ fn list_split() {
(RocList<i64>, RocList<i64>,)
);
assert_evals_to!(
"List.split [] 1",
"List.splitAt [] 1",
(
RocList::<i64>::from_slice(&[]),
RocList::<i64>::from_slice(&[]),
@ -421,6 +421,133 @@ fn list_split() {
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn list_split_on() {
assert_evals_to!(
r"
List.splitOn [] 1
",
RocList::<RocList<i64>>::from_slice(&[RocList::<i64>::from_slice(&[])]),
RocList<RocList<i64>>
);
assert_evals_to!(
r"
List.splitOn [1] 1
",
RocList::<RocList<i64>>::from_slice(&[
RocList::<i64>::from_slice(&[]),
RocList::<i64>::from_slice(&[]),
]),
RocList<RocList<i64>>
);
assert_evals_to!(
r"
List.splitOn [1, 2, 3] 47
",
RocList::<RocList<i64>>::from_slice(&[RocList::<i64>::from_slice(&[1, 2, 3])]),
RocList<RocList<i64>>
);
assert_evals_to!(
r"
List.splitOn [1, 2, 3, 4, 5] 3
",
RocList::<RocList<i64>>::from_slice(&[
RocList::<i64>::from_slice(&[1, 2]),
RocList::<i64>::from_slice(&[4, 5]),
]),
RocList<RocList<i64>>
);
assert_evals_to!(
r"
List.splitOn [1, 0, 1, 0, 1] 1
",
RocList::<RocList<i64>>::from_slice(&[
RocList::<i64>::from_slice(&[]),
RocList::<i64>::from_slice(&[0]),
RocList::<i64>::from_slice(&[0]),
RocList::<i64>::from_slice(&[]),
]),
RocList<RocList<i64>>
);
assert_evals_to!(
r"
List.splitOn [1, 0, 1, 0, 1] 0
",
RocList::<RocList<i64>>::from_slice(&[
RocList::<i64>::from_slice(&[1]),
RocList::<i64>::from_slice(&[1]),
RocList::<i64>::from_slice(&[1]),
]),
RocList<RocList<i64>>
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn list_split_on_list() {
assert_evals_to!(
r"
List.splitOnList [] []
",
RocList::<RocList<i64>>::from_slice(&[RocList::<i64>::from_slice(&[])]),
RocList<RocList<i64>>
);
assert_evals_to!(
r"
List.splitOnList [] [1, 2, 3]
",
RocList::<RocList<i64>>::from_slice(&[RocList::<i64>::from_slice(&[]),]),
RocList<RocList<i64>>
);
assert_evals_to!(
r"
List.splitOnList [1, 2, 3] []
",
RocList::<RocList<i64>>::from_slice(&[RocList::<i64>::from_slice(&[1, 2, 3]),]),
RocList<RocList<i64>>
);
assert_evals_to!(
r"
List.splitOnList [1] [1]
",
RocList::<RocList<i64>>::from_slice(&[
RocList::<i64>::from_slice(&[]),
RocList::<i64>::from_slice(&[]),
]),
RocList<RocList<i64>>
);
assert_evals_to!(
r"
List.splitOnList [1, 2, 3] [47]
",
RocList::<RocList<i64>>::from_slice(&[RocList::<i64>::from_slice(&[1, 2, 3])]),
RocList<RocList<i64>>
);
assert_evals_to!(
r"
List.splitOnList [1, 2, 3, 4, 5] [2, 3]
",
RocList::<RocList<i64>>::from_slice(&[
RocList::<i64>::from_slice(&[1]),
RocList::<i64>::from_slice(&[4, 5]),
]),
RocList<RocList<i64>>
);
assert_evals_to!(
r"
List.splitOnList [1, 0, 1, 0, 1] [1]
",
RocList::<RocList<i64>>::from_slice(&[
RocList::<i64>::from_slice(&[]),
RocList::<i64>::from_slice(&[0]),
RocList::<i64>::from_slice(&[0]),
RocList::<i64>::from_slice(&[]),
]),
RocList<RocList<i64>>
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn list_split_first() {
@ -3172,7 +3299,7 @@ fn list_join_map() {
assert_evals_to!(
indoc!(
r#"
List.joinMap ["guava,apple,pear", "bailey,cyrus"] (\s -> Str.split s ",")
List.joinMap ["guava,apple,pear", "bailey,cyrus"] (\s -> Str.splitOn s ",")
"#
),
RocList::from_slice(&[
@ -3192,7 +3319,7 @@ fn list_join_map_empty() {
assert_evals_to!(
indoc!(
r#"
List.joinMap [] (\s -> Str.split s ",")
List.joinMap [] (\s -> Str.splitOn s ",")
"#
),
RocList::from_slice(&[]),

View file

@ -1605,20 +1605,21 @@ fn tail_call_elimination() {
);
}
#[test]
#[cfg(feature = "gen-dev")]
fn int_negate_dev() {
// TODO
// dev backend yet to have `Num.maxI64` or `Num.minI64`.
// add the "gen-dev" feature to the test below after implementing them both.
assert_evals_to!("Num.neg 123", -123, i64);
assert_evals_to!("Num.neg -123", 123, i64);
assert_evals_to!("Num.neg 0", 0, i64);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn int_negate() {
assert_evals_to!("Num.neg 123i8", -123, i8);
assert_evals_to!("Num.neg Num.maxI8", -i8::MAX, i8);
assert_evals_to!("Num.neg (Num.minI8 + 1)", i8::MAX, i8);
assert_evals_to!("Num.neg 123i16", -123, i16);
assert_evals_to!("Num.neg Num.maxI16", -i16::MAX, i16);
assert_evals_to!("Num.neg (Num.minI16 + 1)", i16::MAX, i16);
assert_evals_to!("Num.neg 123i32", -123, i32);
assert_evals_to!("Num.neg Num.maxI32", -i32::MAX, i32);
assert_evals_to!("Num.neg (Num.minI32 + 1)", i32::MAX, i32);
assert_evals_to!("Num.neg 123", -123, i64);
assert_evals_to!("Num.neg Num.maxI64", -i64::MAX, i64);
assert_evals_to!("Num.neg (Num.minI64 + 1)", i64::MAX, i64);

View file

@ -220,13 +220,13 @@ fn list_str_take_first() {
#[test]
#[cfg(feature = "gen-wasm")]
fn list_str_split() {
fn list_str_split_on() {
assert_refcounts!(
indoc!(
r#"
s = Str.concat "A long enough string " "to be heap-allocated"
list = [s, s, s]
List.split list 1
List.splitAt list 1
"#
),
(RocList<RocStr>, RocList<RocStr>),
@ -239,13 +239,13 @@ fn list_str_split() {
#[test]
#[cfg(feature = "gen-wasm")]
fn list_str_split_zero() {
fn list_str_split_on_zero() {
assert_refcounts!(
indoc!(
r#"
s = Str.concat "A long enough string " "to be heap-allocated"
list = [s, s, s]
List.split list 0
List.splitAt list 0
"#
),
(RocList<RocStr>, RocList<RocStr>),

View file

@ -0,0 +1,265 @@
#![cfg(not(feature = "gen-wasm"))]
#[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-llvm")]
use crate::helpers::llvm::identity;
#[cfg(feature = "gen-dev")]
use crate::helpers::dev::identity;
#[allow(unused_imports)]
use indoc::indoc;
#[allow(unused_imports)]
use roc_std::{RocList, RocResult, RocStr, I128, U128};
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn early_return_nested_ifs() {
assert_evals_to!(
indoc!(
r#"
app "test" provides [main] to "./platform"
displayN = \n ->
first = Num.toStr n
second =
if n == 1 then
return "early 1"
else
third = Num.toStr (n + 1)
if n == 2 then
return "early 2"
else
third
"$(first), $(second)"
main : List Str
main = List.map [1, 2, 3] displayN
"#
),
RocList::from_slice(&[
RocStr::from("early 1"),
RocStr::from("early 2"),
RocStr::from("3, 4")
]),
RocList<RocStr>
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn early_return_nested_whens() {
assert_evals_to!(
indoc!(
r#"
app "test" provides [main] to "./platform"
displayN = \n ->
first = Num.toStr n
second =
when n is
1 ->
return "early 1"
_ ->
third = Num.toStr (n + 1)
when n is
2 ->
return "early 2"
_ ->
third
"$(first), $(second)"
main : List Str
main = List.map [1, 2, 3] displayN
"#
),
RocList::from_slice(&[
RocStr::from("early 1"),
RocStr::from("early 2"),
RocStr::from("3, 4")
]),
RocList<RocStr>
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn early_return_solo() {
assert_evals_to!(
r#"
identity = \x ->
return x
identity "abc"
"#,
RocStr::from("abc"),
RocStr,
identity,
true
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn early_return_solo_annotated() {
assert_evals_to!(
r#"
identity : Str -> Str
identity = \x ->
return x
identity "abc"
"#,
RocStr::from("abc"),
RocStr,
identity,
true
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn early_return_annotated_function() {
assert_evals_to!(
indoc!(
r#"
app "test" provides [main] to "./platform"
failIfLessThanFive : U64 -> Result {} [LessThanFive]
failIfLessThanFive = \n ->
if n < 5 then
Err LessThanFive
else
Ok {}
validateInput : Str -> Result U64 [InvalidNumStr, LessThanFive]
validateInput = \str ->
num = try Str.toU64 str
when failIfLessThanFive num is
Err err ->
return Err err
Ok {} ->
Ok num
main : List Str
main =
["abc", "3", "7"]
|> List.map validateInput
|> List.map Inspect.toStr
"#
),
RocList::from_slice(&[
RocStr::from("(Err InvalidNumStr)"),
RocStr::from("(Err LessThanFive)"),
RocStr::from("(Ok 7)")
]),
RocList<RocStr>
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn early_return_nested_annotated_function() {
assert_evals_to!(
indoc!(
r#"
app "test" provides [main] to "./platform"
validateInput : Str -> Result U64 [InvalidNumStr, LessThanFive]
validateInput = \str ->
failIfLessThanFive : U64 -> Result {} [LessThanFive]
failIfLessThanFive = \n ->
if n < 5 then
Err LessThanFive
else
Ok {}
num = try Str.toU64 str
when failIfLessThanFive num is
Err err ->
return Err err
Ok {} ->
Ok num
main : List Str
main =
["abc", "3", "7"]
|> List.map validateInput
|> List.map Inspect.toStr
"#
),
RocList::from_slice(&[
RocStr::from("(Err InvalidNumStr)"),
RocStr::from("(Err LessThanFive)"),
RocStr::from("(Ok 7)")
]),
RocList<RocStr>
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm", feature = "gen-dev"))]
fn early_return_annotated_recursive_function() {
assert_evals_to!(
indoc!(
r#"
app "test" provides [main] to "./platform"
mightCallSecond : U64 -> Result U64 _
mightCallSecond = \num ->
nextNum =
if num < 5 then
return Err LessThanFive
else
num - 1
mightCallFirst nextNum
mightCallFirst : U64 -> Result U64 _
mightCallFirst = \num ->
nextNum =
if num < 10 then
return Err LessThanTen
else
num * 2
if nextNum > 25 then
Ok nextNum
else
mightCallSecond nextNum
main : List Str
main =
[
mightCallSecond 3,
mightCallSecond 7,
mightCallSecond 20,
mightCallFirst 7,
mightCallFirst 15,
]
|> List.map Inspect.toStr
"#
),
RocList::from_slice(&[
RocStr::from("(Err LessThanFive)"),
RocStr::from("(Err LessThanTen)"),
RocStr::from("(Ok 38)"),
RocStr::from("(Err LessThanTen)"),
RocStr::from("(Ok 30)")
]),
RocList<RocStr>
);
}

View file

@ -51,11 +51,11 @@ fn string_neq() {
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
fn str_split_empty_delimiter() {
fn str_split_on_empty_delimiter() {
assert_evals_to!(
indoc!(
r#"
List.len (Str.split "hello" "")
List.len (Str.splitOn "hello" "")
"#
),
1,
@ -65,7 +65,7 @@ fn str_split_empty_delimiter() {
assert_evals_to!(
indoc!(
r#"
when List.first (Str.split "JJJ" "") is
when List.first (Str.splitOn "JJJ" "") is
Ok str ->
Str.countUtf8Bytes str
@ -81,11 +81,11 @@ fn str_split_empty_delimiter() {
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
fn str_split_bigger_delimiter_small_str() {
fn str_split_on_bigger_delimiter_small_str() {
assert_evals_to!(
indoc!(
r#"
List.len (Str.split "hello" "JJJJ there")
List.len (Str.splitOn "hello" "JJJJ there")
"#
),
1,
@ -95,7 +95,7 @@ fn str_split_bigger_delimiter_small_str() {
assert_evals_to!(
indoc!(
r#"
when List.first (Str.split "JJJ" "JJJJ there") is
when List.first (Str.splitOn "JJJ" "JJJJ there") is
Ok str ->
Str.countUtf8Bytes str
@ -111,11 +111,11 @@ fn str_split_bigger_delimiter_small_str() {
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
fn str_split_str_concat_repeated() {
fn str_split_on_str_concat_repeated() {
assert_evals_to!(
indoc!(
r#"
when List.first (Str.split "JJJJJ" "JJJJ there") is
when List.first (Str.splitOn "JJJJJ" "JJJJ there") is
Ok str ->
str
|> Str.concat str
@ -135,9 +135,9 @@ fn str_split_str_concat_repeated() {
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
fn str_split_small_str_bigger_delimiter() {
fn str_split_on_small_str_bigger_delimiter() {
assert_evals_to!(
indoc!(r#"Str.split "JJJ" "0123456789abcdefghi""#),
indoc!(r#"Str.splitOn "JJJ" "0123456789abcdefghi""#),
RocList::from_slice(&[RocStr::from("JJJ")]),
RocList<RocStr>
);
@ -145,11 +145,11 @@ fn str_split_small_str_bigger_delimiter() {
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
fn str_split_big_str_small_delimiter() {
fn str_split_on_big_str_small_delimiter() {
assert_evals_to!(
indoc!(
r#"
Str.split "01234567789abcdefghi?01234567789abcdefghi" "?"
Str.splitOn "01234567789abcdefghi?01234567789abcdefghi" "?"
"#
),
RocList::from_slice(&[
@ -162,7 +162,7 @@ fn str_split_big_str_small_delimiter() {
assert_evals_to!(
indoc!(
r#"
Str.split "01234567789abcdefghi 3ch 01234567789abcdefghi" "3ch"
Str.splitOn "01234567789abcdefghi 3ch 01234567789abcdefghi" "3ch"
"#
),
RocList::from_slice(&[
@ -175,11 +175,11 @@ fn str_split_big_str_small_delimiter() {
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
fn str_split_small_str_small_delimiter() {
fn str_split_on_small_str_small_delimiter() {
assert_evals_to!(
indoc!(
r#"
Str.split "J!J!J" "!"
Str.splitOn "J!J!J" "!"
"#
),
RocList::from_slice(&[RocStr::from("J"), RocStr::from("J"), RocStr::from("J")]),
@ -189,11 +189,11 @@ fn str_split_small_str_small_delimiter() {
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
fn str_split_bigger_delimiter_big_strs() {
fn str_split_on_bigger_delimiter_big_strs() {
assert_evals_to!(
indoc!(
r#"
Str.split
Str.splitOn
"string to split is shorter"
"than the delimiter which happens to be very very long"
"#
@ -205,11 +205,11 @@ fn str_split_bigger_delimiter_big_strs() {
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
fn str_split_empty_strs() {
fn str_split_on_empty_strs() {
assert_evals_to!(
indoc!(
r#"
Str.split "" ""
Str.splitOn "" ""
"#
),
RocList::from_slice(&[RocStr::from("")]),
@ -219,11 +219,11 @@ fn str_split_empty_strs() {
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
fn str_split_minimal_example() {
fn str_split_on_minimal_example() {
assert_evals_to!(
indoc!(
r#"
Str.split "a," ","
Str.splitOn "a," ","
"#
),
RocList::from_slice(&[RocStr::from("a"), RocStr::from("")]),
@ -233,11 +233,11 @@ fn str_split_minimal_example() {
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
fn str_split_small_str_big_delimiter() {
fn str_split_on_small_str_big_delimiter() {
assert_evals_to!(
indoc!(
r#"
Str.split
Str.splitOn
"1---- ---- ---- ---- ----2---- ---- ---- ---- ----"
"---- ---- ---- ---- ----"
|> List.len
@ -250,7 +250,7 @@ fn str_split_small_str_big_delimiter() {
assert_evals_to!(
indoc!(
r#"
Str.split
Str.splitOn
"1---- ---- ---- ---- ----2---- ---- ---- ---- ----"
"---- ---- ---- ---- ----"
"#
@ -262,11 +262,11 @@ fn str_split_small_str_big_delimiter() {
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
fn str_split_small_str_20_char_delimiter() {
fn str_split_on_small_str_20_char_delimiter() {
assert_evals_to!(
indoc!(
r#"
Str.split
Str.splitOn
"3|-- -- -- -- -- -- |4|-- -- -- -- -- -- |"
"|-- -- -- -- -- -- |"
"#
@ -1548,7 +1548,7 @@ fn issue_2811() {
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
fn str_split_first_one_char() {
fn str_split_on_first_one_char() {
assert_evals_to!(
indoc!(
r#"
@ -1564,7 +1564,7 @@ fn str_split_first_one_char() {
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
fn str_split_first_multiple_chars() {
fn str_split_on_first_multiple_chars() {
assert_evals_to!(
indoc!(
r#"
@ -1578,7 +1578,7 @@ fn str_split_first_multiple_chars() {
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
fn str_split_first_entire_input() {
fn str_split_on_first_entire_input() {
assert_evals_to!(
indoc!(
r#"
@ -1592,7 +1592,7 @@ fn str_split_first_entire_input() {
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
fn str_split_first_not_found() {
fn str_split_on_first_not_found() {
assert_evals_to!(
indoc!(
r#"
@ -1606,7 +1606,7 @@ fn str_split_first_not_found() {
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
fn str_split_last_one_char() {
fn str_split_on_last_one_char() {
assert_evals_to!(
indoc!(
r#"
@ -1620,7 +1620,7 @@ fn str_split_last_one_char() {
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
fn str_split_last_multiple_chars() {
fn str_split_on_last_multiple_chars() {
assert_evals_to!(
indoc!(
r#"
@ -1634,7 +1634,7 @@ fn str_split_last_multiple_chars() {
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
fn str_split_last_entire_input() {
fn str_split_on_last_entire_input() {
assert_evals_to!(
indoc!(
r#"
@ -1648,7 +1648,7 @@ fn str_split_last_entire_input() {
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
fn str_split_last_not_found() {
fn str_split_on_last_not_found() {
assert_evals_to!(
indoc!(
r#"
@ -1662,9 +1662,9 @@ fn str_split_last_not_found() {
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
fn str_split_overlapping_substring_1() {
fn str_split_on_overlapping_substring_1() {
assert_evals_to!(
r#"Str.split "aaa" "aa""#,
r#"Str.splitOn "aaa" "aa""#,
RocList::from_slice(&[RocStr::from(""), RocStr::from("a")]),
RocList<RocStr>
);
@ -1672,9 +1672,9 @@ fn str_split_overlapping_substring_1() {
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
fn str_split_overlapping_substring_2() {
fn str_split_on_overlapping_substring_2() {
assert_evals_to!(
r#"Str.split "aaaa" "aa""#,
r#"Str.splitOn "aaaa" "aa""#,
RocList::from_slice(&[RocStr::from(""), RocStr::from(""), RocStr::from("")]),
RocList<RocStr>
);
@ -1988,3 +1988,75 @@ fn str_contains_self() {
bool
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev", feature = "gen-wasm"))]
fn str_drop_prefix() {
assert_evals_to!(
r#"
Str.dropPrefix "" "foo"
"#,
RocStr::from(""),
RocStr
);
assert_evals_to!(
r#"
Str.dropPrefix "bar" "foo"
"#,
RocStr::from("bar"),
RocStr
);
assert_evals_to!(
r#"
Str.dropPrefix "foobar" "foo"
"#,
RocStr::from("bar"),
RocStr
);
assert_evals_to!(
r#"
Str.dropPrefix "fooBarThisIsDefinitelyAReallyLongAndNotaShortString" "foo"
"#,
RocStr::from("BarThisIsDefinitelyAReallyLongAndNotaShortString"),
RocStr
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev", feature = "gen-wasm"))]
fn str_drop_suffix() {
assert_evals_to!(
r#"
Str.dropSuffix "" "foo"
"#,
RocStr::from(""),
RocStr
);
assert_evals_to!(
r#"
Str.dropSuffix "bar" "foo"
"#,
RocStr::from("bar"),
RocStr
);
assert_evals_to!(
r#"
Str.dropSuffix "barfoo" "foo"
"#,
RocStr::from("bar"),
RocStr
);
assert_evals_to!(
r#"
Str.dropSuffix "BarThisIsDefinitelyAReallyLongAndNotaShortStringfoo" "foo"
"#,
RocStr::from("BarThisIsDefinitelyAReallyLongAndNotaShortString"),
RocStr
);
}

View file

@ -113,9 +113,13 @@ pub fn helper(
} => {
// TODO support multiple of these!
debug_assert_eq!(exposed_to_host.len(), 1);
let (symbol, layout) = exposed_to_host[0];
let (name, symbol, layout) = exposed_to_host[0];
SingleEntryPoint { symbol, layout }
SingleEntryPoint {
name,
symbol,
layout,
}
}
EntryPoint::Test => {
unreachable!()

View file

@ -243,9 +243,13 @@ fn create_llvm_module<'a>(
} => {
// TODO support multiple of these!
debug_assert_eq!(exposed_to_host.len(), 1);
let (symbol, layout) = exposed_to_host[0];
let (name, symbol, layout) = exposed_to_host[0];
SingleEntryPoint { symbol, layout }
SingleEntryPoint {
name,
symbol,
layout,
}
}
EntryPoint::Test => {
unreachable!()
@ -536,6 +540,7 @@ pub fn try_run_lib_function<T>(
}
}
#[allow(dead_code)]
// only used in tests
#[allow(dead_code)]
pub(crate) fn llvm_evals_to<T, U, F>(

View file

@ -16,6 +16,7 @@ pub mod gen_primitives;
pub mod gen_records;
pub mod gen_refcount;
pub mod gen_result;
pub mod gen_return;
pub mod gen_set;
pub mod gen_str;
pub mod gen_tags;

View file

@ -15,11 +15,11 @@ use indoc::indoc;
use roc_std::{RocList, RocStr, I128, U128};
#[test]
fn str_split_empty_delimiter() {
fn str_split_on_empty_delimiter() {
assert_evals_to!(
indoc!(
r#"
List.len (Str.split "hello" "")
List.len (Str.splitOn "hello" "")
"#
),
1,
@ -28,11 +28,11 @@ fn str_split_empty_delimiter() {
}
#[test]
fn str_split_bigger_delimiter_small_str() {
fn str_split_on_bigger_delimiter_small_str() {
assert_evals_to!(
indoc!(
r#"
List.len (Str.split "hello" "JJJJ there")
List.len (Str.splitOn "hello" "JJJJ there")
"#
),
1,
@ -41,11 +41,11 @@ fn str_split_bigger_delimiter_small_str() {
}
#[test]
fn str_split_str_concat_repeated() {
fn str_split_on_str_concat_repeated() {
assert_evals_to!(
indoc!(
r#"
when List.first (Str.split "JJJJJ" "JJJJ there") is
when List.first (Str.splitOn "JJJJJ" "JJJJ there") is
Ok str ->
str
|> Str.concat str
@ -64,13 +64,13 @@ fn str_split_str_concat_repeated() {
}
#[test]
fn str_split_small_str_bigger_delimiter() {
fn str_split_on_small_str_bigger_delimiter() {
assert_evals_to!(
indoc!(
r#"
when
List.first
(Str.split "JJJ" "0123456789abcdefghi")
(Str.splitOn "JJJ" "0123456789abcdefghi")
is
Ok str -> str
_ -> ""
@ -82,11 +82,11 @@ fn str_split_small_str_bigger_delimiter() {
}
#[test]
fn str_split_big_str_small_delimiter() {
fn str_split_on_big_str_small_delimiter() {
assert_evals_to!(
indoc!(
r#"
Str.split "01234567789abcdefghi?01234567789abcdefghi" "?"
Str.splitOn "01234567789abcdefghi?01234567789abcdefghi" "?"
"#
),
RocList::from_slice(&[
@ -99,7 +99,7 @@ fn str_split_big_str_small_delimiter() {
assert_evals_to!(
indoc!(
r#"
Str.split "01234567789abcdefghi 3ch 01234567789abcdefghi" "3ch"
Str.splitOn "01234567789abcdefghi 3ch 01234567789abcdefghi" "3ch"
"#
),
RocList::from_slice(&[
@ -111,11 +111,11 @@ fn str_split_big_str_small_delimiter() {
}
#[test]
fn str_split_small_str_small_delimiter() {
fn str_split_on_small_str_small_delimiter() {
assert_evals_to!(
indoc!(
r#"
Str.split "J!J!J" "!"
Str.splitOn "J!J!J" "!"
"#
),
RocList::from_slice(&[RocStr::from("J"), RocStr::from("J"), RocStr::from("J")]),
@ -124,11 +124,11 @@ fn str_split_small_str_small_delimiter() {
}
#[test]
fn str_split_bigger_delimiter_big_strs() {
fn str_split_on_bigger_delimiter_big_strs() {
assert_evals_to!(
indoc!(
r#"
Str.split
Str.splitOn
"string to split is shorter"
"than the delimiter which happens to be very very long"
"#
@ -139,11 +139,11 @@ fn str_split_bigger_delimiter_big_strs() {
}
#[test]
fn str_split_empty_strs() {
fn str_split_on_empty_strs() {
assert_evals_to!(
indoc!(
r#"
Str.split "" ""
Str.splitOn "" ""
"#
),
RocList::from_slice(&[RocStr::from("")]),
@ -152,11 +152,11 @@ fn str_split_empty_strs() {
}
#[test]
fn str_split_minimal_example() {
fn str_split_on_minimal_example() {
assert_evals_to!(
indoc!(
r#"
Str.split "a," ","
Str.splitOn "a," ","
"#
),
RocList::from_slice(&[RocStr::from("a"), RocStr::from("")]),
@ -165,11 +165,11 @@ fn str_split_minimal_example() {
}
#[test]
fn str_split_small_str_big_delimiter() {
fn str_split_on_small_str_big_delimiter() {
assert_evals_to!(
indoc!(
r#"
Str.split
Str.splitOn
"1---- ---- ---- ---- ----2---- ---- ---- ---- ----"
"---- ---- ---- ---- ----"
|> List.len
@ -182,7 +182,7 @@ fn str_split_small_str_big_delimiter() {
assert_evals_to!(
indoc!(
r#"
Str.split
Str.splitOn
"1---- ---- ---- ---- ----2---- ---- ---- ---- ----"
"---- ---- ---- ---- ----"
"#
@ -193,11 +193,11 @@ fn str_split_small_str_big_delimiter() {
}
#[test]
fn str_split_small_str_20_char_delimiter() {
fn str_split_on_small_str_20_char_delimiter() {
assert_evals_to!(
indoc!(
r#"
Str.split
Str.splitOn
"3|-- -- -- -- -- -- |4|-- -- -- -- -- -- |"
"|-- -- -- -- -- -- |"
"#