Add Str.walkUtf8

This commit is contained in:
Richard Feldman 2023-03-29 15:52:08 -04:00
parent f7e96ecf82
commit c3c1b8d083
No known key found for this signature in database
GPG key ID: F1F21AA5B1D9E43B
3 changed files with 56 additions and 0 deletions

View file

@ -1822,6 +1822,33 @@ fn str_split_overlapping_substring_2() {
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
fn str_walk_utf8() {
#[cfg(not(feature = "gen-llvm-wasm"))]
assert_evals_to!(
// Reverse the bytes
indoc!(
r#"
Str.walkUtf8 "abcd" [] (\list, byte -> List.prepend list byte)
"#
),
RocList::from_slice(&[b'd', b'c', b'b', b'a']),
RocList<u8>
);
#[cfg(feature = "gen-llvm-wasm")]
assert_evals_to!(
indoc!(
r#"
Str.walkUtf8WithIndex "abcd" [] (\list, byte, index -> List.append list (Pair index byte))
"#
),
RocList::from_slice(&[(0, 'a'), (1, 'b'), (2, 'c'), (3, 'd')]),
RocList<(u32, char)>
);
}
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-dev"))]
fn str_walk_utf8_with_index() {