2024-12-03 17:20:29 -05:00
|
|
|
use dust_lang::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn true_and_true() {
|
|
|
|
let source = "true && true";
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
compile(source),
|
2025-01-21 04:30:16 -05:00
|
|
|
Ok(Chunk {
|
|
|
|
name: None,
|
|
|
|
r#type: FunctionType {
|
2024-12-10 03:34:41 -05:00
|
|
|
return_type: Type::Boolean,
|
2025-01-21 04:30:16 -05:00
|
|
|
..FunctionType::default()
|
2024-12-03 17:20:29 -05:00
|
|
|
},
|
2025-01-21 04:30:16 -05:00
|
|
|
instructions: vec![
|
2024-12-18 14:57:29 -05:00
|
|
|
Instruction::load_boolean(0, true, false),
|
|
|
|
Instruction::test(0, true),
|
|
|
|
Instruction::jump(1, true),
|
|
|
|
Instruction::load_boolean(1, true, false),
|
2025-01-21 04:30:16 -05:00
|
|
|
Instruction::r#return(true, TypeCode::BOOLEAN, 1),
|
2024-12-03 17:20:29 -05:00
|
|
|
],
|
2025-01-21 04:30:16 -05:00
|
|
|
positions: vec![
|
2024-12-18 14:57:29 -05:00
|
|
|
Span(0, 4),
|
|
|
|
Span(5, 7),
|
|
|
|
Span(5, 7),
|
|
|
|
Span(8, 12),
|
|
|
|
Span(12, 12),
|
|
|
|
],
|
2025-01-21 04:30:16 -05:00
|
|
|
constants: ConstantTable::new(),
|
|
|
|
..Chunk::default()
|
|
|
|
})
|
2024-12-03 17:20:29 -05:00
|
|
|
);
|
|
|
|
|
2025-01-21 04:30:16 -05:00
|
|
|
assert_eq!(run(source), Ok(Some(Value::Boolean(true))));
|
2024-12-03 17:20:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn false_and_false() {
|
|
|
|
let source = "false && false";
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
compile(source),
|
2025-01-21 04:30:16 -05:00
|
|
|
Ok(Chunk {
|
|
|
|
name: None,
|
|
|
|
r#type: FunctionType {
|
2024-12-10 03:34:41 -05:00
|
|
|
return_type: Type::Boolean,
|
2025-01-21 04:30:16 -05:00
|
|
|
..FunctionType::default()
|
2024-12-03 17:20:29 -05:00
|
|
|
},
|
2025-01-21 04:30:16 -05:00
|
|
|
instructions: vec![
|
2024-12-18 14:57:29 -05:00
|
|
|
Instruction::load_boolean(0, false, false),
|
|
|
|
Instruction::test(0, true),
|
|
|
|
Instruction::jump(1, true),
|
|
|
|
Instruction::load_boolean(1, false, false),
|
2025-01-21 04:30:16 -05:00
|
|
|
Instruction::r#return(true, TypeCode::BOOLEAN, 1),
|
2024-12-18 14:57:29 -05:00
|
|
|
],
|
2025-01-21 04:30:16 -05:00
|
|
|
positions: vec![
|
2024-12-18 14:57:29 -05:00
|
|
|
Span(0, 5),
|
|
|
|
Span(6, 8),
|
|
|
|
Span(6, 8),
|
|
|
|
Span(9, 14),
|
|
|
|
Span(14, 14),
|
2024-12-03 17:20:29 -05:00
|
|
|
],
|
2025-01-21 04:30:16 -05:00
|
|
|
constants: ConstantTable::new(),
|
|
|
|
..Chunk::default()
|
|
|
|
})
|
2024-12-03 17:20:29 -05:00
|
|
|
);
|
|
|
|
|
2025-01-21 04:30:16 -05:00
|
|
|
assert_eq!(run(source), Ok(Some(Value::Boolean(false))));
|
2024-12-03 17:20:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn false_and_true() {
|
|
|
|
let source = "false && true";
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
compile(source),
|
2025-01-21 04:30:16 -05:00
|
|
|
Ok(Chunk {
|
|
|
|
name: None,
|
|
|
|
r#type: FunctionType {
|
2024-12-10 03:34:41 -05:00
|
|
|
return_type: Type::Boolean,
|
2025-01-21 04:30:16 -05:00
|
|
|
..FunctionType::default()
|
2024-12-03 17:20:29 -05:00
|
|
|
},
|
2025-01-21 04:30:16 -05:00
|
|
|
instructions: vec![
|
2024-12-18 14:57:29 -05:00
|
|
|
Instruction::load_boolean(0, false, false),
|
|
|
|
Instruction::test(0, true),
|
|
|
|
Instruction::jump(1, true),
|
|
|
|
Instruction::load_boolean(1, true, false),
|
2025-01-21 04:30:16 -05:00
|
|
|
Instruction::r#return(true, TypeCode::BOOLEAN, 1),
|
2024-12-03 17:20:29 -05:00
|
|
|
],
|
2025-01-21 04:30:16 -05:00
|
|
|
positions: vec![
|
2024-12-18 14:57:29 -05:00
|
|
|
Span(0, 5),
|
|
|
|
Span(6, 8),
|
|
|
|
Span(6, 8),
|
|
|
|
Span(9, 13),
|
2025-01-21 04:30:16 -05:00
|
|
|
Span(13, 13),
|
2024-12-18 14:57:29 -05:00
|
|
|
],
|
2025-01-21 04:30:16 -05:00
|
|
|
constants: ConstantTable::new(),
|
|
|
|
..Chunk::default()
|
|
|
|
})
|
2024-12-03 17:20:29 -05:00
|
|
|
);
|
|
|
|
|
2025-01-21 04:30:16 -05:00
|
|
|
assert_eq!(run(source), Ok(Some(Value::Boolean(false))));
|
2024-12-03 17:20:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn true_and_false() {
|
|
|
|
let source = "true && false";
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
compile(source),
|
2025-01-21 04:30:16 -05:00
|
|
|
Ok(Chunk {
|
|
|
|
name: None,
|
|
|
|
r#type: FunctionType {
|
2024-12-10 03:34:41 -05:00
|
|
|
return_type: Type::Boolean,
|
2025-01-21 04:30:16 -05:00
|
|
|
..FunctionType::default()
|
2024-12-03 17:20:29 -05:00
|
|
|
},
|
2025-01-21 04:30:16 -05:00
|
|
|
instructions: vec![
|
2024-12-18 14:57:29 -05:00
|
|
|
Instruction::load_boolean(0, true, false),
|
|
|
|
Instruction::test(0, true),
|
|
|
|
Instruction::jump(1, true),
|
|
|
|
Instruction::load_boolean(1, false, false),
|
2025-01-21 04:30:16 -05:00
|
|
|
Instruction::r#return(true, TypeCode::BOOLEAN, 1),
|
2024-12-18 14:57:29 -05:00
|
|
|
],
|
2025-01-21 04:30:16 -05:00
|
|
|
positions: vec![
|
2024-12-18 14:57:29 -05:00
|
|
|
Span(0, 4),
|
2025-01-21 04:30:16 -05:00
|
|
|
Span(5, 8),
|
|
|
|
Span(5, 8),
|
|
|
|
Span(9, 14),
|
|
|
|
Span(14, 14),
|
2024-12-03 17:20:29 -05:00
|
|
|
],
|
2025-01-21 04:30:16 -05:00
|
|
|
constants: ConstantTable::new(),
|
|
|
|
..Chunk::default()
|
|
|
|
})
|
2024-12-03 17:20:29 -05:00
|
|
|
);
|
|
|
|
|
2025-01-21 04:30:16 -05:00
|
|
|
assert_eq!(run(source), Ok(Some(Value::Boolean(false))));
|
2024-12-03 17:20:29 -05:00
|
|
|
}
|