Add tests for Str.splitLast

There was only one test, which didn't cover the bug I fixed in Str.splitLast. I
added the tests to make sure the bug will be caught in the future.
This commit is contained in:
kilianv 2022-09-01 17:03:26 +02:00
parent 97f49bf940
commit 273907319d
No known key found for this signature in database
GPG key ID: 8E1AEB931E0A6174

View file

@ -1758,7 +1758,7 @@ fn str_split_first_not_found() {
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_split_last() {
fn str_split_last_one_char() {
assert_evals_to!(
indoc!(
r#"
@ -1770,6 +1770,48 @@ fn str_split_last() {
);
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_split_last_multiple_chars() {
assert_evals_to!(
indoc!(
r#"
Str.splitLast "foo//bar//baz" "//"
"#
),
RocResult::ok((RocStr::from("baz"), RocStr::from("foo//bar"))),
RocResult<(RocStr, RocStr), ()>
);
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_split_last_entire_input() {
assert_evals_to!(
indoc!(
r#"
Str.splitLast "foo" "foo"
"#
),
RocResult::ok((RocStr::from(""), RocStr::from(""))),
RocResult<(RocStr, RocStr), ()>
);
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_split_last_not_found() {
assert_evals_to!(
indoc!(
r#"
Str.splitFirst "foo" "bar"
"#
),
RocResult::err(()),
RocResult<(RocStr, RocStr), ()>
);
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn str_walk_utf8_with_index() {