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

66 lines
1.7 KiB
Rust
Raw Normal View History

2024-12-03 19:27:48 +00:00
use dust_lang::*;
#[test]
fn multiply_floats() {
let source = "2.0 * 2.0";
assert_eq!(
compile(source),
Ok(Chunk::with_data(
None,
FunctionType {
type_parameters: None,
value_parameters: None,
return_type: Box::new(Type::Float),
},
vec![
(
Instruction::multiply(
Destination::Register(0),
Argument::Constant(0),
Argument::Constant(1)
),
Span(4, 5)
),
(Instruction::r#return(true), Span(9, 9)),
],
vec![ConcreteValue::Float(2.0), ConcreteValue::Float(2.0)],
vec![]
))
);
assert_eq!(run(source), Ok(Some(ConcreteValue::Float(4.0))));
}
#[test]
fn multiply_integers() {
let source = "1 * 2";
assert_eq!(
compile(source),
Ok(Chunk::with_data(
None,
FunctionType {
type_parameters: None,
value_parameters: None,
return_type: Box::new(Type::Integer),
},
vec![
(
Instruction::multiply(
Destination::Register(0),
Argument::Constant(0),
Argument::Constant(1)
),
Span(2, 3)
),
(Instruction::r#return(true), Span(5, 5)),
],
vec![ConcreteValue::Integer(1), ConcreteValue::Integer(2)],
vec![]
))
);
assert_eq!(run(source), Ok(Some(ConcreteValue::Integer(2))));
}