feat: basic string coercion
This commit is contained in:
parent
0af757fa27
commit
92b32ff2df
2 changed files with 13 additions and 0 deletions
10
src/env/core.rs
vendored
10
src/env/core.rs
vendored
|
@ -300,6 +300,16 @@ pub(super) fn core() -> HashMap<String, Node> {
|
|||
})
|
||||
}),
|
||||
),
|
||||
// Strings
|
||||
(
|
||||
"str",
|
||||
Node::NativeFunc(|_env, args| {
|
||||
arg_count!(1, args.len());
|
||||
|
||||
let val = args[0].borrow();
|
||||
Ok(Node::String(val.to_string()))
|
||||
}),
|
||||
),
|
||||
// IO
|
||||
(
|
||||
"display",
|
||||
|
|
|
@ -156,6 +156,9 @@ mod test {
|
|||
#[case("(>= 2 1)", "true")]
|
||||
#[case("(>= 1 1)", "true")]
|
||||
#[case("(>= 1 2)", "false")]
|
||||
// Strings
|
||||
#[case("(str (+ 1 2))", "3")]
|
||||
#[case("(str (list 1 2 3))", "(1 2 3)")]
|
||||
fn test_evaluator(#[case] input: &str, #[case] expected: &str) {
|
||||
let env = Environment::new();
|
||||
let ast = parser::parse_str(input).unwrap();
|
||||
|
|
Loading…
Reference in a new issue