Add more test cases

This commit is contained in:
d0cd 2022-11-08 15:46:17 -08:00
parent eb1534bb28
commit ef4ae89b92
12 changed files with 161 additions and 6 deletions

16
Cargo.lock generated
View File

@ -368,9 +368,9 @@ checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5"
[[package]]
name = "cc"
version = "1.0.74"
version = "1.0.76"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "581f5dba903aac52ea3feb5ec4810848460ee833876f1f9b0fdeab1f19091574"
checksum = "76a284da2e6fe2092f2353e51713435363112dfd60030e22add80be333fb928f"
dependencies = [
"jobserver",
]
@ -1101,12 +1101,13 @@ dependencies = [
[[package]]
name = "indicatif"
version = "0.17.1"
version = "0.17.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bfddc9561e8baf264e0e45e197fd7696320026eb10a8180340debc27b18f535b"
checksum = "4295cbb7573c16d310e99e713cf9e75101eb190ab31fccd35f2d2691b4352b19"
dependencies = [
"console",
"number_prefix",
"portable-atomic",
"unicode-width",
]
@ -1178,6 +1179,7 @@ version = "1.5.3"
dependencies = [
"criterion",
"indexmap",
"itertools",
"leo-errors",
"leo-span",
"serde",
@ -1763,6 +1765,12 @@ dependencies = [
"plotters-backend",
]
[[package]]
name = "portable-atomic"
version = "0.3.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "15eb2c6e362923af47e13c23ca5afb859e83d54452c55b0b9ac763b8f7c1ac16"
[[package]]
name = "ppv-lite86"
version = "0.2.17"

View File

@ -30,6 +30,9 @@ version = "1.5.3"
version = "1.9"
features = [ "serde-1" ]
[dependencies.itertools]
version = "0.10.5"
[dependencies.serde]
version = "1.0"
features = [ "derive", "rc" ]

View File

@ -16,6 +16,7 @@
use crate::{Identifier, IntegerType, MappingType, Tuple};
use itertools::Itertools;
use serde::{Deserialize, Serialize};
use std::fmt;
@ -69,9 +70,9 @@ impl Type {
(Type::Mapping(left), Type::Mapping(right)) => {
left.key.eq_flat(&right.key) && left.value.eq_flat(&right.value)
}
(Type::Tuple(left), Type::Tuple(right)) => left
(Type::Tuple(left), Type::Tuple(right)) if left.len() == right.len() => left
.iter()
.zip(right.iter())
.zip_eq(right.iter())
.all(|(left_type, right_type)| left_type.eq_flat(right_type)),
(Type::Identifier(left), Type::Identifier(right)) => left.matches(right),
_ => false,

View File

@ -56,6 +56,10 @@ impl<'a> CodeGenerator<'a> {
// Note that this unwrap is safe, since `current_function` is set in `visit_function`.
self.current_function.unwrap().output.iter()
};
println!("input: {:?}", input);
println!("output: {:?}", output);
println!("operand: {:?}", operand);
println!("function: {:?}", self.current_function);
let instructions = operand
.split(' ')
.into_iter()

View File

@ -0,0 +1,45 @@
/*
namespace: Compile
expectation: Pass
*/
program test.aleo {
struct Data {
a: u8,
b: u8,
c: Extra,
}
struct Extra {
c: u8,
}
function foo(a: u8, b: u8) -> (u8, u8, Data) {
let extra: Extra = Extra { c: a };
let data: Data = Data { a: a, b: b, c: extra };
if (a == b) {
return (a, b, data);
}
let c: u8 = a + b;
let d: u8 = a - b;
return (c, d, data);
}
transition bar(flag1: bool, flag2: bool, a: u8, b: u8) -> (u8, u8, Data) {
let start: (u8, u8, Data) = foo(a, b);
if flag1 {
start = foo(start.0, start.2.c.c);
} else {
if flag2 {
start = foo(start.1, start.2.b);
} else {
start = foo(start.2.a, start.1);
}
}
return start;
}
}

View File

@ -18,6 +18,7 @@ program test.aleo {
if flag {
start = foo(start.0, start.1);
} else {
start = foo(start.1, start.0);
}
return start;

View File

@ -0,0 +1,10 @@
/*
namespace: Compile
expectation: Pass
*/
program test.aleo {
transition main(a: u8, b: u8) -> (public u8, u8) {
return (a + b, b + a);
}
}

View File

@ -0,0 +1,17 @@
/*
namespace: Compile
expectation: Fail
*/
program test.aleo {
function foo(a: ()) -> u8 {
console.assert_eq(1u8, 2u8);
return 3u8;
}
transition bar(a: u8, b: u8) -> u8 {
foo(());
return a + b;
}
}

View File

@ -0,0 +1,41 @@
/*
namespace: Compile
expectation: Pass
*/
program test.aleo {
transition foo(a: u8, b: u8) -> () {
console.assert_eq(a, b);
console.assert_eq(b, a);
return ();
}
transition bar(a: u8, b: u8) -> () {
console.assert_eq(a, b);
console.assert_eq(b, a);
return;
}
transition baz(a: u8, b: u8) -> () {
console.assert_eq(a, b);
console.assert_eq(b, a);
}
transition floo(a: u8, b: u8) {
console.assert_eq(a, b);
console.assert_eq(b, a);
return ();
}
transition blar(a: u8, b: u8) {
console.assert_eq(a, b);
console.assert_eq(b, a);
return;
}
transition blaz(a: u8, b: u8) {
console.assert_eq(a, b);
console.assert_eq(b, a);
}
}

View File

@ -0,0 +1,10 @@
---
namespace: Compile
expectation: Pass
outputs:
- output:
- initial_input_ast: no input
initial_ast: 83b847eab54f967d44f321a5f0244c0912810eb277f5e590044bf716c7b6c734
unrolled_ast: 83b847eab54f967d44f321a5f0244c0912810eb277f5e590044bf716c7b6c734
ssa_ast: f14f674da8459d980fa06e0075fec29d29020204142e7a0b159e434926dd44f8
flattened_ast: 45fbe9a7af2a427d9fa6914c5866ea16df0cb86207b694a51aecb814fec11354

View File

@ -0,0 +1,5 @@
---
namespace: Compile
expectation: Fail
outputs:
- "Error [ETYC0372062]: Unit expressions can only be used in return statements.\n --> compiler-test:10:13\n |\n 10 | foo(());\n | ^^\n"

View File

@ -0,0 +1,10 @@
---
namespace: Compile
expectation: Pass
outputs:
- output:
- initial_input_ast: no input
initial_ast: 9667486318cf08b4a5c76d913a853564f3628104d16cd960cab04d37850a0185
unrolled_ast: 9667486318cf08b4a5c76d913a853564f3628104d16cd960cab04d37850a0185
ssa_ast: 9667486318cf08b4a5c76d913a853564f3628104d16cd960cab04d37850a0185
flattened_ast: d24e68675c57fc9ed8b252e07a9ef50d5ee4a739b011cd127b5d552840aa0e71