mirror of
https://github.com/AleoHQ/leo.git
synced 2024-11-28 19:23:24 +03:00
output file now does 'a', swapped to compiler tests, we fail char tests for now since no constraints
This commit is contained in:
commit
1377fc5d75
5
Cargo.lock
generated
5
Cargo.lock
generated
@ -1308,12 +1308,15 @@ dependencies = [
|
||||
"leo-package",
|
||||
"leo-parser",
|
||||
"leo-state",
|
||||
"leo-synthesizer",
|
||||
"leo-test-framework",
|
||||
"num-bigint",
|
||||
"pest",
|
||||
"rand 0.8.3",
|
||||
"rand_core 0.6.2",
|
||||
"rand_xorshift",
|
||||
"serde",
|
||||
"serde_yaml",
|
||||
"sha2",
|
||||
"snarkvm-algorithms",
|
||||
"snarkvm-curves",
|
||||
@ -1450,9 +1453,11 @@ dependencies = [
|
||||
name = "leo-synthesizer"
|
||||
version = "1.4.0"
|
||||
dependencies = [
|
||||
"hex",
|
||||
"num-bigint",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"sha2",
|
||||
"snarkvm-curves",
|
||||
"snarkvm-fields",
|
||||
"snarkvm-gadgets",
|
||||
|
@ -49,6 +49,10 @@ version = "1.4.0"
|
||||
path = "../asg-passes"
|
||||
version = "1.4.0"
|
||||
|
||||
[dependencies.leo-synthesizer]
|
||||
path = "../synthesizer"
|
||||
version = "1.4.0"
|
||||
|
||||
[dependencies.tendril]
|
||||
version = "0.4"
|
||||
|
||||
@ -120,6 +124,13 @@ default-features = false
|
||||
[dev-dependencies.tempfile]
|
||||
version = "3.0.4"
|
||||
|
||||
[dev-dependencies.serde_yaml]
|
||||
version = "0.8"
|
||||
|
||||
[dev-dependencies.leo-test-framework]
|
||||
path = "../test-framework"
|
||||
version = "1.4.0"
|
||||
|
||||
[features]
|
||||
default = [ ]
|
||||
ci_skip = [ "leo-ast/ci_skip" ]
|
||||
|
@ -21,7 +21,7 @@ use crate::{
|
||||
errors::CompilerError,
|
||||
CompilerOptions,
|
||||
GroupType,
|
||||
OutputBytes,
|
||||
Output,
|
||||
OutputFile,
|
||||
};
|
||||
pub use leo_asg::{new_context, AsgContext as Context, AsgContext};
|
||||
@ -272,7 +272,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> Compiler<'a, F, G> {
|
||||
///
|
||||
/// Synthesizes the circuit with program input to verify correctness.
|
||||
///
|
||||
pub fn compile_constraints<CS: ConstraintSystem<F>>(&self, cs: &mut CS) -> Result<OutputBytes, CompilerError> {
|
||||
pub fn compile_constraints<CS: ConstraintSystem<F>>(&self, cs: &mut CS) -> Result<Output, CompilerError> {
|
||||
generate_constraints::<F, G, CS>(cs, &self.asg.as_ref().unwrap(), &self.program_input)
|
||||
}
|
||||
|
||||
@ -337,7 +337,9 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstraintSynthesizer<F> for Compiler<'
|
||||
|
||||
// Write results to file
|
||||
let output_file = OutputFile::new(&package_name);
|
||||
output_file.write(&output_directory, result.bytes()).unwrap();
|
||||
output_file
|
||||
.write(&output_directory, result.to_string().as_bytes())
|
||||
.unwrap();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
//! Generates R1CS constraints for a compiled Leo program.
|
||||
|
||||
use crate::{errors::CompilerError, ConstrainedProgram, GroupType, OutputBytes, OutputFile};
|
||||
use crate::{errors::CompilerError, ConstrainedProgram, GroupType, Output, OutputFile};
|
||||
use leo_asg::Program;
|
||||
use leo_ast::Input;
|
||||
use leo_input::LeoInputParser;
|
||||
@ -30,7 +30,7 @@ pub fn generate_constraints<'a, F: PrimeField, G: GroupType<F>, CS: ConstraintSy
|
||||
cs: &mut CS,
|
||||
program: &Program<'a>,
|
||||
input: &Input,
|
||||
) -> Result<OutputBytes, CompilerError> {
|
||||
) -> Result<Output, CompilerError> {
|
||||
let mut resolved_program = ConstrainedProgram::<F, G>::new(program.clone());
|
||||
|
||||
for (_, global_const) in program.global_consts.iter() {
|
||||
@ -132,7 +132,9 @@ pub fn generate_test_constraints<'a, F: PrimeField, G: GroupType<F>>(
|
||||
let output = result?;
|
||||
let output_file = OutputFile::new(&output_file_name);
|
||||
|
||||
output_file.write(output_directory, output.bytes()).unwrap();
|
||||
output_file
|
||||
.write(output_directory, output.to_string().as_bytes())
|
||||
.unwrap();
|
||||
|
||||
// increment passed tests
|
||||
passed += 1;
|
||||
|
@ -117,7 +117,10 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
Ok(ConstrainedValue::Tuple(
|
||||
values
|
||||
.iter()
|
||||
.map(|x| self.constant_main_function_input(_cs, type_, name, Some(x.clone()), span))
|
||||
.enumerate()
|
||||
.map(|(i, x)| {
|
||||
self.constant_main_function_input(_cs, types.get(i).unwrap(), name, Some(x.clone()), span)
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()?,
|
||||
))
|
||||
}
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
//! Enforces constraints on the main function of a compiled Leo program.
|
||||
|
||||
use crate::{errors::FunctionError, program::ConstrainedProgram, GroupType, OutputBytes};
|
||||
use crate::{errors::FunctionError, program::ConstrainedProgram, GroupType, Output};
|
||||
|
||||
use leo_asg::{Expression, Function, FunctionQualifier};
|
||||
use leo_ast::Input;
|
||||
@ -31,7 +31,7 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
cs: &mut CS,
|
||||
function: &'a Function<'a>,
|
||||
input: &Input,
|
||||
) -> Result<OutputBytes, FunctionError> {
|
||||
) -> Result<Output, FunctionError> {
|
||||
let registers = input.get_registers();
|
||||
|
||||
// Iterate over main function input variables and allocate new values
|
||||
@ -123,8 +123,8 @@ impl<'a, F: PrimeField, G: GroupType<F>> ConstrainedProgram<'a, F, G> {
|
||||
|
||||
let span = function.span.clone().unwrap_or_default();
|
||||
let result_value = self.enforce_function(cs, function, None, &arguments)?;
|
||||
let output_bytes = OutputBytes::new_from_constrained_value(&self.asg, registers, result_value, &span)?;
|
||||
let output = Output::new(&self.asg, registers, result_value, &span)?;
|
||||
|
||||
Ok(output_bytes)
|
||||
Ok(output)
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,105 @@
|
||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
pub mod output_file;
|
||||
use std::{collections::BTreeMap, fmt};
|
||||
|
||||
pub use self::output_file::*;
|
||||
|
||||
pub mod output_bytes;
|
||||
pub use self::output_bytes::*;
|
||||
|
||||
use crate::{errors::OutputBytesError, ConstrainedValue, GroupType, REGISTERS_VARIABLE_NAME};
|
||||
use leo_asg::Program;
|
||||
use leo_ast::{Parameter, Registers, Span};
|
||||
|
||||
use snarkvm_fields::PrimeField;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Deserialize, Serialize, Debug)]
|
||||
pub struct OutputRegister {
|
||||
#[serde(rename = "type")]
|
||||
pub type_: String,
|
||||
pub value: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, Debug)]
|
||||
pub struct Output {
|
||||
pub registers: BTreeMap<String, OutputRegister>,
|
||||
}
|
||||
|
||||
impl fmt::Display for Output {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
writeln!(f, "[{}]", REGISTERS_VARIABLE_NAME)?;
|
||||
// format: "token_id: u64 = 1u64;"
|
||||
for (name, register) in self.registers.iter() {
|
||||
match register.type_.as_str() {
|
||||
"char" => writeln!(f, "{}: {} = '{}';", name, register.type_, register.value)?,
|
||||
_ => writeln!(f, "{}: {} = {};", name, register.type_, register.value)?,
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(clippy::from_over_into)]
|
||||
impl Into<OutputBytes> for Output {
|
||||
fn into(self) -> OutputBytes {
|
||||
OutputBytes::from(self.to_string().into_bytes())
|
||||
}
|
||||
}
|
||||
|
||||
impl Output {
|
||||
pub fn new<'a, F: PrimeField, G: GroupType<F>>(
|
||||
program: &Program<'a>,
|
||||
registers: &Registers,
|
||||
value: ConstrainedValue<'a, F, G>,
|
||||
span: &Span,
|
||||
) -> Result<Self, OutputBytesError> {
|
||||
let return_values = match value {
|
||||
ConstrainedValue::Tuple(values) => values,
|
||||
value => vec![value],
|
||||
};
|
||||
let register_hashmap = registers.values();
|
||||
|
||||
// Create vector of parameter values in alphabetical order
|
||||
let mut register_values = register_hashmap
|
||||
.into_iter()
|
||||
.map(|register| register.0)
|
||||
.collect::<Vec<Parameter>>();
|
||||
|
||||
register_values.sort_by(|a, b| a.variable.name.cmp(&b.variable.name));
|
||||
|
||||
// Return an error if we do not have enough return registers
|
||||
if register_values.len() < return_values.len() {
|
||||
return Err(OutputBytesError::not_enough_registers(span));
|
||||
}
|
||||
|
||||
let mut registers = BTreeMap::new();
|
||||
|
||||
for (parameter, value) in register_values.into_iter().zip(return_values.into_iter()) {
|
||||
let name = parameter.variable.name;
|
||||
|
||||
// Check register type == return value type.
|
||||
let register_type = program.scope.resolve_ast_type(¶meter.type_)?;
|
||||
let return_value_type = value.to_type(span)?;
|
||||
|
||||
if !register_type.is_assignable_from(&return_value_type) {
|
||||
return Err(OutputBytesError::mismatched_output_types(
|
||||
®ister_type,
|
||||
&return_value_type,
|
||||
span,
|
||||
));
|
||||
}
|
||||
|
||||
let value = value.to_string();
|
||||
|
||||
registers.insert(name.to_string(), OutputRegister {
|
||||
type_: register_type.to_string(),
|
||||
value,
|
||||
});
|
||||
}
|
||||
|
||||
Ok(Output { registers })
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +0,0 @@
|
||||
function main() {
|
||||
const address_1 = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;
|
||||
const address_2 = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j9;
|
||||
|
||||
console.assert(address_1 == address_2);
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
function main() {
|
||||
const address_1 = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;
|
||||
const address_2 = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;
|
||||
|
||||
console.assert(address_1 == address_2);
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
function main() {
|
||||
const owner = address();
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
function main(a: address, b: address, c: bool) {
|
||||
console.assert(a == b == c);
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
function main() {
|
||||
const public_key_string: address = zleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
function main() {
|
||||
const public_key_string: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
function main(owner: address) {
|
||||
const sender = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;
|
||||
|
||||
console.assert(owner == sender);
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
function main() {
|
||||
const public_key_string = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j88;
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
function main() {
|
||||
const public_key_string = address(zleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8);
|
||||
}
|
@ -1,139 +0,0 @@
|
||||
// Copyright (C) 2019-2021 Aleo Systems Inc.
|
||||
// This file is part of the Leo library.
|
||||
|
||||
// The Leo library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// The Leo library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::{assert_satisfied, expect_asg_error, expect_compiler_error, generate_main_input, parse_program};
|
||||
use leo_ast::InputValue;
|
||||
|
||||
static TEST_ADDRESS_1: &str = "aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8";
|
||||
static TEST_ADDRESS_2: &str = "aleo18qgam03qe483tdrcc3fkqwpp38ehff4a2xma6lu7hams6lfpgcpq3dq05r";
|
||||
|
||||
#[test]
|
||||
fn test_valid() {
|
||||
let program_string = include_str!("valid.leo");
|
||||
let program = parse_program(program_string).unwrap();
|
||||
|
||||
assert_satisfied(program)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_invalid_prefix() {
|
||||
let program_string = include_str!("invalid_prefix.leo");
|
||||
let syntax_error = parse_program(program_string).is_err();
|
||||
|
||||
assert!(syntax_error);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_invalid_length() {
|
||||
let program_string = include_str!("invalid_length.leo");
|
||||
let syntax_error = parse_program(program_string).is_err();
|
||||
|
||||
assert!(syntax_error);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_empty() {
|
||||
let program_string = include_str!("empty.leo");
|
||||
let syntax_error = parse_program(program_string).is_err();
|
||||
|
||||
assert!(syntax_error);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_implicit_valid() {
|
||||
let program_string = include_str!("implicit_valid.leo");
|
||||
let program = parse_program(program_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_implicit_invalid() {
|
||||
let program_string = include_str!("implicit_invalid.leo");
|
||||
let error = parse_program(program_string).err().unwrap();
|
||||
|
||||
expect_asg_error(error);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_console_assert_pass() {
|
||||
let program_string = include_str!("console_assert_pass.leo");
|
||||
let program = parse_program(program_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_console_assert_fail() {
|
||||
let program_string = include_str!("console_assert_fail.leo");
|
||||
let program = parse_program(program_string).unwrap();
|
||||
|
||||
let _output = expect_compiler_error(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ternary() {
|
||||
let program_string = include_str!("ternary.leo");
|
||||
let mut program = parse_program(program_string).unwrap();
|
||||
|
||||
let main_input = generate_main_input(vec![
|
||||
("s", Some(InputValue::Boolean(true))),
|
||||
("c", Some(InputValue::Address(TEST_ADDRESS_1.to_string()))),
|
||||
]);
|
||||
|
||||
program.set_main_input(main_input);
|
||||
|
||||
assert_satisfied(program);
|
||||
|
||||
let mut program = parse_program(program_string).unwrap();
|
||||
|
||||
let main_input = generate_main_input(vec![
|
||||
("s", Some(InputValue::Boolean(false))),
|
||||
("c", Some(InputValue::Address(TEST_ADDRESS_2.to_string()))),
|
||||
]);
|
||||
|
||||
program.set_main_input(main_input);
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_equal() {
|
||||
let program_string = include_str!("equal.leo");
|
||||
let mut program = parse_program(program_string).unwrap();
|
||||
|
||||
let main_input = generate_main_input(vec![
|
||||
("a", Some(InputValue::Address(TEST_ADDRESS_1.to_string()))),
|
||||
("b", Some(InputValue::Address(TEST_ADDRESS_1.to_string()))),
|
||||
("c", Some(InputValue::Boolean(true))),
|
||||
]);
|
||||
|
||||
program.set_main_input(main_input);
|
||||
|
||||
assert_satisfied(program);
|
||||
|
||||
let mut program = parse_program(program_string).unwrap();
|
||||
|
||||
let main_input = generate_main_input(vec![
|
||||
("a", Some(InputValue::Address(TEST_ADDRESS_1.to_string()))),
|
||||
("b", Some(InputValue::Address(TEST_ADDRESS_2.to_string()))),
|
||||
("c", Some(InputValue::Boolean(false))),
|
||||
]);
|
||||
|
||||
program.set_main_input(main_input);
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
function main(s: bool, c: address) {
|
||||
const a = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;
|
||||
const b = aleo18qgam03qe483tdrcc3fkqwpp38ehff4a2xma6lu7hams6lfpgcpq3dq05r;
|
||||
|
||||
let r = s ? a: b;
|
||||
|
||||
console.assert(r == c);
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
function main() {
|
||||
const public_key_string = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8;
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
function main(a: [u8; 3]) {
|
||||
console.assert(a == [1u8; 3]);
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
function main(a: [u8; 3]) {
|
||||
console.assert(a == [1u8; -3]);
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
function main(a: [u8; (3, 2)]) {
|
||||
console.assert(a == [0u8; (3, 2)]);
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
function main(a: [u8; 3]) {
|
||||
console.assert(a == [1u8, 1u8, 1u8]);
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
function main() {
|
||||
const a = [1u8, bool];
|
||||
}
|
@ -1,2 +0,0 @@
|
||||
[registers]
|
||||
r: [u8; 3] = [1u8, 1u8, 1u8];
|
@ -1,2 +0,0 @@
|
||||
[registers]
|
||||
r: [u8; 3] = [0u8, 0u8, 0u8];
|
@ -1,2 +0,0 @@
|
||||
[main]
|
||||
a: [u8; (3, 2)] = [0; (3, 2)];
|
@ -1,2 +0,0 @@
|
||||
[main]
|
||||
a: [u8; 3] = [1, 1, 1];
|
@ -1,3 +0,0 @@
|
||||
function main(a: [u8; (3, 2)]) {
|
||||
console.assert(a == [[0u8; 2]; 3]);
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
function main(a: [u8; (3, 2)]) {
|
||||
console.assert(a == [[0u8; 2]; 3)]); // This should be written the right way as this test is for the input file.
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
function main(a: [u8; (3, 2)]) {
|
||||
console.assert(a == [0u8; (3, 2)]);
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
function main(a: [u8; (3, 2)]) {
|
||||
console.assert(a == [0u8; (3, 2)]);
|
||||
}
|
@ -1,716 +0,0 @@
|
||||
// Copyright (C) 2019-2021 Aleo Systems Inc.
|
||||
// This file is part of the Leo library.
|
||||
|
||||
// The Leo library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// The Leo library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::{
|
||||
assert_satisfied,
|
||||
expect_asg_error,
|
||||
expect_compiler_error,
|
||||
get_output,
|
||||
parse_program,
|
||||
parse_program_with_input,
|
||||
EdwardsTestCompiler,
|
||||
};
|
||||
|
||||
pub fn output_ones(program: EdwardsTestCompiler) {
|
||||
let expected = include_bytes!("output/registers_ones.out");
|
||||
let actual = get_output(program);
|
||||
|
||||
assert!(expected.eq(actual.bytes().as_slice()));
|
||||
}
|
||||
|
||||
pub fn output_zeros(program: EdwardsTestCompiler) {
|
||||
let expected = include_bytes!("output/registers_zeros.out");
|
||||
let actual = get_output(program);
|
||||
|
||||
assert!(expected.eq(actual.bytes().as_slice()));
|
||||
}
|
||||
|
||||
// Registers
|
||||
|
||||
#[test]
|
||||
fn test_registers() {
|
||||
let program_string = include_str!("registers.leo");
|
||||
let ones_input_string = include_str!("input/registers_ones.in");
|
||||
let zeros_input_string = include_str!("input/registers_zeros.in");
|
||||
|
||||
// test ones input register => ones output register
|
||||
let program = parse_program_with_input(program_string, ones_input_string).unwrap();
|
||||
|
||||
output_ones(program);
|
||||
|
||||
// test zeros input register => zeros output register
|
||||
let program = parse_program_with_input(program_string, zeros_input_string).unwrap();
|
||||
|
||||
output_zeros(program);
|
||||
}
|
||||
|
||||
// Expressions
|
||||
|
||||
#[test]
|
||||
fn test_inline() {
|
||||
let program_string = include_str!("inline.leo");
|
||||
let input_string = include_str!("input/three_ones.in");
|
||||
let program = parse_program_with_input(program_string, input_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_nested() {
|
||||
let program_string = include_str!("nested.leo");
|
||||
let program = parse_program(program_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_inline_fail() {
|
||||
let program_string = include_str!("inline.leo");
|
||||
let program = parse_program(program_string).unwrap();
|
||||
|
||||
let _err = expect_compiler_error(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_initializer() {
|
||||
let program_string = include_str!("initializer.leo");
|
||||
let input_string = include_str!("input/three_ones.in");
|
||||
let program = parse_program_with_input(program_string, input_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_initializer_fail() {
|
||||
let program_string = include_str!("initializer_fail.leo");
|
||||
let input_string = include_str!("input/three_ones.in");
|
||||
let syntax_error = parse_program_with_input(program_string, input_string).is_err();
|
||||
|
||||
assert!(syntax_error);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_initializer_input() {
|
||||
let program_string = include_str!("initializer_input.leo");
|
||||
let input_string = include_str!("input/six_zeros.in");
|
||||
let program = parse_program_with_input(program_string, input_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_initializer_input_fail() {
|
||||
let program_string = include_str!("initializer_input.leo");
|
||||
let input_string = include_str!("input/initializer_fail.in");
|
||||
let syntax_error = parse_program_with_input(program_string, input_string).is_err();
|
||||
|
||||
assert!(syntax_error);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_input_nested_3x2() {
|
||||
let program_string = include_str!("input_nested_3x2.leo");
|
||||
let input_string = include_str!("input/input_nested_3x2.in");
|
||||
let program = parse_program_with_input(program_string, input_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_input_nested_3x2_fail() {
|
||||
let program_string = include_str!("input_nested_3x2_fail.leo");
|
||||
let input_string = include_str!("input/input_nested_3x2_fail.in");
|
||||
let syntax_error = parse_program_with_input(program_string, input_string).is_err();
|
||||
|
||||
assert!(syntax_error);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_input_tuple_3x2() {
|
||||
let program_string = include_str!("input_tuple_3x2.leo");
|
||||
let input_string = include_str!("input/input_tuple_3x2.in");
|
||||
let program = parse_program_with_input(program_string, input_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_input_tuple_3x2_fail() {
|
||||
let program_string = include_str!("input_tuple_3x2_fail.leo");
|
||||
let input_string = include_str!("input/input_tuple_3x2_fail.in");
|
||||
let syntax_error = parse_program_with_input(program_string, input_string).is_err();
|
||||
|
||||
assert!(syntax_error);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_multi_fail_initializer() {
|
||||
let program_string = include_str!("multi_fail_initializer.leo");
|
||||
let error = parse_program(program_string).err().unwrap();
|
||||
|
||||
expect_asg_error(error);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_multi_inline_fail() {
|
||||
let program_string = include_str!("multi_fail_inline.leo");
|
||||
let error = parse_program(program_string).err().unwrap();
|
||||
|
||||
expect_asg_error(error);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_multi_initializer() {
|
||||
let program_string = include_str!("multi_initializer.leo");
|
||||
let program = parse_program(program_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_multi_initializer_fail() {
|
||||
let program_string = include_str!("multi_initializer_fail.leo");
|
||||
let error = parse_program(program_string).err().unwrap();
|
||||
|
||||
expect_asg_error(error);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_nested_3x2_value() {
|
||||
let program_string = include_str!("nested_3x2_value.leo");
|
||||
let program = parse_program(program_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_nested_3x2_value_fail() {
|
||||
let program_string = include_str!("nested_3x2_value_fail.leo");
|
||||
let error = parse_program(program_string).err().unwrap();
|
||||
|
||||
expect_asg_error(error);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_tuple_3x2_value() {
|
||||
let program_string = include_str!("tuple_3x2_value.leo");
|
||||
let program = parse_program(program_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_tuple_3x2_value_fail() {
|
||||
let program_string = include_str!("tuple_3x2_value_fail.leo");
|
||||
let error = parse_program(program_string).err().unwrap();
|
||||
|
||||
expect_asg_error(error);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_spread() {
|
||||
let program_string = include_str!("spread.leo");
|
||||
let input_string = include_str!("input/three_ones.in");
|
||||
let program = parse_program_with_input(program_string, input_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_slice() {
|
||||
let program_string = include_str!("slice.leo");
|
||||
let input_string = include_str!("input/three_ones.in");
|
||||
let program = parse_program_with_input(program_string, input_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_slice_lower() {
|
||||
let program_string = include_str!("slice_lower.leo");
|
||||
let program = parse_program(program_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
// Array type tests
|
||||
|
||||
#[test]
|
||||
fn test_type_fail() {
|
||||
let program_string = include_str!("type_fail.leo");
|
||||
let syntax_error = parse_program(program_string).is_err();
|
||||
|
||||
assert!(syntax_error);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_type_nested_value_nested_3x2() {
|
||||
let program_string = include_str!("type_nested_value_nested_3x2.leo");
|
||||
let program = parse_program(program_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_type_nested_value_nested_3x2_fail() {
|
||||
let program_string = include_str!("type_nested_value_nested_3x2_fail.leo");
|
||||
let error = parse_program(program_string).err().unwrap();
|
||||
|
||||
expect_asg_error(error);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_type_nested_value_nested_4x3x2() {
|
||||
let program_string = include_str!("type_nested_value_nested_4x3x2.leo");
|
||||
let program = parse_program(program_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_type_nested_value_nested_4x3x2_fail() {
|
||||
let program_string = include_str!("type_nested_value_nested_4x3x2_fail.leo");
|
||||
let error = parse_program(program_string).err().unwrap();
|
||||
|
||||
expect_asg_error(error);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_type_nested_value_tuple_3x2() {
|
||||
let program_string = include_str!("type_nested_value_tuple_3x2.leo");
|
||||
let program = parse_program(program_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_type_nested_value_tuple_3x2_fail() {
|
||||
let program_string = include_str!("type_nested_value_tuple_3x2_fail.leo");
|
||||
let error = parse_program(program_string).err().unwrap();
|
||||
|
||||
expect_asg_error(error);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_type_nested_value_tuple_4x3x2() {
|
||||
let program_string = include_str!("type_nested_value_tuple_4x3x2.leo");
|
||||
let program = parse_program(program_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_type_nested_value_tuple_4x3x2_fail() {
|
||||
let program_string = include_str!("type_nested_value_tuple_4x3x2_fail.leo");
|
||||
let error = parse_program(program_string).err().unwrap();
|
||||
|
||||
expect_asg_error(error);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_type_tuple_value_nested_3x2() {
|
||||
let program_string = include_str!("type_tuple_value_nested_3x2.leo");
|
||||
let program = parse_program(program_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_type_tuple_value_nested_3x2_fail() {
|
||||
let program_string = include_str!("type_tuple_value_nested_3x2_fail.leo");
|
||||
let error = parse_program(program_string).err().unwrap();
|
||||
|
||||
expect_asg_error(error);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_type_tuple_value_nested_4x3x2() {
|
||||
let program_string = include_str!("type_tuple_value_nested_4x3x2.leo");
|
||||
let program = parse_program(program_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_type_tuple_value_nested_4x3x2_fail() {
|
||||
let program_string = include_str!("type_tuple_value_nested_4x3x2_fail.leo");
|
||||
let error = parse_program(program_string).err().unwrap();
|
||||
|
||||
expect_asg_error(error);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_type_tuple_value_tuple_3x2() {
|
||||
let program_string = include_str!("type_tuple_value_tuple_3x2.leo");
|
||||
let program = parse_program(program_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_type_tuple_value_tuple_3x2_fail() {
|
||||
let program_string = include_str!("type_tuple_value_tuple_3x2_fail.leo");
|
||||
let error = parse_program(program_string).err().unwrap();
|
||||
|
||||
expect_asg_error(error);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_type_tuple_value_tuple_4x3x2() {
|
||||
let program_string = include_str!("type_tuple_value_tuple_4x3x2.leo");
|
||||
let program = parse_program(program_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_type_tuple_value_tuple_4x3x2_fail() {
|
||||
let program_string = include_str!("type_tuple_value_tuple_4x3x2_fail.leo");
|
||||
let error = parse_program(program_string).err().unwrap();
|
||||
|
||||
expect_asg_error(error);
|
||||
}
|
||||
|
||||
// Tests for nested multi-dimensional arrays as input to the program
|
||||
|
||||
#[test]
|
||||
fn test_input_type_nested_value_nested_3x2() {
|
||||
let program_string = include_str!("type_input_3x2.leo");
|
||||
let input_string = include_str!("input/type_nested_value_nested_3x2.in");
|
||||
let program = parse_program_with_input(program_string, input_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_input_type_nested_value_nested_3x2_fail() {
|
||||
let program_string = include_str!("type_input_3x2.leo");
|
||||
let input_string = include_str!("input/type_nested_value_nested_3x2_fail.in");
|
||||
let syntax_error = parse_program_with_input(program_string, input_string).is_err();
|
||||
|
||||
assert!(syntax_error);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_input_type_nested_value_nested_4x3x2() {
|
||||
let program_string = include_str!("type_input_4x3x2.leo");
|
||||
let input_string = include_str!("input/type_nested_value_nested_4x3x2.in");
|
||||
let program = parse_program_with_input(program_string, input_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_input_type_nested_value_nested_4x3x2_fail() {
|
||||
let program_string = include_str!("type_input_4x3x2.leo");
|
||||
let input_string = include_str!("input/type_nested_value_nested_4x3x2_fail.in");
|
||||
let syntax_error = parse_program_with_input(program_string, input_string).is_err();
|
||||
|
||||
assert!(syntax_error);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_input_type_nested_value_tuple_3x2() {
|
||||
let program_string = include_str!("type_input_3x2.leo");
|
||||
let input_string = include_str!("input/type_nested_value_tuple_3x2.in");
|
||||
let program = parse_program_with_input(program_string, input_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_input_type_nested_value_tuple_3x2_fail() {
|
||||
let program_string = include_str!("type_input_3x2.leo");
|
||||
let input_string = include_str!("input/type_nested_value_tuple_3x2_fail.in");
|
||||
let syntax_error = parse_program_with_input(program_string, input_string).is_err();
|
||||
|
||||
assert!(syntax_error);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_input_type_nested_value_tuple_4x3x2() {
|
||||
let program_string = include_str!("type_input_4x3x2.leo");
|
||||
let input_string = include_str!("input/type_nested_value_tuple_4x3x2.in");
|
||||
let program = parse_program_with_input(program_string, input_string).unwrap();
|
||||
|
||||
assert_satisfied(program)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_input_type_nested_value_tuple_4x3x2_fail() {
|
||||
let program_string = include_str!("type_input_4x3x2.leo");
|
||||
let input_string = include_str!("input/type_nested_value_tuple_4x3x2_fail.in");
|
||||
let syntax_error = parse_program_with_input(program_string, input_string).is_err();
|
||||
|
||||
assert!(syntax_error);
|
||||
}
|
||||
|
||||
// Tests for multi-dimensional arrays using tuple syntax as input to the program
|
||||
|
||||
#[test]
|
||||
fn test_input_type_tuple_value_nested_3x2() {
|
||||
let program_string = include_str!("type_input_3x2.leo");
|
||||
let input_string = include_str!("input/type_tuple_value_nested_3x2.in");
|
||||
let program = parse_program_with_input(program_string, input_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_input_type_tuple_value_nested_3x2_fail() {
|
||||
let program_string = include_str!("type_input_3x2.leo");
|
||||
let input_string = include_str!("input/type_tuple_value_nested_3x2_fail.in");
|
||||
let syntax_error = parse_program_with_input(program_string, input_string).is_err();
|
||||
|
||||
assert!(syntax_error);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_input_type_tuple_value_nested_4x3x2() {
|
||||
let program_string = include_str!("type_input_4x3x2.leo");
|
||||
let input_string = include_str!("input/type_tuple_value_nested_4x3x2.in");
|
||||
let program = parse_program_with_input(program_string, input_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_input_type_tuple_value_nested_4x3x2_fail() {
|
||||
let program_string = include_str!("type_input_4x3x2.leo");
|
||||
let input_string = include_str!("input/type_tuple_value_nested_4x3x2_fail.in");
|
||||
let syntax_error = parse_program_with_input(program_string, input_string).is_err();
|
||||
|
||||
assert!(syntax_error);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_input_type_tuple_value_tuple_3x2() {
|
||||
let program_string = include_str!("type_input_3x2.leo");
|
||||
let input_string = include_str!("input/type_tuple_value_tuple_3x2.in");
|
||||
let program = parse_program_with_input(program_string, input_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_input_type_tuple_value_tuple_3x2_fail() {
|
||||
let program_string = include_str!("type_input_3x2.leo");
|
||||
let input_string = include_str!("input/type_tuple_value_tuple_3x2_fail.in");
|
||||
let syntax_error = parse_program_with_input(program_string, input_string).is_err();
|
||||
|
||||
assert!(syntax_error);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_input_type_tuple_value_tuple_4x3x2() {
|
||||
let program_string = include_str!("type_input_4x3x2.leo");
|
||||
let input_string = include_str!("input/type_tuple_value_tuple_4x3x2.in");
|
||||
let program = parse_program_with_input(program_string, input_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_input_type_tuple_value_tuple_4x3x2_fail() {
|
||||
let program_string = include_str!("type_input_4x3x2.leo");
|
||||
let input_string = include_str!("input/type_tuple_value_tuple_4x3x2_fail.in");
|
||||
let syntax_error = parse_program_with_input(program_string, input_string).is_err();
|
||||
|
||||
assert!(syntax_error);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_variable_slice_fail() {
|
||||
let program_string = include_str!("variable_slice_fail.leo");
|
||||
let error = parse_program(program_string).err().unwrap();
|
||||
|
||||
expect_asg_error(error);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_array_index() {
|
||||
let program_string = r#"
|
||||
function main(i: u32) {
|
||||
let b = [1u8, 2, 3, 4];
|
||||
|
||||
console.assert(2 == b[i]);
|
||||
console.assert(3 == b[2]);
|
||||
}
|
||||
"#;
|
||||
let input_string = r#"
|
||||
[main]
|
||||
i: u32 = 1;
|
||||
"#;
|
||||
let program = parse_program_with_input(program_string, input_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_array_index_bounds_fail() {
|
||||
let program_string = r#"
|
||||
function main(i: u32) {
|
||||
let b = [1u8, 2, 3, 4];
|
||||
|
||||
console.assert(2 == b[i]);
|
||||
}
|
||||
"#;
|
||||
let input_string = r#"
|
||||
[main]
|
||||
i: u32 = 4;
|
||||
"#;
|
||||
let program = parse_program_with_input(program_string, input_string).unwrap();
|
||||
|
||||
expect_compiler_error(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_const_array_index_bounds_fail() {
|
||||
let program_string = r#"
|
||||
function main() {
|
||||
let b = [1u8, 2, 3, 4];
|
||||
const i: u32 = 4;
|
||||
|
||||
console.assert(2 == b[i]);
|
||||
}
|
||||
"#;
|
||||
let error = parse_program(program_string).err().unwrap();
|
||||
|
||||
expect_asg_error(error);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_array_range_index() {
|
||||
let program_string = r#"
|
||||
function main(i: u32) {
|
||||
let b = [1u8, 2, 3, 4];
|
||||
|
||||
console.assert([1u8, 2] == b[0..i]);
|
||||
console.assert([3u8, 4] == b[i..4]);
|
||||
}
|
||||
"#;
|
||||
let input_string = r#"
|
||||
[main]
|
||||
i: u32 = 2;
|
||||
"#;
|
||||
let program = parse_program_with_input(program_string, input_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_array_range_index_dyn() {
|
||||
let program_string = r#"
|
||||
function main(i: u32) {
|
||||
let b = [1u8, 2, 3, 4];
|
||||
|
||||
console.assert([1u8, 2] == b[..i]);
|
||||
console.assert([3u8, 4] == b[i..]);
|
||||
}
|
||||
"#;
|
||||
let input_string = r#"
|
||||
[main]
|
||||
i: u32 = 2;
|
||||
"#;
|
||||
let program = parse_program_with_input(program_string, input_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_array_range_index_full_dyn() {
|
||||
let program_string = r#"
|
||||
function main(i: u32, y: u32) {
|
||||
let b = [1u8, 2, 3, 4];
|
||||
|
||||
console.assert([3u8, 4] == b[i..y]);
|
||||
}
|
||||
"#;
|
||||
let input_string = r#"
|
||||
[main]
|
||||
i: u32 = 2;
|
||||
y: u32 = 4;
|
||||
"#;
|
||||
let program = parse_program_with_input(program_string, input_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_array_range_index_out_of_bounds_fail() {
|
||||
let program_string = r#"
|
||||
function main() {
|
||||
let b = [1u8, 2, 3, 4];
|
||||
|
||||
console.assert([1, 2] == b[3..5]);
|
||||
}
|
||||
"#;
|
||||
let error = parse_program(program_string).err().unwrap();
|
||||
|
||||
expect_asg_error(error);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_array_range_index_invalid_bounds_fail() {
|
||||
let program_string = r#"
|
||||
function main() {
|
||||
let b = [1u8, 2, 3, 4];
|
||||
|
||||
console.assert([1, 2] == b[2..1]);
|
||||
}
|
||||
"#;
|
||||
let error = parse_program(program_string).err().unwrap();
|
||||
|
||||
expect_asg_error(error);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_array_range_index_full_dyn_resized_fail() {
|
||||
let program_string = r#"
|
||||
function main(i: u32, y: u32) {
|
||||
let b = [1u8, 2, 3, 4];
|
||||
|
||||
console.assert([3u8, 4] == b[i..y]);
|
||||
}
|
||||
"#;
|
||||
let input_string = r#"
|
||||
[main]
|
||||
i: u32 = 1;
|
||||
y: u32 = 4;
|
||||
"#;
|
||||
let program = parse_program_with_input(program_string, input_string).unwrap();
|
||||
|
||||
expect_compiler_error(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_array_range_index_full_dyn_bounds_fail() {
|
||||
let program_string = r#"
|
||||
function main(i: u32, y: u32) {
|
||||
let b = [1u8, 2, 3, 4];
|
||||
|
||||
console.assert([3u8, 4] == b[i..y]);
|
||||
}
|
||||
"#;
|
||||
let input_string = r#"
|
||||
[main]
|
||||
i: u32 = 3;
|
||||
y: u32 = 5;
|
||||
"#;
|
||||
let program = parse_program_with_input(program_string, input_string).unwrap();
|
||||
|
||||
expect_compiler_error(program);
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
function main() {
|
||||
const arr: [u8; (2, 2)] = [[1u8; 2]; 1]; // incorrect dimensions
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
function main() {
|
||||
const arr: [u8; (2, 2)] = [[1u8, 1u8],
|
||||
[1u8]]; // incorrect dimensions
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
function main() {
|
||||
const a: [u8; (2, 2, 2)] = [1u8; (2, 2, 2)];
|
||||
|
||||
const b: [u8; (2, 2, 2)] = [[[1u8; 2]; 2]; 2];
|
||||
|
||||
console.assert(a == b);
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
function main() {
|
||||
const arr: [u8; (2, 2)] = [1u8; (2, 1)]; // incorrect dimensions
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
function main () {
|
||||
const x = [false; (2, 2)];
|
||||
const y: bool = x[0][0];
|
||||
}
|
@ -1,2 +0,0 @@
|
||||
[registers]
|
||||
r: [u8; 3] = [1, 1, 1];
|
@ -1,2 +0,0 @@
|
||||
[registers]
|
||||
r: [u8; 3] = [0, 0, 0];
|
@ -1,3 +0,0 @@
|
||||
function main() -> [u8; 3] {
|
||||
return input.registers.r;
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
// `{from}..{to}` copies the elements of one array into another exclusively
|
||||
function main(a: [u8; 3]) {
|
||||
const b = [1u8; 4];
|
||||
|
||||
console.assert(a == b[0..3]);
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
// A spread operator `...` copies the elements of one array into another
|
||||
function main(a: [u8; 3]) {
|
||||
const b = [1u8, 1u8];
|
||||
const c = [1u8, ...b];
|
||||
|
||||
console.assert(a == c);
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
function main(a: [[u8; 2]; 3]) {
|
||||
const b = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline
|
||||
|
||||
console.assert(a == b);
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
function main() {
|
||||
const a = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline
|
||||
|
||||
const b: [[u8; 2]; 3] = [[0; 2]; 3]; // initializer
|
||||
|
||||
console.assert(a == b);
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
function main() {
|
||||
const a = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline
|
||||
|
||||
const b: [[u8; 2]; 3] = [0; (3, 2)]; // initializer
|
||||
|
||||
console.assert(a == b);
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
function main() {
|
||||
const a = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline
|
||||
|
||||
const b: [u8; (3, 2)] = [[0; 2]; 3]; // initializer
|
||||
|
||||
console.assert(a == b);
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
function main() {
|
||||
const a = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline
|
||||
|
||||
const b: [u8; (3, 2)] = [0; (3, 2)]; // initializer
|
||||
|
||||
console.assert(a == b);
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
// !(true && (false || true))
|
||||
function main() {
|
||||
const a = true;
|
||||
const b = false || a;
|
||||
const c = !(true && b);
|
||||
|
||||
console.assert(c == false);
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
function main(a: bool, b: bool) {
|
||||
console.assert(a == b);
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
function main () {
|
||||
let x = true;
|
||||
if x {
|
||||
const y = 0u8;
|
||||
}
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
function main() {
|
||||
const a = false && false;
|
||||
|
||||
console.assert(a == false);
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
function main() {
|
||||
const a = false || false;
|
||||
|
||||
console.assert(a == false);
|
||||
}
|
@ -1,2 +0,0 @@
|
||||
[registers]
|
||||
r: bool = false;
|
@ -1,2 +0,0 @@
|
||||
[registers]
|
||||
r: bool = true;
|
@ -1,3 +0,0 @@
|
||||
[main]
|
||||
a: bool = true;
|
||||
b: bool = false;
|
@ -1,3 +0,0 @@
|
||||
[main]
|
||||
a: bool = true;
|
||||
b: bool = true;
|
@ -1,196 +0,0 @@
|
||||
// Copyright (C) 2019-2021 Aleo Systems Inc.
|
||||
// This file is part of the Leo library.
|
||||
|
||||
// The Leo library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// The Leo library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::{
|
||||
assert_satisfied,
|
||||
expect_asg_error,
|
||||
expect_compiler_error,
|
||||
get_output,
|
||||
parse_program,
|
||||
parse_program_with_input,
|
||||
EdwardsTestCompiler,
|
||||
};
|
||||
|
||||
pub fn output_true(program: EdwardsTestCompiler) {
|
||||
let expected = include_bytes!("output/registers_true.out");
|
||||
let actual = get_output(program);
|
||||
|
||||
assert_eq!(expected, actual.bytes().as_slice());
|
||||
}
|
||||
|
||||
pub fn output_false(program: EdwardsTestCompiler) {
|
||||
let expected = include_bytes!("output/registers_false.out");
|
||||
let actual = get_output(program);
|
||||
|
||||
assert_eq!(expected, actual.bytes().as_slice());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_input_pass() {
|
||||
let program_string = include_str!("assert_eq_input.leo");
|
||||
let input_string = include_str!("input/true_true.in");
|
||||
|
||||
let program = parse_program_with_input(program_string, input_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_input_fail() {
|
||||
let program_string = include_str!("assert_eq_input.leo");
|
||||
let input_string = include_str!("input/true_false.in");
|
||||
|
||||
let program = parse_program_with_input(program_string, input_string).unwrap();
|
||||
|
||||
expect_compiler_error(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_registers() {
|
||||
let program_string = include_str!("output_register.leo");
|
||||
let true_input_string = include_str!("input/registers_true.in");
|
||||
let false_input_string = include_str!("input/registers_false.in");
|
||||
|
||||
// test true input register => true output register
|
||||
let program = parse_program_with_input(program_string, true_input_string).unwrap();
|
||||
|
||||
output_true(program);
|
||||
|
||||
// test false input register => false output register
|
||||
let program = parse_program_with_input(program_string, false_input_string).unwrap();
|
||||
|
||||
output_false(program);
|
||||
}
|
||||
|
||||
// Boolean not !
|
||||
|
||||
#[test]
|
||||
fn test_not_true() {
|
||||
let program_string = include_str!("not_true.leo");
|
||||
let program = parse_program(program_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_not_false() {
|
||||
let program_string = include_str!("not_false.leo");
|
||||
let program = parse_program(program_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_not_mutable() {
|
||||
let program_string = include_str!("not_mutable.leo");
|
||||
let program = parse_program(program_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_conditional_mut() {
|
||||
let program_string = include_str!("conditional_mut.leo");
|
||||
let program = parse_program(program_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_not_u32() {
|
||||
let program_string = include_str!("not_u32.leo");
|
||||
let error = parse_program(program_string).err().unwrap();
|
||||
|
||||
expect_asg_error(error);
|
||||
}
|
||||
|
||||
// Boolean or ||
|
||||
|
||||
#[test]
|
||||
fn test_true_or_true() {
|
||||
let program_string = include_str!("true_or_true.leo");
|
||||
let program = parse_program(program_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_true_or_false() {
|
||||
let program_string = include_str!("true_or_false.leo");
|
||||
let program = parse_program(program_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_false_or_false() {
|
||||
let program_string = include_str!("false_or_false.leo");
|
||||
let program = parse_program(program_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_true_or_u32() {
|
||||
let program_string = include_str!("true_or_u32.leo");
|
||||
let error = parse_program(program_string).err().unwrap();
|
||||
|
||||
expect_asg_error(error);
|
||||
}
|
||||
|
||||
// Boolean and &&
|
||||
|
||||
#[test]
|
||||
fn test_true_and_true() {
|
||||
let program_string = include_str!("true_and_true.leo");
|
||||
let program = parse_program(program_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_true_and_false() {
|
||||
let program_string = include_str!("true_and_false.leo");
|
||||
let program = parse_program(program_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_false_and_false() {
|
||||
let program_string = include_str!("false_and_false.leo");
|
||||
let program = parse_program(program_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_true_and_u32() {
|
||||
let program_string = include_str!("true_and_u32.leo");
|
||||
let error = parse_program(program_string).err().unwrap();
|
||||
|
||||
expect_asg_error(error);
|
||||
}
|
||||
|
||||
// All
|
||||
|
||||
#[test]
|
||||
fn test_all() {
|
||||
let program_string = include_str!("all.leo");
|
||||
let program = parse_program(program_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
function main() {
|
||||
console.assert(!false == true);
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
function main () {
|
||||
const b = false;
|
||||
const a = !b;
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
function main() {
|
||||
console.assert(!true == false);
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
function main() -> bool {
|
||||
console.assert(!1u32 == 0u32);
|
||||
}
|
@ -1,2 +0,0 @@
|
||||
[registers]
|
||||
r: bool = false;
|
@ -1,2 +0,0 @@
|
||||
[registers]
|
||||
r: bool = true;
|
@ -1,3 +0,0 @@
|
||||
function main() -> bool {
|
||||
return input.registers.r;
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
function main() {
|
||||
const a = true && false;
|
||||
|
||||
console.assert(a == false);
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
function main() {
|
||||
const a = true && true;
|
||||
|
||||
console.assert(a == true);
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
function main() {
|
||||
const a = true && 1u32;
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
function main() {
|
||||
const a = true || false;
|
||||
|
||||
console.assert(a == true);
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
function main() {
|
||||
const a = true || true;
|
||||
|
||||
console.assert(a == true);
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
function main() {
|
||||
const a = true || 1u32;
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
function main() {
|
||||
const a: char = 'a';
|
||||
const B = 'B';
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
circuit Foo {
|
||||
a: char;
|
||||
b: char;
|
||||
c: char;
|
||||
d: char;
|
||||
}
|
||||
|
||||
function main(a: char, b: char, c: char, d: char) {
|
||||
let f = Foo { a, b, c, d };
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
function main() {
|
||||
const newline: char = '\n';
|
||||
const quote = '\'';
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
function b(a: char) -> char {
|
||||
return a;
|
||||
}
|
||||
|
||||
function main() {
|
||||
const b = b('x');
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
function main() {
|
||||
const star = '\x2A';
|
||||
const star = '\x7F';
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
[main]
|
||||
a: char = 'a';
|
||||
b: char = '\'';
|
||||
c: char = '\u{2764}';
|
||||
d: char = '\x2A';
|
@ -1,2 +0,0 @@
|
||||
[registers]
|
||||
r: char = 'a';
|
@ -1,85 +0,0 @@
|
||||
// Copyright (C) 2019-2021 Aleo Systems Inc.
|
||||
// This file is part of the Leo library.
|
||||
|
||||
// The Leo library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// The Leo library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::{assert_satisfied, get_output, parse_program, parse_program_with_input, EdwardsTestCompiler};
|
||||
|
||||
pub fn output_char(program: EdwardsTestCompiler) {
|
||||
let expected = include_bytes!("output/output_char.out");
|
||||
let actual = get_output(program);
|
||||
|
||||
assert_eq!(expected, actual.bytes().as_slice());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_registers() {
|
||||
let program_string = include_str!("output_register.leo");
|
||||
let char_input_string = include_str!("input/char_register.in");
|
||||
|
||||
// test true input register => true output register
|
||||
let program = parse_program_with_input(program_string, char_input_string).unwrap();
|
||||
|
||||
output_char(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_basic() {
|
||||
let program_string = include_str!("basic.leo");
|
||||
let program = parse_program(program_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_circuit() {
|
||||
let program_string = include_str!("circuit.leo");
|
||||
let char_input_string = include_str!("input/char.in");
|
||||
|
||||
let program = parse_program_with_input(program_string, char_input_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_escapes() {
|
||||
let program_string = include_str!("escapes.leo");
|
||||
let program = parse_program(program_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_hex() {
|
||||
let program_string = include_str!("hex.leo");
|
||||
let program = parse_program(program_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_function() {
|
||||
let program_string = include_str!("function.leo");
|
||||
let program = parse_program(program_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_unicode() {
|
||||
let program_string = include_str!("unicode.leo");
|
||||
let program = parse_program(program_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
function main() -> char {
|
||||
return input.registers.r;
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
function main() {
|
||||
const heart: char = '\u{2764}';
|
||||
const Hiragana = '\u{306E}';
|
||||
|
||||
const heart2: char = '❤';
|
||||
const Hiragana2 = 'の';
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
circuit Foo {
|
||||
a: u8;
|
||||
|
||||
function use_a(const self) -> u8 {
|
||||
return self.a + 1;
|
||||
}
|
||||
}
|
||||
|
||||
function main() {
|
||||
let f = Foo { a: 0u8 };
|
||||
|
||||
console.assert(1u8 == f.use_a());
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
circuit Foo {
|
||||
a: u32;
|
||||
}
|
||||
|
||||
circuit Bar {
|
||||
function bar() {
|
||||
const f = Foo { a: 0u32 };
|
||||
}
|
||||
}
|
||||
|
||||
function main() {
|
||||
const b = Bar::bar();
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
circuit Bar {
|
||||
b2: u32;
|
||||
|
||||
function add_five(z:u32) -> u32 {
|
||||
return z+5u32;
|
||||
}
|
||||
}
|
||||
|
||||
function main () {
|
||||
const Bar = 66u32;
|
||||
const k1 = Bar{ b2: 30u32 };
|
||||
const k2 = Bar::add_five(55u32);
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
circuit Foo {
|
||||
x: u32;
|
||||
}
|
||||
|
||||
function main() {
|
||||
const a = Foo { x: 1u32 };
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
circuit Foo {
|
||||
x: u8;
|
||||
|
||||
function new(x: u8) -> Self {
|
||||
return Self { x };
|
||||
}
|
||||
}
|
||||
|
||||
function main() {
|
||||
const x: u8 = 1;
|
||||
const a = Foo { x };
|
||||
const b = Foo::new(x);
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
function main() {
|
||||
const a = Foo { };
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
circuit Foo {
|
||||
x: u32;
|
||||
|
||||
function echo(self) -> u32 {
|
||||
return self.x;
|
||||
}
|
||||
}
|
||||
|
||||
function main() {
|
||||
const a = Foo { x: 1u32 };
|
||||
|
||||
console.assert(a.echo() == 1u32);
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
circuit Foo {
|
||||
x: u32;
|
||||
|
||||
function add_x(self, y: u32) -> u32 {
|
||||
return self.x + y;
|
||||
}
|
||||
|
||||
function call_add_x(self, y: u32) -> u32 {
|
||||
return self.add_x(y);
|
||||
}
|
||||
}
|
||||
|
||||
function main() {
|
||||
const a = Foo { x: 1u32 };
|
||||
const b = a.add_x(1u32);
|
||||
|
||||
console.assert(b == 2u32);
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
circuit Foo {
|
||||
function echo(x: u32) -> u32 {
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
||||
function main() {
|
||||
const a = Foo::echo(1u32);
|
||||
|
||||
console.assert(a == 1u32);
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
circuit Foo {
|
||||
x: u32;
|
||||
}
|
||||
|
||||
function main() {
|
||||
const a = Foo { x: 1u32 };
|
||||
|
||||
console.assert(a.x == 1u32);
|
||||
}
|
@ -1,318 +0,0 @@
|
||||
// Copyright (C) 2019-2021 Aleo Systems Inc.
|
||||
// This file is part of the Leo library.
|
||||
|
||||
// The Leo library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// The Leo library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::{assert_satisfied, expect_asg_error, parse_program};
|
||||
|
||||
// Expressions
|
||||
|
||||
#[test]
|
||||
fn test_inline() {
|
||||
let program_string = include_str!("inline.leo");
|
||||
let program = parse_program(program_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_inline_fail() {
|
||||
let program_string = include_str!("inline_fail.leo");
|
||||
let error = parse_program(program_string).err().unwrap();
|
||||
|
||||
expect_asg_error(error);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_inline_undefined() {
|
||||
let program_string = include_str!("inline_undefined.leo");
|
||||
let error = parse_program(program_string).err().unwrap();
|
||||
|
||||
expect_asg_error(error);
|
||||
}
|
||||
|
||||
// Members
|
||||
|
||||
#[test]
|
||||
fn test_member_variable() {
|
||||
let program_string = include_str!("member_variable.leo");
|
||||
let program = parse_program(program_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_member_variable_fail() {
|
||||
let program_string = include_str!("member_variable_fail.leo");
|
||||
let error = parse_program(program_string).err().unwrap();
|
||||
|
||||
expect_asg_error(error);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_member_variable_and_function() {
|
||||
let program_string = include_str!("member_variable_and_function.leo");
|
||||
let program = parse_program(program_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_member_function() {
|
||||
let program_string = include_str!("member_function.leo");
|
||||
let program = parse_program(program_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_member_function_fail() {
|
||||
let program_string = include_str!("member_function_fail.leo");
|
||||
let error = parse_program(program_string).err().unwrap();
|
||||
|
||||
expect_asg_error(error);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_member_function_invalid() {
|
||||
let program_string = include_str!("member_function_invalid.leo");
|
||||
let error = parse_program(program_string).err().unwrap();
|
||||
|
||||
expect_asg_error(error);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_member_function_nested() {
|
||||
let program_string = include_str!("member_function_nested.leo");
|
||||
let program = parse_program(program_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_member_static_function() {
|
||||
let program_string = include_str!("member_static_function.leo");
|
||||
let program = parse_program(program_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_member_static_function_nested() {
|
||||
let program_string = include_str!("member_static_function_nested.leo");
|
||||
let program = parse_program(program_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_member_static_function_invalid() {
|
||||
let program_string = include_str!("member_static_function_invalid.leo");
|
||||
let error = parse_program(program_string).err().unwrap();
|
||||
|
||||
expect_asg_error(error)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_member_static_function_undefined() {
|
||||
let program_string = include_str!("member_static_function_undefined.leo");
|
||||
let error = parse_program(program_string).err().unwrap();
|
||||
|
||||
expect_asg_error(error)
|
||||
}
|
||||
|
||||
// Constant
|
||||
#[test]
|
||||
fn test_const_self_variable() {
|
||||
let program_string = include_str!("const_self_variable.leo");
|
||||
let program = parse_program(program_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_const_self_variable_fail() {
|
||||
let program_string = include_str!("const_self_variable_fail.leo");
|
||||
let error = parse_program(program_string).err().unwrap();
|
||||
|
||||
expect_asg_error(error);
|
||||
}
|
||||
|
||||
// Mutability
|
||||
|
||||
#[test]
|
||||
fn test_mutate_function_fail() {
|
||||
let program_string = include_str!("mut_function_fail.leo");
|
||||
let error = parse_program(program_string).err().unwrap();
|
||||
|
||||
expect_asg_error(error);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mutate_self_variable() {
|
||||
let program_string = include_str!("mut_self_variable.leo");
|
||||
let program = parse_program(program_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mutate_self_variable_branch() {
|
||||
let program_string = include_str!("mut_self_variable_branch.leo");
|
||||
let program = parse_program(program_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mutate_self_variable_conditional() {
|
||||
let program_string = include_str!("mut_self_variable_conditional.leo");
|
||||
let program = parse_program(program_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mutate_self_variable_fail() {
|
||||
let program_string = include_str!("mut_self_variable_fail.leo");
|
||||
let error = parse_program(program_string).err().unwrap();
|
||||
|
||||
expect_asg_error(error);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mutate_self_function_fail() {
|
||||
let program_string = include_str!("mut_self_function_fail.leo");
|
||||
let error = parse_program(program_string).err().unwrap();
|
||||
|
||||
expect_asg_error(error);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mutate_self_static_function_fail() {
|
||||
let program_string = include_str!("mut_self_static_function_fail.leo");
|
||||
let error = parse_program(program_string).err().unwrap();
|
||||
|
||||
expect_asg_error(error);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mutate_static_function_fail() {
|
||||
let program_string = include_str!("mut_static_function_fail.leo");
|
||||
let error = parse_program(program_string).err().unwrap();
|
||||
|
||||
expect_asg_error(error);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mutate_variable() {
|
||||
let program_string = include_str!("mut_variable.leo");
|
||||
let program = parse_program(program_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mutate_variable_fail() {
|
||||
let program_string = include_str!("mut_variable_fail.leo");
|
||||
let error = parse_program(program_string).err().unwrap();
|
||||
|
||||
expect_asg_error(error);
|
||||
}
|
||||
|
||||
// Self
|
||||
|
||||
#[test]
|
||||
fn test_self_fail() {
|
||||
let program_string = include_str!("self_fail.leo");
|
||||
let error = parse_program(program_string).err().unwrap();
|
||||
|
||||
expect_asg_error(error);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_self_member_pass() {
|
||||
let program_string = include_str!("self_member.leo");
|
||||
let program = parse_program(program_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_self_member_invalid() {
|
||||
let program_string = include_str!("self_member_invalid.leo");
|
||||
let error = parse_program(program_string).err().unwrap();
|
||||
|
||||
expect_asg_error(error);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_self_member_undefined() {
|
||||
let program_string = include_str!("self_member_undefined.leo");
|
||||
let error = parse_program(program_string).err().unwrap();
|
||||
|
||||
expect_asg_error(error);
|
||||
}
|
||||
|
||||
// Inline circuit member
|
||||
|
||||
#[test]
|
||||
fn test_inline_member_pass() {
|
||||
let program_string = include_str!("inline_member_pass.leo");
|
||||
let program = parse_program(program_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_inline_member_fail() {
|
||||
let program_string = include_str!("inline_member_fail.leo");
|
||||
let error = parse_program(program_string).err().unwrap();
|
||||
|
||||
expect_asg_error(error);
|
||||
}
|
||||
|
||||
// All
|
||||
|
||||
#[test]
|
||||
fn test_pedersen_mock() {
|
||||
let program_string = include_str!("pedersen_mock.leo");
|
||||
let program = parse_program(program_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_define_circuit_inside_circuit_function() {
|
||||
let program_string = include_str!("define_circuit_inside_circuit_function.leo");
|
||||
let program = parse_program(program_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_duplicate_name_context() {
|
||||
let program_string = include_str!("duplicate_name_context.leo");
|
||||
let program = parse_program(program_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mutable_call_immutable_context() {
|
||||
let program_string = include_str!("mutable_call_immutable_context.leo");
|
||||
let program = parse_program(program_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
circuit Foo {
|
||||
a: u8;
|
||||
}
|
||||
|
||||
function main() {
|
||||
let f = Foo { a: 0u8 };
|
||||
|
||||
console.assert(f.a == 0u8);
|
||||
|
||||
f.a = 1u8;
|
||||
|
||||
console.assert(f.a == 1u8);
|
||||
|
||||
f.a = 2u8;
|
||||
|
||||
console.assert(f.a == 2u8);
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
function main() {
|
||||
Self::main();
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
function main() {
|
||||
const a: u32 = 1 + 2;
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
// Copyright (C) 2019-2021 Aleo Systems Inc.
|
||||
// This file is part of the Leo library.
|
||||
|
||||
// The Leo library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// The Leo library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::{get_output, EdwardsTestCompiler};
|
||||
|
||||
use std::{env::current_dir, path::PathBuf};
|
||||
|
||||
static MAIN_FILE_NAME: &str = "tests/compiler/main.leo";
|
||||
|
||||
// Compiler tests rely on knowledge of local directories. They should be run locally only.
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn test_parse_program_from_string() {
|
||||
// Parse program from string with compiler.
|
||||
let program_string = include_str!("main.leo");
|
||||
let context = crate::make_test_context();
|
||||
let mut compiler_no_path = EdwardsTestCompiler::new("".to_string(), PathBuf::new(), PathBuf::new(), context, None);
|
||||
|
||||
compiler_no_path.parse_program_from_string(program_string).unwrap();
|
||||
|
||||
// Parse program from file path with compiler.
|
||||
let mut local = current_dir().unwrap();
|
||||
local.push(MAIN_FILE_NAME);
|
||||
|
||||
let compiler_with_path =
|
||||
EdwardsTestCompiler::parse_program_without_input("".to_string(), local, PathBuf::new(), context, None).unwrap();
|
||||
|
||||
// Compare output bytes.
|
||||
let expected_output = get_output(compiler_no_path);
|
||||
let actual_output = get_output(compiler_with_path);
|
||||
|
||||
assert_eq!(expected_output, actual_output);
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
function main(a: bool) {
|
||||
console.assert(a == true);
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
function main(a: bool) {
|
||||
if a {
|
||||
console.assert(a == true);
|
||||
} else {
|
||||
console.assert(a == false);
|
||||
}
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
function main() {
|
||||
console.debug("hello debug");
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
function main() {
|
||||
console.error("hello error");
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user