2024-12-03 19:27:48 +00:00
|
|
|
use dust_lang::*;
|
|
|
|
|
2024-12-03 20:26:05 +00:00
|
|
|
#[test]
|
|
|
|
fn divide_bytes() {
|
|
|
|
let source = "0xff / 0x01";
|
|
|
|
|
|
|
|
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::Byte,
|
2024-12-03 20:26:05 +00:00
|
|
|
},
|
|
|
|
vec![
|
|
|
|
(
|
2024-12-10 08:34:41 +00:00
|
|
|
Instruction::divide(0, Argument::Constant(0), Argument::Constant(1)),
|
2024-12-03 22:11:02 +00:00
|
|
|
Span(5, 6)
|
2024-12-03 20:26:05 +00:00
|
|
|
),
|
|
|
|
(Instruction::r#return(true), Span(11, 11))
|
|
|
|
],
|
|
|
|
vec![ConcreteValue::Byte(0xff), ConcreteValue::Byte(0x01)],
|
|
|
|
vec![]
|
|
|
|
))
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(run(source), Ok(Some(ConcreteValue::Byte(0xff))));
|
|
|
|
}
|
|
|
|
|
2024-12-03 19:27:48 +00:00
|
|
|
#[test]
|
|
|
|
fn divide_floats() {
|
|
|
|
let source = "2.0 / 2.0";
|
|
|
|
|
|
|
|
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::Float,
|
2024-12-03 19:27:48 +00:00
|
|
|
},
|
|
|
|
vec![
|
|
|
|
(
|
2024-12-10 08:34:41 +00:00
|
|
|
Instruction::divide(0, Argument::Constant(0), Argument::Constant(0)),
|
2024-12-03 19:27:48 +00:00
|
|
|
Span(4, 5)
|
|
|
|
),
|
|
|
|
(Instruction::r#return(true), Span(9, 9))
|
|
|
|
],
|
|
|
|
vec![ConcreteValue::Float(2.0)],
|
|
|
|
vec![]
|
|
|
|
))
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(run(source), Ok(Some(ConcreteValue::Float(1.0))));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn divide_integers() {
|
|
|
|
let source = "2 / 2";
|
|
|
|
|
|
|
|
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:27:48 +00:00
|
|
|
},
|
|
|
|
vec![
|
|
|
|
(
|
2024-12-10 08:34:41 +00:00
|
|
|
Instruction::divide(0, Argument::Constant(0), Argument::Constant(0)),
|
2024-12-03 19:27:48 +00:00
|
|
|
Span(2, 3)
|
|
|
|
),
|
|
|
|
(Instruction::r#return(true), Span(5, 5))
|
|
|
|
],
|
|
|
|
vec![ConcreteValue::Integer(2)],
|
|
|
|
vec![]
|
|
|
|
))
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(run(source), Ok(Some(ConcreteValue::Integer(1))));
|
|
|
|
}
|