mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 06:14:46 +00:00
Str Split bitcode
This commit is contained in:
parent
bf81e67a89
commit
626d49d7b0
3 changed files with 91 additions and 12 deletions
|
@ -3,7 +3,7 @@ extern crate pretty_assertions;
|
|||
|
||||
#[cfg(test)]
|
||||
mod bitcode {
|
||||
use roc_builtins_bitcode::{count_delimiters_, measure_next_split_segment_length_};
|
||||
use roc_builtins_bitcode::{count_delimiters_, measure_next_split_segment_length_, str_split_};
|
||||
|
||||
#[test]
|
||||
fn count_delimiters() {
|
||||
|
@ -21,6 +21,47 @@ mod bitcode {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn str_split() {
|
||||
fn splits_to(string: &str, delimiter: &str, expectation: &[&[u8]]) {
|
||||
assert_eq!(
|
||||
str_split_(
|
||||
&mut [(&"").as_bytes()].repeat(expectation.len()),
|
||||
&string.as_bytes(),
|
||||
&delimiter.as_bytes()
|
||||
),
|
||||
expectation
|
||||
);
|
||||
}
|
||||
|
||||
splits_to(
|
||||
"a!b!c",
|
||||
"!",
|
||||
&[(&"a").as_bytes(), (&"b").as_bytes(), (&"c").as_bytes()],
|
||||
);
|
||||
|
||||
splits_to(
|
||||
"a!?b!?c!?",
|
||||
"!?",
|
||||
&[
|
||||
(&"a").as_bytes(),
|
||||
(&"b").as_bytes(),
|
||||
(&"c").as_bytes(),
|
||||
(&"").as_bytes(),
|
||||
],
|
||||
);
|
||||
|
||||
splits_to("abc", "!", &[(&"abc").as_bytes()]);
|
||||
|
||||
splits_to(
|
||||
"tttttghittttt",
|
||||
"ttttt",
|
||||
&[(&"").as_bytes(), (&"ghi").as_bytes(), (&"").as_bytes()],
|
||||
);
|
||||
|
||||
splits_to("def", "!!!!!!", &[(&"def").as_bytes()]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn measure_next_split_segment() {
|
||||
assert_eq!(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue