add macro tests

This commit is contained in:
collin 2020-07-09 19:23:15 -07:00
parent cd38e3a476
commit 118b50fb58
13 changed files with 108 additions and 4 deletions

View File

@ -549,7 +549,9 @@ test function expect_fail() {
Leo supports `print!`, `debug!`, and `error!` logging macros.
Macros support string formatting arguments `[macro]!("{} {}", [argument_1], [argument_2])`
The first argument a macro receives is a format string. This must be a string literal. The power of the formatting string is in the `{}`s contained.
Additional parameters passed to a macro replace the `{}`s within the formatting string in the order given.
#### `print!`
Directly calls the `println!` macro in rust.
@ -569,7 +571,7 @@ function main(a: u32) {
#### `error!`
Halts program execution and prints to console.
Prints the error to console.
```js
function main(a: u32) {
error!("a is {}", a);

View File

@ -22,8 +22,8 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
.unwrap_or(Ok("".to_string()))?;
match macro_.name {
MacroName::Debug(_) => log::debug!("{}\n", string),
MacroName::Error(_) => log::error!("{}\n", string),
MacroName::Debug(_) => log::debug!("{}", string),
MacroName::Error(_) => log::error!("{}", string),
MacroName::Print(_) => println!("{}", string),
}

View File

@ -0,0 +1,3 @@
function main() {
debug!("hello debug");
}

View File

@ -0,0 +1,3 @@
function main() {
error!("hello error");
}

View File

@ -0,0 +1,74 @@
use crate::{get_error, get_output, parse_program};
use leo_types::InputValue;
#[test]
fn test_print() {
let bytes = include_bytes!("print.leo");
let program = parse_program(bytes).unwrap();
let _output = get_output(program);
}
#[test]
fn test_print_fail() {
let bytes = include_bytes!("print_fail.leo");
assert!(parse_program(bytes).is_err());
}
#[test]
fn test_print_parameter() {
let bytes = include_bytes!("print_parameter.leo");
let program = parse_program(bytes).unwrap();
let _output = get_output(program);
}
#[test]
fn test_print_parameter_many() {
let bytes = include_bytes!("print_parameter_many.leo");
let program = parse_program(bytes).unwrap();
let _output = get_output(program);
}
#[test]
fn test_print_parameter_fail_empty() {
let bytes = include_bytes!("print_parameter_fail_empty.leo");
let program = parse_program(bytes).unwrap();
let _err = get_error(program);
}
#[test]
fn test_print_parameter_fail_none() {
let bytes = include_bytes!("print_parameter_fail_empty.leo");
let program = parse_program(bytes).unwrap();
let _err = get_error(program);
}
#[test]
fn test_print_input() {
let bytes = include_bytes!("print_input.leo");
let mut program = parse_program(bytes).unwrap();
program.set_inputs(vec![Some(InputValue::Boolean(true))]);
let _output = get_output(program);
}
#[test]
fn test_debug() {
let bytes = include_bytes!("debug.leo");
let program = parse_program(bytes).unwrap();
let _output = get_output(program);
}
#[test]
fn test_error() {
let bytes = include_bytes!("error.leo");
let program = parse_program(bytes).unwrap();
let _output = get_output(program);
}

View File

@ -0,0 +1,3 @@
function main() {
print!("hello world");
}

View File

@ -0,0 +1,3 @@
function main() {
print!( hello );
}

View File

@ -0,0 +1,3 @@
function main(b: bool) {
print!("b = {}", b);
}

View File

@ -0,0 +1,3 @@
function main() {
print!("{}", 1u32);
}

View File

@ -0,0 +1,3 @@
function main() {
print!("{}");
}

View File

@ -0,0 +1,3 @@
function main() {
print!("", 1u32);
}

View File

@ -0,0 +1,3 @@
function main() {
print!("{} {}", 1u32, true);
}

View File

@ -8,6 +8,7 @@ pub mod group;
pub mod import;
pub mod inputs;
pub mod integers;
pub mod macros;
pub mod mutability;
pub mod statements;
pub mod syntax;