Add support for character constants
This commit is contained in:
@@ -636,6 +636,7 @@ impl Engine {
|
||||
match *expr {
|
||||
Expr::IntConst(i) => Ok(Box::new(i)),
|
||||
Expr::StringConst(ref s) => Ok(Box::new(s.clone())),
|
||||
Expr::CharConst(ref c) => Ok(Box::new(c.clone())),
|
||||
Expr::Identifier(ref id) => {
|
||||
for &mut (ref name, ref mut val) in &mut scope.iter_mut().rev() {
|
||||
if *id == *name {
|
||||
@@ -1029,6 +1030,30 @@ fn test_number_literal() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_chars() {
|
||||
let mut engine = Engine::new();
|
||||
|
||||
if let Ok(result) = engine.eval::<char>("'y'") {
|
||||
assert_eq!(result, 'y');
|
||||
}
|
||||
else {
|
||||
assert!(false);
|
||||
}
|
||||
|
||||
if let Ok(result) = engine.eval::<char>("'\\u2764'") {
|
||||
assert_eq!(result, '❤');
|
||||
}
|
||||
else {
|
||||
assert!(false);
|
||||
}
|
||||
|
||||
match engine.eval::<char>("''") {
|
||||
Err(_) => (),
|
||||
_ => assert!(false)
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ops() {
|
||||
let mut engine = Engine::new();
|
||||
|
Reference in New Issue
Block a user