Add string concat/compare. Bump to 0.4
This commit is contained in:
@@ -1314,22 +1314,27 @@ impl Engine {
|
||||
fn or(x: bool, y: bool) -> bool {
|
||||
x || y
|
||||
}
|
||||
fn concat(x: String, y: String) -> String {
|
||||
x + &y
|
||||
}
|
||||
|
||||
reg_op!(engine, "+", add, i32, i64, u32, u64, f32, f64);
|
||||
reg_op!(engine, "-", sub, i32, i64, u32, u64, f32, f64);
|
||||
reg_op!(engine, "*", mul, i32, i64, u32, u64, f32, f64);
|
||||
reg_op!(engine, "/", div, i32, i64, u32, u64, f32, f64);
|
||||
|
||||
reg_cmp!(engine, "<", lt, i32, i64, u32, u64);
|
||||
reg_cmp!(engine, "<=", lte, i32, i64, u32, u64);
|
||||
reg_cmp!(engine, ">", gt, i32, i64, u32, u64);
|
||||
reg_cmp!(engine, ">=", gte, i32, i64, u32, u64);
|
||||
reg_cmp!(engine, "==", eq, i32, i64, u32, u64, bool);
|
||||
reg_cmp!(engine, "!=", ne, i32, i64, u32, u64, bool);
|
||||
reg_cmp!(engine, "<", lt, i32, i64, u32, u64, String);
|
||||
reg_cmp!(engine, "<=", lte, i32, i64, u32, u64, String);
|
||||
reg_cmp!(engine, ">", gt, i32, i64, u32, u64, String);
|
||||
reg_cmp!(engine, ">=", gte, i32, i64, u32, u64, String);
|
||||
reg_cmp!(engine, "==", eq, i32, i64, u32, u64, bool, String);
|
||||
reg_cmp!(engine, "!=", ne, i32, i64, u32, u64, bool, String);
|
||||
|
||||
reg_op!(engine, "||", or, bool);
|
||||
reg_op!(engine, "&&", and, bool);
|
||||
|
||||
engine.register_fn("+", concat);
|
||||
|
||||
// engine.register_fn("[]", idx);
|
||||
// FIXME? Registering array lookups are a special case because we want to return boxes
|
||||
// directly let ent = engine.fns.entry("[]".to_string()).or_insert(Vec::new());
|
||||
@@ -1676,6 +1681,12 @@ fn test_string() {
|
||||
} else {
|
||||
assert!(false);
|
||||
}
|
||||
|
||||
if let Ok(result) = engine.eval::<String>("\"foo\" + \"bar\"") {
|
||||
assert_eq!(result, "foobar");
|
||||
} else {
|
||||
assert!(false);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@@ -1,4 +1,3 @@
|
||||
use std::io::prelude::*;
|
||||
use std::error::Error;
|
||||
use std::fmt;
|
||||
use std::iter::Peekable;
|
||||
|
Reference in New Issue
Block a user