rhai/tests/number_literals.rs

36 lines
789 B
Rust
Raw Normal View History

use rhai::Engine;
2017-11-03 17:58:51 +01:00
#[test]
fn test_number_literal() {
let mut engine = Engine::new();
assert_eq!(engine.eval::<i64>("65"), Ok(65));
2017-11-03 17:58:51 +01:00
}
#[test]
fn test_hex_literal() {
let mut engine = Engine::new();
assert_eq!(engine.eval::<i64>("let x = 0xf; x"), Ok(15));
assert_eq!(engine.eval::<i64>("let x = 0xff; x"), Ok(255));
2017-11-03 17:58:51 +01:00
}
#[test]
fn test_octal_literal() {
let mut engine = Engine::new();
assert_eq!(engine.eval::<i64>("let x = 0o77; x"), Ok(63));
assert_eq!(engine.eval::<i64>("let x = 0o1234; x"), Ok(668));
2017-11-03 17:58:51 +01:00
}
#[test]
fn test_binary_literal() {
let mut engine = Engine::new();
assert_eq!(engine.eval::<i64>("let x = 0b1111; x"), Ok(15));
assert_eq!(
engine.eval::<i64>("let x = 0b0011_1100_1010_0101; x"),
Ok(15525)
);
}