1
0
dust/dust-lang/tests/unary_operations.rs

53 lines
1.3 KiB
Rust
Raw Normal View History

2024-11-05 16:33:56 -05:00
use dust_lang::*;
#[test]
fn negate() {
let source = "-(42)";
assert_eq!(
2024-11-06 15:40:37 -05:00
compile(source),
2024-11-05 16:33:56 -05:00
Ok(Chunk::with_data(
None,
2024-11-16 05:16:51 -05:00
FunctionType {
type_parameters: None,
value_parameters: None,
return_type: Type::Integer,
2024-11-16 05:16:51 -05:00
},
2024-11-05 16:33:56 -05:00
vec![
(Instruction::negate(0, Argument::Constant(0)), Span(0, 1)),
(Instruction::r#return(true), Span(5, 5)),
2024-11-05 16:33:56 -05:00
],
2024-11-16 01:29:21 -05:00
vec![ConcreteValue::Integer(42)],
2024-11-05 16:33:56 -05:00
vec![]
)),
);
assert_eq!(run(source), Ok(Some(ConcreteValue::Integer(-42))));
2024-11-05 16:33:56 -05:00
}
#[test]
fn not() {
let source = "!true";
assert_eq!(
2024-11-06 15:40:37 -05:00
compile(source),
2024-11-05 16:33:56 -05:00
Ok(Chunk::with_data(
None,
2024-11-16 05:16:51 -05:00
FunctionType {
type_parameters: None,
value_parameters: None,
return_type: Type::Boolean,
2024-11-16 05:16:51 -05:00
},
2024-11-05 16:33:56 -05:00
vec![
(Instruction::load_boolean(0, true, false), Span(1, 5)),
(Instruction::not(1, Argument::Register(0)), Span(0, 1)),
(Instruction::r#return(true), Span(5, 5)),
2024-11-05 16:33:56 -05:00
],
vec![],
vec![]
)),
);
assert_eq!(run(source), Ok(Some(ConcreteValue::Boolean(false))));
2024-11-05 16:33:56 -05:00
}