2024-11-01 00:33:46 +00:00
|
|
|
use dust_lang::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn equal() {
|
|
|
|
let source = "1 == 2";
|
|
|
|
|
|
|
|
assert_eq!(
|
2024-11-06 20:40:37 +00:00
|
|
|
compile(source),
|
2024-11-01 00:33:46 +00:00
|
|
|
Ok(Chunk::with_data(
|
|
|
|
None,
|
2024-11-16 10:16:51 +00:00
|
|
|
FunctionType {
|
|
|
|
type_parameters: None,
|
|
|
|
value_parameters: None,
|
2024-12-10 08:34:41 +00:00
|
|
|
return_type: Type::Boolean
|
2024-11-16 10:16:51 +00:00
|
|
|
},
|
2024-11-01 00:33:46 +00:00
|
|
|
vec![
|
|
|
|
(
|
2024-12-10 08:34:41 +00:00
|
|
|
Instruction::equal(0, true, Argument::Constant(0), Argument::Constant(1)),
|
2024-11-28 02:13:35 +00:00
|
|
|
Span(2, 4)
|
|
|
|
),
|
2024-12-02 10:59:01 +00:00
|
|
|
(Instruction::r#return(true), Span(6, 6)),
|
2024-11-01 00:33:46 +00:00
|
|
|
],
|
2024-11-16 06:29:21 +00:00
|
|
|
vec![ConcreteValue::Integer(1), ConcreteValue::Integer(2)],
|
2024-11-01 00:33:46 +00:00
|
|
|
vec![]
|
|
|
|
)),
|
|
|
|
);
|
|
|
|
|
2024-11-28 00:43:50 +00:00
|
|
|
assert_eq!(run(source), Ok(Some(ConcreteValue::Boolean(false))));
|
2024-11-01 00:33:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn greater() {
|
|
|
|
let source = "1 > 2";
|
|
|
|
|
|
|
|
assert_eq!(
|
2024-11-06 20:40:37 +00:00
|
|
|
compile(source),
|
2024-11-01 00:33:46 +00:00
|
|
|
Ok(Chunk::with_data(
|
|
|
|
None,
|
2024-11-16 10:16:51 +00:00
|
|
|
FunctionType {
|
|
|
|
type_parameters: None,
|
|
|
|
value_parameters: None,
|
2024-12-10 08:34:41 +00:00
|
|
|
return_type: Type::Boolean
|
2024-11-16 10:16:51 +00:00
|
|
|
},
|
2024-11-01 00:33:46 +00:00
|
|
|
vec![
|
|
|
|
(
|
2024-12-10 08:34:41 +00:00
|
|
|
Instruction::less_equal(0, false, Argument::Constant(0), Argument::Constant(1)),
|
2024-11-28 02:13:35 +00:00
|
|
|
Span(2, 3)
|
|
|
|
),
|
2024-12-02 10:59:01 +00:00
|
|
|
(Instruction::r#return(true), Span(5, 5)),
|
2024-11-01 00:33:46 +00:00
|
|
|
],
|
2024-11-16 06:29:21 +00:00
|
|
|
vec![ConcreteValue::Integer(1), ConcreteValue::Integer(2)],
|
2024-11-01 00:33:46 +00:00
|
|
|
vec![]
|
|
|
|
)),
|
|
|
|
);
|
|
|
|
|
2024-11-28 00:43:50 +00:00
|
|
|
assert_eq!(run(source), Ok(Some(ConcreteValue::Boolean(false))));
|
2024-11-01 00:33:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn greater_than_or_equal() {
|
|
|
|
let source = "1 >= 2";
|
|
|
|
|
|
|
|
assert_eq!(
|
2024-11-06 20:40:37 +00:00
|
|
|
compile(source),
|
2024-11-01 00:33:46 +00:00
|
|
|
Ok(Chunk::with_data(
|
|
|
|
None,
|
2024-11-16 10:16:51 +00:00
|
|
|
FunctionType {
|
|
|
|
type_parameters: None,
|
|
|
|
value_parameters: None,
|
2024-12-10 08:34:41 +00:00
|
|
|
return_type: Type::Boolean
|
2024-11-16 10:16:51 +00:00
|
|
|
},
|
2024-11-01 00:33:46 +00:00
|
|
|
vec![
|
|
|
|
(
|
2024-12-10 08:34:41 +00:00
|
|
|
Instruction::less(0, false, Argument::Constant(0), Argument::Constant(1)),
|
2024-11-01 00:33:46 +00:00
|
|
|
Span(2, 4)
|
|
|
|
),
|
2024-12-02 10:59:01 +00:00
|
|
|
(Instruction::r#return(true), Span(6, 6)),
|
2024-11-01 00:33:46 +00:00
|
|
|
],
|
2024-11-16 06:29:21 +00:00
|
|
|
vec![ConcreteValue::Integer(1), ConcreteValue::Integer(2)],
|
2024-11-01 00:33:46 +00:00
|
|
|
vec![]
|
|
|
|
)),
|
|
|
|
);
|
|
|
|
|
2024-11-28 00:43:50 +00:00
|
|
|
assert_eq!(run(source), Ok(Some(ConcreteValue::Boolean(false))));
|
2024-11-01 00:33:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn less_than() {
|
|
|
|
let source = "1 < 2";
|
|
|
|
|
|
|
|
assert_eq!(
|
2024-11-06 20:40:37 +00:00
|
|
|
compile(source),
|
2024-11-01 00:33:46 +00:00
|
|
|
Ok(Chunk::with_data(
|
|
|
|
None,
|
2024-11-16 10:16:51 +00:00
|
|
|
FunctionType {
|
|
|
|
type_parameters: None,
|
|
|
|
value_parameters: None,
|
2024-12-10 08:34:41 +00:00
|
|
|
return_type: Type::Boolean
|
2024-11-16 10:16:51 +00:00
|
|
|
},
|
2024-11-01 00:33:46 +00:00
|
|
|
vec![
|
|
|
|
(
|
2024-12-10 08:34:41 +00:00
|
|
|
Instruction::less(0, true, Argument::Constant(0), Argument::Constant(1)),
|
2024-11-28 02:13:35 +00:00
|
|
|
Span(2, 3)
|
|
|
|
),
|
2024-12-02 10:59:01 +00:00
|
|
|
(Instruction::r#return(true), Span(5, 5)),
|
2024-11-01 00:33:46 +00:00
|
|
|
],
|
2024-11-16 06:29:21 +00:00
|
|
|
vec![ConcreteValue::Integer(1), ConcreteValue::Integer(2)],
|
2024-11-01 00:33:46 +00:00
|
|
|
vec![]
|
|
|
|
)),
|
|
|
|
);
|
|
|
|
|
2024-11-28 00:43:50 +00:00
|
|
|
assert_eq!(run(source), Ok(Some(ConcreteValue::Boolean(true))));
|
2024-11-01 00:33:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn less_than_or_equal() {
|
|
|
|
let source = "1 <= 2";
|
|
|
|
|
|
|
|
assert_eq!(
|
2024-11-06 20:40:37 +00:00
|
|
|
compile(source),
|
2024-11-01 00:33:46 +00:00
|
|
|
Ok(Chunk::with_data(
|
|
|
|
None,
|
2024-11-16 10:16:51 +00:00
|
|
|
FunctionType {
|
|
|
|
type_parameters: None,
|
|
|
|
value_parameters: None,
|
2024-12-10 08:34:41 +00:00
|
|
|
return_type: Type::Boolean
|
2024-11-16 10:16:51 +00:00
|
|
|
},
|
2024-11-01 00:33:46 +00:00
|
|
|
vec![
|
|
|
|
(
|
2024-12-10 08:34:41 +00:00
|
|
|
Instruction::less_equal(0, true, Argument::Constant(0), Argument::Constant(1)),
|
2024-11-28 02:13:35 +00:00
|
|
|
Span(2, 4)
|
|
|
|
),
|
2024-12-02 10:59:01 +00:00
|
|
|
(Instruction::r#return(true), Span(6, 6)),
|
2024-11-01 00:33:46 +00:00
|
|
|
],
|
2024-11-16 06:29:21 +00:00
|
|
|
vec![ConcreteValue::Integer(1), ConcreteValue::Integer(2)],
|
2024-11-01 00:33:46 +00:00
|
|
|
vec![]
|
|
|
|
)),
|
|
|
|
);
|
|
|
|
|
2024-11-28 00:43:50 +00:00
|
|
|
assert_eq!(run(source), Ok(Some(ConcreteValue::Boolean(true))));
|
2024-11-01 00:33:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn not_equal() {
|
|
|
|
let source = "1 != 2";
|
|
|
|
|
|
|
|
assert_eq!(
|
2024-11-06 20:40:37 +00:00
|
|
|
compile(source),
|
2024-11-01 00:33:46 +00:00
|
|
|
Ok(Chunk::with_data(
|
|
|
|
None,
|
2024-11-16 10:16:51 +00:00
|
|
|
FunctionType {
|
|
|
|
type_parameters: None,
|
|
|
|
value_parameters: None,
|
2024-12-10 08:34:41 +00:00
|
|
|
return_type: Type::Boolean
|
2024-11-16 10:16:51 +00:00
|
|
|
},
|
2024-11-01 00:33:46 +00:00
|
|
|
vec![
|
|
|
|
(
|
2024-12-10 08:34:41 +00:00
|
|
|
Instruction::equal(0, false, Argument::Constant(0), Argument::Constant(1)),
|
2024-11-01 00:33:46 +00:00
|
|
|
Span(2, 4)
|
|
|
|
),
|
2024-12-02 10:59:01 +00:00
|
|
|
(Instruction::r#return(true), Span(6, 6)),
|
2024-11-01 00:33:46 +00:00
|
|
|
],
|
2024-11-16 06:29:21 +00:00
|
|
|
vec![ConcreteValue::Integer(1), ConcreteValue::Integer(2)],
|
2024-11-01 00:33:46 +00:00
|
|
|
vec![]
|
|
|
|
)),
|
|
|
|
);
|
|
|
|
|
2024-11-28 00:43:50 +00:00
|
|
|
assert_eq!(run(source), Ok(Some(ConcreteValue::Boolean(true))));
|
2024-11-01 00:33:46 +00:00
|
|
|
}
|