2020-06-21 01:24:46 +03:00
|
|
|
use crate::{
|
2020-07-30 10:56:17 +03:00
|
|
|
assert_satisfied,
|
2020-07-30 21:11:54 +03:00
|
|
|
expect_compiler_error,
|
2020-07-30 10:56:17 +03:00
|
|
|
get_outputs,
|
2020-06-21 01:24:46 +03:00
|
|
|
parse_program,
|
2020-08-01 05:39:30 +03:00
|
|
|
parse_program_with_input,
|
2020-06-21 01:24:46 +03:00
|
|
|
EdwardsTestCompiler,
|
|
|
|
};
|
2020-05-20 03:08:38 +03:00
|
|
|
|
2020-07-30 10:56:17 +03:00
|
|
|
pub fn output_ones(program: EdwardsTestCompiler) {
|
2020-07-30 21:11:54 +03:00
|
|
|
let expected = include_bytes!("outputs_/registers_ones.out");
|
2020-07-30 10:56:17 +03:00
|
|
|
let actual = get_outputs(program);
|
2020-05-20 03:08:38 +03:00
|
|
|
|
2020-07-30 10:56:17 +03:00
|
|
|
assert!(expected.eq(actual.bytes().as_slice()));
|
2020-05-20 03:08:38 +03:00
|
|
|
}
|
|
|
|
|
2020-07-30 10:56:17 +03:00
|
|
|
pub fn output_zeros(program: EdwardsTestCompiler) {
|
2020-07-30 21:11:54 +03:00
|
|
|
let expected = include_bytes!("outputs_/registers_zeros.out");
|
2020-07-30 10:56:17 +03:00
|
|
|
let actual = get_outputs(program);
|
|
|
|
|
|
|
|
assert!(expected.eq(actual.bytes().as_slice()));
|
2020-06-11 02:14:55 +03:00
|
|
|
}
|
|
|
|
|
2020-07-30 10:56:17 +03:00
|
|
|
// Registers
|
2020-05-20 03:08:38 +03:00
|
|
|
|
|
|
|
#[test]
|
2020-07-30 10:56:17 +03:00
|
|
|
fn test_registers() {
|
|
|
|
let program_bytes = include_bytes!("registers.leo");
|
|
|
|
let ones_input_bytes = include_bytes!("inputs/registers_ones.in");
|
|
|
|
let zeros_input_bytes = include_bytes!("inputs/registers_zeros.in");
|
|
|
|
|
|
|
|
// test ones input register => ones output register
|
2020-08-01 05:39:30 +03:00
|
|
|
let program = parse_program_with_input(program_bytes, ones_input_bytes).unwrap();
|
2020-06-09 03:51:06 +03:00
|
|
|
|
2020-05-20 03:08:38 +03:00
|
|
|
output_ones(program);
|
|
|
|
|
2020-07-30 10:56:17 +03:00
|
|
|
// test zeros input register => zeros output register
|
2020-08-01 05:39:30 +03:00
|
|
|
let program = parse_program_with_input(program_bytes, zeros_input_bytes).unwrap();
|
2020-06-09 03:51:06 +03:00
|
|
|
|
2020-07-30 10:56:17 +03:00
|
|
|
output_zeros(program);
|
2020-05-20 03:08:38 +03:00
|
|
|
}
|
|
|
|
|
2020-07-30 10:56:17 +03:00
|
|
|
// Expressions
|
|
|
|
|
2020-05-20 03:08:38 +03:00
|
|
|
#[test]
|
2020-07-30 10:56:17 +03:00
|
|
|
fn test_inline() {
|
|
|
|
let program_bytes = include_bytes!("inline.leo");
|
|
|
|
let input_bytes = include_bytes!("inputs/three_ones.in");
|
2020-08-01 05:39:30 +03:00
|
|
|
let program = parse_program_with_input(program_bytes, input_bytes).unwrap();
|
2020-06-09 03:51:06 +03:00
|
|
|
|
2020-07-30 10:56:17 +03:00
|
|
|
assert_satisfied(program);
|
2020-05-20 03:08:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-07-30 10:56:17 +03:00
|
|
|
fn test_inline_fail() {
|
|
|
|
let program_bytes = include_bytes!("inline.leo");
|
|
|
|
let program = parse_program(program_bytes).unwrap();
|
2020-06-09 03:51:06 +03:00
|
|
|
|
2020-07-30 21:11:54 +03:00
|
|
|
let _err = expect_compiler_error(program);
|
2020-05-20 03:08:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-07-30 10:56:17 +03:00
|
|
|
fn test_initializer() {
|
|
|
|
let program_bytes = include_bytes!("initializer.leo");
|
|
|
|
let input_bytes = include_bytes!("inputs/three_ones.in");
|
2020-08-01 05:39:30 +03:00
|
|
|
let program = parse_program_with_input(program_bytes, input_bytes).unwrap();
|
2020-06-09 03:51:06 +03:00
|
|
|
|
2020-07-30 10:56:17 +03:00
|
|
|
assert_satisfied(program);
|
2020-05-20 03:08:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-07-30 10:56:17 +03:00
|
|
|
fn test_spread() {
|
|
|
|
let program_bytes = include_bytes!("spread.leo");
|
|
|
|
let input_bytes = include_bytes!("inputs/three_ones.in");
|
2020-08-01 05:39:30 +03:00
|
|
|
let program = parse_program_with_input(program_bytes, input_bytes).unwrap();
|
2020-06-09 03:51:06 +03:00
|
|
|
|
2020-07-30 10:56:17 +03:00
|
|
|
assert_satisfied(program);
|
2020-05-20 03:08:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-07-30 10:56:17 +03:00
|
|
|
fn test_slice() {
|
|
|
|
let program_bytes = include_bytes!("slice.leo");
|
|
|
|
let input_bytes = include_bytes!("inputs/three_ones.in");
|
2020-08-01 05:39:30 +03:00
|
|
|
let program = parse_program_with_input(program_bytes, input_bytes).unwrap();
|
2020-06-09 03:51:06 +03:00
|
|
|
|
2020-07-30 10:56:17 +03:00
|
|
|
assert_satisfied(program);
|
2020-05-20 03:08:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-07-30 10:56:17 +03:00
|
|
|
fn test_multi() {
|
|
|
|
let program_bytes = include_bytes!("multi.leo");
|
|
|
|
let program = parse_program(program_bytes).unwrap();
|
2020-06-09 03:51:06 +03:00
|
|
|
|
2020-07-30 10:56:17 +03:00
|
|
|
assert_satisfied(program);
|
2020-05-20 03:08:38 +03:00
|
|
|
}
|