Add if/else test
This commit is contained in:
parent
5b3232c723
commit
a1dd7e3bb9
@ -2,6 +2,36 @@ use crate::Local;
|
|||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn if_else_expression() {
|
||||||
|
let source = "if 1 == 1 { 2 } else { 3 }";
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
parse(source),
|
||||||
|
Ok(Chunk::with_data(
|
||||||
|
vec![
|
||||||
|
(
|
||||||
|
*Instruction::equal(true, 0, 1)
|
||||||
|
.set_first_argument_to_constant()
|
||||||
|
.set_second_argument_to_constant(),
|
||||||
|
Span(5, 7)
|
||||||
|
),
|
||||||
|
(Instruction::jump(1, true), Span(5, 7)),
|
||||||
|
(Instruction::load_constant(0, 2), Span(12, 13)),
|
||||||
|
(Instruction::load_constant(1, 3), Span(23, 24)),
|
||||||
|
(Instruction::r#return(), Span(0, 26)),
|
||||||
|
],
|
||||||
|
vec![
|
||||||
|
Value::integer(1),
|
||||||
|
Value::integer(1),
|
||||||
|
Value::integer(2),
|
||||||
|
Value::integer(3)
|
||||||
|
],
|
||||||
|
vec![]
|
||||||
|
)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn list_with_expression() {
|
fn list_with_expression() {
|
||||||
let source = "[1, 2 + 3, 4]";
|
let source = "[1, 2 + 3, 4]";
|
||||||
|
Loading…
Reference in New Issue
Block a user