2024-11-05 21:33:56 +00:00
|
|
|
use dust_lang::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn negate() {
|
|
|
|
let source = "-(42)";
|
|
|
|
|
|
|
|
assert_eq!(
|
2024-11-06 20:40:37 +00:00
|
|
|
compile(source),
|
2024-11-05 21:33:56 +00:00
|
|
|
Ok(Chunk::with_data(
|
|
|
|
None,
|
|
|
|
vec![
|
|
|
|
(*Instruction::negate(0, 0).set_b_is_constant(), Span(0, 1)),
|
|
|
|
(Instruction::r#return(true), Span(5, 5)),
|
|
|
|
],
|
2024-11-16 06:29:21 +00:00
|
|
|
vec![ConcreteValue::Integer(42)],
|
2024-11-05 21:33:56 +00:00
|
|
|
vec![]
|
|
|
|
)),
|
|
|
|
);
|
|
|
|
|
2024-11-16 06:29:21 +00:00
|
|
|
assert_eq!(run(source), Ok(Some(ConcreteValue::Integer(-42))));
|
2024-11-05 21:33:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn not() {
|
|
|
|
let source = "!true";
|
|
|
|
|
|
|
|
assert_eq!(
|
2024-11-06 20:40:37 +00:00
|
|
|
compile(source),
|
2024-11-05 21:33:56 +00:00
|
|
|
Ok(Chunk::with_data(
|
|
|
|
None,
|
|
|
|
vec![
|
|
|
|
(Instruction::load_boolean(0, true, false), Span(1, 5)),
|
|
|
|
(Instruction::not(1, 0), Span(0, 1)),
|
|
|
|
(Instruction::r#return(true), Span(5, 5)),
|
|
|
|
],
|
|
|
|
vec![],
|
|
|
|
vec![]
|
|
|
|
)),
|
|
|
|
);
|
|
|
|
|
2024-11-16 06:29:21 +00:00
|
|
|
assert_eq!(run(source), Ok(Some(ConcreteValue::Boolean(false))));
|
2024-11-05 21:33:56 +00:00
|
|
|
}
|