1
0
dust/tests/built_in_string_functions.rs

50 lines
1.0 KiB
Rust
Raw Normal View History

use dust_lang::{interpret, List, Value};
#[test]
fn as_bytes() {
let result = interpret("str:as_bytes('123')");
assert_eq!(
result,
Ok(Value::List(List::with_items(vec![
Value::Integer(49),
Value::Integer(50),
Value::Integer(51),
])))
);
}
2024-01-30 19:11:18 +00:00
#[test]
fn ends_with() {
let result = interpret("str:ends_with('abc', 'c')");
assert_eq!(result, Ok(Value::Boolean(true)));
let result = interpret("str:ends_with('abc', 'b')");
assert_eq!(result, Ok(Value::Boolean(false)));
}
#[test]
fn find() {
let result = interpret("str:find('abc', 'a')");
2024-02-15 15:33:25 +00:00
assert_eq!(result, Ok(Value::some(Value::Integer(0))));
2024-01-30 19:11:18 +00:00
let result = interpret("str:find('foobar', 'b')");
2024-02-15 15:33:25 +00:00
assert_eq!(result, Ok(Value::some(Value::Integer(3))));
2024-01-30 19:11:18 +00:00
}
#[test]
fn insert() {
assert_eq!(
interpret("str:insert('ac', 1, 'b')"),
Ok(Value::string("abc"))
2024-01-30 19:11:18 +00:00
);
assert_eq!(
interpret("str:insert('foo', 3, 'bar')"),
Ok(Value::string("foobar"))
2024-01-30 19:11:18 +00:00
);
}