removed debug variant macro
This commit is contained in:
@@ -3,7 +3,7 @@ use pretty_assertions::assert_eq;
|
||||
|
||||
#[test]
|
||||
fn test_function_declaration_with_spillover_params() -> anyhow::Result<()> {
|
||||
let compiled = compile!(debug r#"
|
||||
let compiled = compile!(check r#"
|
||||
// we need more than 4 params to 'spill' into a stack var
|
||||
fn doSomething(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) {
|
||||
return arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7 + arg8 + arg9;
|
||||
@@ -13,8 +13,14 @@ fn test_function_declaration_with_spillover_params() -> anyhow::Result<()> {
|
||||
let returned = doSomething(item1, 2, 3, 4, 5, 6, 7, 8, 9);
|
||||
"#);
|
||||
|
||||
assert!(
|
||||
compiled.errors.is_empty(),
|
||||
"Expected no errors, got: {:?}",
|
||||
compiled.errors
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
compiled,
|
||||
compiled.output,
|
||||
indoc! {"
|
||||
j main
|
||||
doSomething:
|
||||
@@ -67,7 +73,7 @@ fn test_function_declaration_with_spillover_params() -> anyhow::Result<()> {
|
||||
|
||||
#[test]
|
||||
fn test_early_return() -> anyhow::Result<()> {
|
||||
let compiled = compile!(debug r#"
|
||||
let compiled = compile!(check r#"
|
||||
// This is a test function declaration with no body
|
||||
fn doSomething() {
|
||||
if (1 == 1) {
|
||||
@@ -79,8 +85,14 @@ fn test_early_return() -> anyhow::Result<()> {
|
||||
doSomething();
|
||||
"#);
|
||||
|
||||
assert!(
|
||||
compiled.errors.is_empty(),
|
||||
"Expected no errors, got: {:?}",
|
||||
compiled.errors
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
compiled,
|
||||
compiled.output,
|
||||
indoc! {
|
||||
"
|
||||
j main
|
||||
@@ -107,14 +119,20 @@ fn test_early_return() -> anyhow::Result<()> {
|
||||
|
||||
#[test]
|
||||
fn test_function_declaration_with_register_params() -> anyhow::Result<()> {
|
||||
let compiled = compile!(debug r#"
|
||||
let compiled = compile!(check r#"
|
||||
// This is a test function declaration with no body
|
||||
fn doSomething(arg1, arg2) {
|
||||
};
|
||||
"#);
|
||||
|
||||
assert!(
|
||||
compiled.errors.is_empty(),
|
||||
"Expected no errors, got: {:?}",
|
||||
compiled.errors
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
compiled,
|
||||
compiled.output,
|
||||
indoc! {"
|
||||
j main
|
||||
doSomething:
|
||||
|
||||
@@ -33,17 +33,6 @@ macro_rules! compile {
|
||||
compiler.compile().errors
|
||||
}};
|
||||
|
||||
(debug $source:expr) => {{
|
||||
let mut writer = std::io::BufWriter::new(Vec::new());
|
||||
let compiler = crate::Compiler::new(
|
||||
parser::Parser::new(tokenizer::Tokenizer::from($source)),
|
||||
Some(crate::CompilerConfig { debug: true }),
|
||||
);
|
||||
let res = compiler.compile();
|
||||
res.instructions.write(&mut writer)?;
|
||||
output!(writer)
|
||||
}};
|
||||
|
||||
(check $source:expr) => {{
|
||||
let mut writer = std::io::BufWriter::new(Vec::new());
|
||||
let compiler = crate::Compiler::new(
|
||||
|
||||
@@ -4,7 +4,7 @@ use pretty_assertions::assert_eq;
|
||||
#[test]
|
||||
fn block_scope() -> anyhow::Result<()> {
|
||||
let compiled = compile! {
|
||||
debug "
|
||||
check "
|
||||
let x = 10;
|
||||
{
|
||||
let y = 20;
|
||||
@@ -13,8 +13,14 @@ fn block_scope() -> anyhow::Result<()> {
|
||||
"
|
||||
};
|
||||
|
||||
assert!(
|
||||
compiled.errors.is_empty(),
|
||||
"Expected no errors, got: {:?}",
|
||||
compiled.errors
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
compiled,
|
||||
compiled.output,
|
||||
indoc! {
|
||||
"
|
||||
j main
|
||||
@@ -33,7 +39,7 @@ fn block_scope() -> anyhow::Result<()> {
|
||||
#[test]
|
||||
fn variable_scope_isolation() -> anyhow::Result<()> {
|
||||
let compiled = compile! {
|
||||
debug "
|
||||
check "
|
||||
let x = 10;
|
||||
{
|
||||
let x = 20;
|
||||
@@ -42,8 +48,14 @@ fn variable_scope_isolation() -> anyhow::Result<()> {
|
||||
"
|
||||
};
|
||||
|
||||
assert!(
|
||||
compiled.errors.is_empty(),
|
||||
"Expected no errors, got: {:?}",
|
||||
compiled.errors
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
compiled,
|
||||
compiled.output,
|
||||
indoc! {
|
||||
"
|
||||
j main
|
||||
@@ -61,7 +73,7 @@ fn variable_scope_isolation() -> anyhow::Result<()> {
|
||||
#[test]
|
||||
fn function_parameter_scope() -> anyhow::Result<()> {
|
||||
let compiled = compile! {
|
||||
debug "
|
||||
check "
|
||||
fn double(x) {
|
||||
return x * 2;
|
||||
};
|
||||
@@ -70,8 +82,14 @@ fn function_parameter_scope() -> anyhow::Result<()> {
|
||||
"
|
||||
};
|
||||
|
||||
assert!(
|
||||
compiled.errors.is_empty(),
|
||||
"Expected no errors, got: {:?}",
|
||||
compiled.errors
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
compiled,
|
||||
compiled.output,
|
||||
indoc! {
|
||||
"
|
||||
j main
|
||||
@@ -95,52 +113,10 @@ fn function_parameter_scope() -> anyhow::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn function_local_variables() -> anyhow::Result<()> {
|
||||
let compiled = compile! {
|
||||
debug "
|
||||
let global = 100;
|
||||
|
||||
fn test() {
|
||||
let local = 50;
|
||||
return local + global;
|
||||
};
|
||||
|
||||
let result = test();
|
||||
"
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
compiled,
|
||||
indoc! {
|
||||
"
|
||||
j main
|
||||
test:
|
||||
push ra
|
||||
move r8 50
|
||||
add r1 r8 r0
|
||||
move r15 r1
|
||||
j __internal_L1
|
||||
__internal_L1:
|
||||
pop ra
|
||||
j ra
|
||||
main:
|
||||
move r8 100
|
||||
push r8
|
||||
jal test
|
||||
pop r8
|
||||
move r9 r15
|
||||
"
|
||||
}
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nested_block_scopes() -> anyhow::Result<()> {
|
||||
let compiled = compile! {
|
||||
debug "
|
||||
check "
|
||||
let x = 1;
|
||||
{
|
||||
let x = 2;
|
||||
@@ -154,8 +130,14 @@ fn nested_block_scopes() -> anyhow::Result<()> {
|
||||
"
|
||||
};
|
||||
|
||||
assert!(
|
||||
compiled.errors.is_empty(),
|
||||
"Expected no errors, got: {:?}",
|
||||
compiled.errors
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
compiled,
|
||||
compiled.output,
|
||||
indoc! {
|
||||
"
|
||||
j main
|
||||
@@ -176,7 +158,7 @@ fn nested_block_scopes() -> anyhow::Result<()> {
|
||||
#[test]
|
||||
fn variable_shadowing_in_conditional() -> anyhow::Result<()> {
|
||||
let compiled = compile! {
|
||||
debug "
|
||||
check "
|
||||
let x = 10;
|
||||
|
||||
if (true) {
|
||||
@@ -187,8 +169,14 @@ fn variable_shadowing_in_conditional() -> anyhow::Result<()> {
|
||||
"
|
||||
};
|
||||
|
||||
assert!(
|
||||
compiled.errors.is_empty(),
|
||||
"Expected no errors, got: {:?}",
|
||||
compiled.errors
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
compiled,
|
||||
compiled.output,
|
||||
indoc! {
|
||||
"
|
||||
j main
|
||||
@@ -208,7 +196,7 @@ fn variable_shadowing_in_conditional() -> anyhow::Result<()> {
|
||||
#[test]
|
||||
fn variable_shadowing_in_loop() -> anyhow::Result<()> {
|
||||
let compiled = compile! {
|
||||
debug "
|
||||
check "
|
||||
let x = 0;
|
||||
|
||||
loop {
|
||||
@@ -220,8 +208,14 @@ fn variable_shadowing_in_loop() -> anyhow::Result<()> {
|
||||
"
|
||||
};
|
||||
|
||||
assert!(
|
||||
compiled.errors.is_empty(),
|
||||
"Expected no errors, got: {:?}",
|
||||
compiled.errors
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
compiled,
|
||||
compiled.output,
|
||||
indoc! {
|
||||
"
|
||||
j main
|
||||
@@ -246,7 +240,7 @@ fn variable_shadowing_in_loop() -> anyhow::Result<()> {
|
||||
#[test]
|
||||
fn const_scope() -> anyhow::Result<()> {
|
||||
let compiled = compile! {
|
||||
debug "
|
||||
check "
|
||||
const PI = 3.14;
|
||||
|
||||
{
|
||||
@@ -256,8 +250,14 @@ fn const_scope() -> anyhow::Result<()> {
|
||||
"
|
||||
};
|
||||
|
||||
assert!(
|
||||
compiled.errors.is_empty(),
|
||||
"Expected no errors, got: {:?}",
|
||||
compiled.errors
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
compiled,
|
||||
compiled.output,
|
||||
indoc! {
|
||||
"
|
||||
j main
|
||||
@@ -273,7 +273,7 @@ fn const_scope() -> anyhow::Result<()> {
|
||||
#[test]
|
||||
fn device_in_scope() -> anyhow::Result<()> {
|
||||
let compiled = compile! {
|
||||
debug "
|
||||
check "
|
||||
device d0 = \"d0\";
|
||||
|
||||
{
|
||||
@@ -282,8 +282,14 @@ fn device_in_scope() -> anyhow::Result<()> {
|
||||
"
|
||||
};
|
||||
|
||||
assert!(
|
||||
compiled.errors.is_empty(),
|
||||
"Expected no errors, got: {:?}",
|
||||
compiled.errors
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
compiled,
|
||||
compiled.output,
|
||||
indoc! {
|
||||
"
|
||||
j main
|
||||
@@ -300,7 +306,7 @@ fn device_in_scope() -> anyhow::Result<()> {
|
||||
#[test]
|
||||
fn function_scope_isolation() -> anyhow::Result<()> {
|
||||
let compiled = compile! {
|
||||
debug "
|
||||
check "
|
||||
fn func1() {
|
||||
let x = 10;
|
||||
return x;
|
||||
@@ -316,8 +322,14 @@ fn function_scope_isolation() -> anyhow::Result<()> {
|
||||
"
|
||||
};
|
||||
|
||||
assert!(
|
||||
compiled.errors.is_empty(),
|
||||
"Expected no errors, got: {:?}",
|
||||
compiled.errors
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
compiled,
|
||||
compiled.output,
|
||||
indoc! {
|
||||
"
|
||||
j main
|
||||
@@ -354,7 +366,7 @@ fn function_scope_isolation() -> anyhow::Result<()> {
|
||||
#[test]
|
||||
fn tuple_unpacking_scope() -> anyhow::Result<()> {
|
||||
let compiled = compile! {
|
||||
debug "
|
||||
check "
|
||||
fn pair() {
|
||||
return (1, 2);
|
||||
};
|
||||
@@ -366,8 +378,14 @@ fn tuple_unpacking_scope() -> anyhow::Result<()> {
|
||||
"
|
||||
};
|
||||
|
||||
assert!(
|
||||
compiled.errors.is_empty(),
|
||||
"Expected no errors, got: {:?}",
|
||||
compiled.errors
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
compiled,
|
||||
compiled.output,
|
||||
indoc! {
|
||||
"
|
||||
j main
|
||||
@@ -397,7 +415,7 @@ fn tuple_unpacking_scope() -> anyhow::Result<()> {
|
||||
#[test]
|
||||
fn shadowing_doesnt_affect_outer() -> anyhow::Result<()> {
|
||||
let compiled = compile! {
|
||||
debug "
|
||||
check "
|
||||
let x = 5;
|
||||
let y = x;
|
||||
{
|
||||
@@ -408,8 +426,14 @@ fn shadowing_doesnt_affect_outer() -> anyhow::Result<()> {
|
||||
"
|
||||
};
|
||||
|
||||
assert!(
|
||||
compiled.errors.is_empty(),
|
||||
"Expected no errors, got: {:?}",
|
||||
compiled.errors
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
compiled,
|
||||
compiled.output,
|
||||
indoc! {
|
||||
"
|
||||
j main
|
||||
|
||||
@@ -6,14 +6,20 @@ mod test {
|
||||
#[test]
|
||||
fn test_tuple_literal_declaration() -> anyhow::Result<()> {
|
||||
let compiled = compile!(
|
||||
debug
|
||||
check
|
||||
r#"
|
||||
let (x, y) = (1, 2);
|
||||
"#
|
||||
);
|
||||
|
||||
assert!(
|
||||
compiled.errors.is_empty(),
|
||||
"Expected no errors, got: {:?}",
|
||||
compiled.errors
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
compiled,
|
||||
compiled.output,
|
||||
indoc! {
|
||||
"
|
||||
j main
|
||||
@@ -30,14 +36,20 @@ mod test {
|
||||
#[test]
|
||||
fn test_tuple_literal_declaration_with_underscore() -> anyhow::Result<()> {
|
||||
let compiled = compile!(
|
||||
debug
|
||||
check
|
||||
r#"
|
||||
let (x, _) = (1, 2);
|
||||
"#
|
||||
);
|
||||
|
||||
assert!(
|
||||
compiled.errors.is_empty(),
|
||||
"Expected no errors, got: {:?}",
|
||||
compiled.errors
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
compiled,
|
||||
compiled.output,
|
||||
indoc! {
|
||||
"
|
||||
j main
|
||||
@@ -53,7 +65,7 @@ mod test {
|
||||
#[test]
|
||||
fn test_tuple_literal_assignment() -> anyhow::Result<()> {
|
||||
let compiled = compile!(
|
||||
debug
|
||||
check
|
||||
r#"
|
||||
let x = 0;
|
||||
let y = 0;
|
||||
@@ -61,8 +73,14 @@ mod test {
|
||||
"#
|
||||
);
|
||||
|
||||
assert!(
|
||||
compiled.errors.is_empty(),
|
||||
"Expected no errors, got: {:?}",
|
||||
compiled.errors
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
compiled,
|
||||
compiled.output,
|
||||
indoc! {
|
||||
"
|
||||
j main
|
||||
@@ -81,7 +99,7 @@ mod test {
|
||||
#[test]
|
||||
fn test_tuple_literal_with_variables() -> anyhow::Result<()> {
|
||||
let compiled = compile!(
|
||||
debug
|
||||
check
|
||||
r#"
|
||||
let a = 42;
|
||||
let b = 99;
|
||||
@@ -89,8 +107,14 @@ mod test {
|
||||
"#
|
||||
);
|
||||
|
||||
assert!(
|
||||
compiled.errors.is_empty(),
|
||||
"Expected no errors, got: {:?}",
|
||||
compiled.errors
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
compiled,
|
||||
compiled.output,
|
||||
indoc! {
|
||||
"
|
||||
j main
|
||||
@@ -109,14 +133,20 @@ mod test {
|
||||
#[test]
|
||||
fn test_tuple_literal_three_elements() -> anyhow::Result<()> {
|
||||
let compiled = compile!(
|
||||
debug
|
||||
check
|
||||
r#"
|
||||
let (x, y, z) = (1, 2, 3);
|
||||
"#
|
||||
);
|
||||
|
||||
assert!(
|
||||
compiled.errors.is_empty(),
|
||||
"Expected no errors, got: {:?}",
|
||||
compiled.errors
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
compiled,
|
||||
compiled.output,
|
||||
indoc! {
|
||||
"
|
||||
j main
|
||||
@@ -134,7 +164,7 @@ mod test {
|
||||
#[test]
|
||||
fn test_tuple_literal_assignment_with_underscore() -> anyhow::Result<()> {
|
||||
let compiled = compile!(
|
||||
debug
|
||||
check
|
||||
r#"
|
||||
let i = 0;
|
||||
let x = 123;
|
||||
@@ -142,8 +172,14 @@ mod test {
|
||||
"#
|
||||
);
|
||||
|
||||
assert!(
|
||||
compiled.errors.is_empty(),
|
||||
"Expected no errors, got: {:?}",
|
||||
compiled.errors
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
compiled,
|
||||
compiled.output,
|
||||
indoc! {
|
||||
"
|
||||
j main
|
||||
@@ -161,7 +197,7 @@ mod test {
|
||||
#[test]
|
||||
fn test_tuple_return_simple() -> anyhow::Result<()> {
|
||||
let compiled = compile!(
|
||||
debug
|
||||
check
|
||||
r#"
|
||||
fn getPair() {
|
||||
return (10, 20);
|
||||
@@ -170,8 +206,14 @@ mod test {
|
||||
"#
|
||||
);
|
||||
|
||||
assert!(
|
||||
compiled.errors.is_empty(),
|
||||
"Expected no errors, got: {:?}",
|
||||
compiled.errors
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
compiled,
|
||||
compiled.output,
|
||||
indoc! {
|
||||
"
|
||||
j main
|
||||
@@ -199,7 +241,7 @@ mod test {
|
||||
#[test]
|
||||
fn test_tuple_return_with_underscore() -> anyhow::Result<()> {
|
||||
let compiled = compile!(
|
||||
debug
|
||||
check
|
||||
r#"
|
||||
fn getPair() {
|
||||
return (5, 15);
|
||||
@@ -208,8 +250,14 @@ mod test {
|
||||
"#
|
||||
);
|
||||
|
||||
assert!(
|
||||
compiled.errors.is_empty(),
|
||||
"Expected no errors, got: {:?}",
|
||||
compiled.errors
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
compiled,
|
||||
compiled.output,
|
||||
indoc! {
|
||||
"
|
||||
j main
|
||||
@@ -237,7 +285,7 @@ mod test {
|
||||
#[test]
|
||||
fn test_tuple_return_three_elements() -> anyhow::Result<()> {
|
||||
let compiled = compile!(
|
||||
debug
|
||||
check
|
||||
r#"
|
||||
fn getTriple() {
|
||||
return (1, 2, 3);
|
||||
@@ -246,8 +294,14 @@ mod test {
|
||||
"#
|
||||
);
|
||||
|
||||
assert!(
|
||||
compiled.errors.is_empty(),
|
||||
"Expected no errors, got: {:?}",
|
||||
compiled.errors
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
compiled,
|
||||
compiled.output,
|
||||
indoc! {
|
||||
"
|
||||
j main
|
||||
@@ -277,7 +331,7 @@ mod test {
|
||||
#[test]
|
||||
fn test_tuple_return_assignment() -> anyhow::Result<()> {
|
||||
let compiled = compile!(
|
||||
debug
|
||||
check
|
||||
r#"
|
||||
fn getPair() {
|
||||
return (42, 84);
|
||||
@@ -288,8 +342,14 @@ mod test {
|
||||
"#
|
||||
);
|
||||
|
||||
assert!(
|
||||
compiled.errors.is_empty(),
|
||||
"Expected no errors, got: {:?}",
|
||||
compiled.errors
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
compiled,
|
||||
compiled.output,
|
||||
indoc! {
|
||||
"
|
||||
j main
|
||||
@@ -346,7 +406,7 @@ mod test {
|
||||
#[test]
|
||||
fn test_tuple_return_called_by_non_tuple_return() -> anyhow::Result<()> {
|
||||
let compiled = compile!(
|
||||
debug
|
||||
check
|
||||
r#"
|
||||
fn doSomething() {
|
||||
return (1, 2);
|
||||
@@ -361,8 +421,14 @@ mod test {
|
||||
"#
|
||||
);
|
||||
|
||||
assert!(
|
||||
compiled.errors.is_empty(),
|
||||
"Expected no errors, got: {:?}",
|
||||
compiled.errors
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
compiled,
|
||||
compiled.output,
|
||||
indoc! {
|
||||
"
|
||||
j main
|
||||
@@ -399,7 +465,7 @@ mod test {
|
||||
#[test]
|
||||
fn test_non_tuple_return_called_by_tuple_return() -> anyhow::Result<()> {
|
||||
let compiled = compile!(
|
||||
debug
|
||||
check
|
||||
r#"
|
||||
fn getValue() {
|
||||
return 42;
|
||||
@@ -414,8 +480,14 @@ mod test {
|
||||
"#
|
||||
);
|
||||
|
||||
assert!(
|
||||
compiled.errors.is_empty(),
|
||||
"Expected no errors, got: {:?}",
|
||||
compiled.errors
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
compiled,
|
||||
compiled.output,
|
||||
indoc! {
|
||||
"
|
||||
j main
|
||||
@@ -471,7 +543,7 @@ mod test {
|
||||
#[test]
|
||||
fn test_multiple_tuple_returns_in_function() -> anyhow::Result<()> {
|
||||
let compiled = compile!(
|
||||
debug
|
||||
check
|
||||
r#"
|
||||
fn getValue(x) {
|
||||
if (x) {
|
||||
@@ -485,8 +557,14 @@ mod test {
|
||||
"#
|
||||
);
|
||||
|
||||
assert!(
|
||||
compiled.errors.is_empty(),
|
||||
"Expected no errors, got: {:?}",
|
||||
compiled.errors
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
compiled,
|
||||
compiled.output,
|
||||
indoc! {
|
||||
"
|
||||
j main
|
||||
@@ -528,7 +606,7 @@ mod test {
|
||||
#[test]
|
||||
fn test_tuple_return_with_expression() -> anyhow::Result<()> {
|
||||
let compiled = compile!(
|
||||
debug
|
||||
check
|
||||
r#"
|
||||
fn add(x, y) {
|
||||
return (x, y);
|
||||
@@ -538,8 +616,14 @@ mod test {
|
||||
"#
|
||||
);
|
||||
|
||||
assert!(
|
||||
compiled.errors.is_empty(),
|
||||
"Expected no errors, got: {:?}",
|
||||
compiled.errors
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
compiled,
|
||||
compiled.output,
|
||||
indoc! {
|
||||
"
|
||||
j main
|
||||
@@ -571,7 +655,7 @@ mod test {
|
||||
#[test]
|
||||
fn test_nested_function_tuple_calls() -> anyhow::Result<()> {
|
||||
let compiled = compile!(
|
||||
debug
|
||||
check
|
||||
r#"
|
||||
fn inner() {
|
||||
return (1, 2);
|
||||
@@ -586,8 +670,14 @@ mod test {
|
||||
"#
|
||||
);
|
||||
|
||||
assert!(
|
||||
compiled.errors.is_empty(),
|
||||
"Expected no errors, got: {:?}",
|
||||
compiled.errors
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
compiled,
|
||||
compiled.output,
|
||||
indoc! {
|
||||
"
|
||||
j main
|
||||
@@ -628,14 +718,20 @@ mod test {
|
||||
#[test]
|
||||
fn test_tuple_literal_with_constant_expressions() -> anyhow::Result<()> {
|
||||
let compiled = compile!(
|
||||
debug
|
||||
check
|
||||
r#"
|
||||
let (a, b) = (1 + 2, 3 * 4);
|
||||
"#
|
||||
);
|
||||
|
||||
assert!(
|
||||
compiled.errors.is_empty(),
|
||||
"Expected no errors, got: {:?}",
|
||||
compiled.errors
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
compiled,
|
||||
compiled.output,
|
||||
indoc! {
|
||||
"
|
||||
j main
|
||||
@@ -652,7 +748,7 @@ mod test {
|
||||
#[test]
|
||||
fn test_tuple_literal_with_variable_expressions() -> anyhow::Result<()> {
|
||||
let compiled = compile!(
|
||||
debug
|
||||
check
|
||||
r#"
|
||||
let x = 5;
|
||||
let y = 10;
|
||||
@@ -660,8 +756,14 @@ mod test {
|
||||
"#
|
||||
);
|
||||
|
||||
assert!(
|
||||
compiled.errors.is_empty(),
|
||||
"Expected no errors, got: {:?}",
|
||||
compiled.errors
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
compiled,
|
||||
compiled.output,
|
||||
indoc! {
|
||||
"
|
||||
j main
|
||||
@@ -682,7 +784,7 @@ mod test {
|
||||
#[test]
|
||||
fn test_tuple_assignment_with_expressions() -> anyhow::Result<()> {
|
||||
let compiled = compile!(
|
||||
debug
|
||||
check
|
||||
r#"
|
||||
let a = 0;
|
||||
let b = 0;
|
||||
@@ -691,8 +793,14 @@ mod test {
|
||||
"#
|
||||
);
|
||||
|
||||
assert!(
|
||||
compiled.errors.is_empty(),
|
||||
"Expected no errors, got: {:?}",
|
||||
compiled.errors
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
compiled,
|
||||
compiled.output,
|
||||
indoc! {
|
||||
"
|
||||
j main
|
||||
@@ -714,7 +822,7 @@ mod test {
|
||||
#[test]
|
||||
fn test_tuple_literal_with_function_calls() -> anyhow::Result<()> {
|
||||
let compiled = compile!(
|
||||
debug
|
||||
check
|
||||
r#"
|
||||
fn getValue() { return 42; };
|
||||
fn getOther() { return 99; };
|
||||
@@ -723,8 +831,14 @@ mod test {
|
||||
"#
|
||||
);
|
||||
|
||||
assert!(
|
||||
compiled.errors.is_empty(),
|
||||
"Expected no errors, got: {:?}",
|
||||
compiled.errors
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
compiled,
|
||||
compiled.output,
|
||||
indoc! {
|
||||
"
|
||||
j main
|
||||
@@ -765,7 +879,7 @@ mod test {
|
||||
#[test]
|
||||
fn test_tuple_with_logical_expressions() -> anyhow::Result<()> {
|
||||
let compiled = compile!(
|
||||
debug
|
||||
check
|
||||
r#"
|
||||
let x = 1;
|
||||
let y = 0;
|
||||
@@ -773,8 +887,14 @@ mod test {
|
||||
"#
|
||||
);
|
||||
|
||||
assert!(
|
||||
compiled.errors.is_empty(),
|
||||
"Expected no errors, got: {:?}",
|
||||
compiled.errors
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
compiled,
|
||||
compiled.output,
|
||||
indoc! {
|
||||
"
|
||||
j main
|
||||
@@ -795,7 +915,7 @@ mod test {
|
||||
#[test]
|
||||
fn test_tuple_with_comparison_expressions() -> anyhow::Result<()> {
|
||||
let compiled = compile!(
|
||||
debug
|
||||
check
|
||||
r#"
|
||||
let x = 5;
|
||||
let y = 10;
|
||||
@@ -803,8 +923,14 @@ mod test {
|
||||
"#
|
||||
);
|
||||
|
||||
assert!(
|
||||
compiled.errors.is_empty(),
|
||||
"Expected no errors, got: {:?}",
|
||||
compiled.errors
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
compiled,
|
||||
compiled.output,
|
||||
indoc! {
|
||||
"
|
||||
j main
|
||||
@@ -825,7 +951,7 @@ mod test {
|
||||
#[test]
|
||||
fn test_tuple_with_device_property_access() -> anyhow::Result<()> {
|
||||
let compiled = compile!(
|
||||
debug
|
||||
check
|
||||
r#"
|
||||
device sensor = "d0";
|
||||
device display = "d1";
|
||||
@@ -834,8 +960,14 @@ mod test {
|
||||
"#
|
||||
);
|
||||
|
||||
assert!(
|
||||
compiled.errors.is_empty(),
|
||||
"Expected no errors, got: {:?}",
|
||||
compiled.errors
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
compiled,
|
||||
compiled.output,
|
||||
indoc! {
|
||||
"
|
||||
j main
|
||||
@@ -854,7 +986,7 @@ mod test {
|
||||
#[test]
|
||||
fn test_tuple_with_device_property_and_function_call() -> anyhow::Result<()> {
|
||||
let compiled = compile!(
|
||||
debug
|
||||
check
|
||||
r#"
|
||||
device self = "db";
|
||||
|
||||
@@ -866,8 +998,14 @@ mod test {
|
||||
"#
|
||||
);
|
||||
|
||||
assert!(
|
||||
compiled.errors.is_empty(),
|
||||
"Expected no errors, got: {:?}",
|
||||
compiled.errors
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
compiled,
|
||||
compiled.output,
|
||||
indoc! {
|
||||
"
|
||||
j main
|
||||
@@ -898,7 +1036,7 @@ mod test {
|
||||
#[test]
|
||||
fn test_tuple_with_function_call_expressions() -> anyhow::Result<()> {
|
||||
let compiled = compile!(
|
||||
debug
|
||||
check
|
||||
r#"
|
||||
fn getValue() { return 10; }
|
||||
fn getOther() { return 20; }
|
||||
@@ -907,8 +1045,14 @@ mod test {
|
||||
"#
|
||||
);
|
||||
|
||||
assert!(
|
||||
compiled.errors.is_empty(),
|
||||
"Expected no errors, got: {:?}",
|
||||
compiled.errors
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
compiled,
|
||||
compiled.output,
|
||||
indoc! {
|
||||
"
|
||||
j main
|
||||
@@ -951,7 +1095,7 @@ mod test {
|
||||
#[test]
|
||||
fn test_tuple_with_stack_spillover() -> anyhow::Result<()> {
|
||||
let compiled = compile!(
|
||||
debug
|
||||
check
|
||||
r#"
|
||||
fn get8() {
|
||||
return (1, 2, 3, 4, 5, 6, 7, 8);
|
||||
@@ -962,8 +1106,14 @@ mod test {
|
||||
"#
|
||||
);
|
||||
|
||||
assert!(
|
||||
compiled.errors.is_empty(),
|
||||
"Expected no errors, got: {:?}",
|
||||
compiled.errors
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
compiled,
|
||||
compiled.output,
|
||||
indoc! {
|
||||
"
|
||||
j main
|
||||
|
||||
Reference in New Issue
Block a user