add string split method

This commit is contained in:
Ava Hahn 2023-03-08 19:42:08 -08:00
parent 7438b2c9e5
commit 6961fcc9fa
Signed by untrusted user who does not match committer: affine
GPG key ID: 3A4645B8CF806069
4 changed files with 90 additions and 2 deletions

View file

@ -181,4 +181,49 @@ mod str_lib_tests {
result.to_string(),
);
}
#[test]
fn test_split() {
let document = "(split 'one.two.three' '.')";
let result = "('one' 'two' 'three')";
let mut syms = SymTable::new();
static_stdlib(&mut syms).unwrap();
dynamic_stdlib(&mut syms).unwrap();
assert_eq!(
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
.unwrap()
.to_string(),
result.to_string(),
);
}
#[test]
fn test_split_big_delim() {
let document = "(split 'one:d:two:d:three' ':d:')";
let result = "('one' 'two' 'three')";
let mut syms = SymTable::new();
static_stdlib(&mut syms).unwrap();
dynamic_stdlib(&mut syms).unwrap();
assert_eq!(
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
.unwrap()
.to_string(),
result.to_string(),
);
}
#[test]
fn test_splitnt() {
let document = "(split 'one.two.three' '-')";
let result = "('one.two.three')";
let mut syms = SymTable::new();
static_stdlib(&mut syms).unwrap();
dynamic_stdlib(&mut syms).unwrap();
assert_eq!(
*eval(&lex(&document.to_string()).unwrap(), &mut syms)
.unwrap()
.to_string(),
result.to_string(),
);
}
}