2018-06-13 10:56:29 +02:00
|
|
|
use rhai::Engine;
|
2017-11-03 17:58:51 +01:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_number_literal() {
|
|
|
|
let mut engine = Engine::new();
|
|
|
|
|
2019-10-09 13:06:32 +02:00
|
|
|
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();
|
|
|
|
|
2019-10-09 13:06:32 +02:00
|
|
|
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();
|
|
|
|
|
2019-10-09 13:06:32 +02:00
|
|
|
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();
|
|
|
|
|
2019-10-09 13:06:32 +02:00
|
|
|
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)
|
|
|
|
);
|
2018-06-13 10:56:29 +02:00
|
|
|
}
|