2024-12-03 19:00:27 +00:00
|
|
|
use dust_lang::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn divide_assign() {
|
|
|
|
let source = "let mut a = 2; a /= 2; a";
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
compile(source),
|
|
|
|
Ok(Chunk::with_data(
|
|
|
|
None,
|
|
|
|
FunctionType {
|
|
|
|
type_parameters: None,
|
|
|
|
value_parameters: None,
|
2024-12-10 08:34:41 +00:00
|
|
|
return_type: Type::Integer,
|
2024-12-03 19:00:27 +00:00
|
|
|
},
|
|
|
|
vec![
|
2024-12-10 08:34:41 +00:00
|
|
|
(Instruction::load_constant(0, 0, false), Span(12, 13)),
|
2024-12-03 19:00:27 +00:00
|
|
|
(
|
2024-12-10 08:34:41 +00:00
|
|
|
Instruction::divide(0, Argument::Register(0), Argument::Constant(0)),
|
2024-12-03 19:00:27 +00:00
|
|
|
Span(17, 19)
|
|
|
|
),
|
2024-12-10 08:34:41 +00:00
|
|
|
(Instruction::get_local(1, 0), Span(23, 24)),
|
2024-12-03 19:00:27 +00:00
|
|
|
(Instruction::r#return(true), Span(24, 24))
|
|
|
|
],
|
|
|
|
vec![ConcreteValue::Integer(2), ConcreteValue::string("a")],
|
2024-12-10 08:34:41 +00:00
|
|
|
vec![Local::new(1, 0, true, Scope::default())]
|
2024-12-03 19:00:27 +00:00
|
|
|
))
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(run(source), Ok(Some(ConcreteValue::Integer(1))));
|
|
|
|
}
|