mirror of
https://github.com/AleoHQ/leo.git
synced 2024-09-17 18:17:49 +03:00
add macro tests
This commit is contained in:
parent
cd38e3a476
commit
118b50fb58
@ -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);
|
||||
|
@ -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),
|
||||
}
|
||||
|
||||
|
3
compiler/tests/macros/debug.leo
Normal file
3
compiler/tests/macros/debug.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main() {
|
||||
debug!("hello debug");
|
||||
}
|
3
compiler/tests/macros/error.leo
Normal file
3
compiler/tests/macros/error.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main() {
|
||||
error!("hello error");
|
||||
}
|
74
compiler/tests/macros/mod.rs
Normal file
74
compiler/tests/macros/mod.rs
Normal 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);
|
||||
}
|
3
compiler/tests/macros/print.leo
Normal file
3
compiler/tests/macros/print.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main() {
|
||||
print!("hello world");
|
||||
}
|
3
compiler/tests/macros/print_fail.leo
Normal file
3
compiler/tests/macros/print_fail.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main() {
|
||||
print!( hello );
|
||||
}
|
3
compiler/tests/macros/print_input.leo
Normal file
3
compiler/tests/macros/print_input.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main(b: bool) {
|
||||
print!("b = {}", b);
|
||||
}
|
3
compiler/tests/macros/print_parameter.leo
Normal file
3
compiler/tests/macros/print_parameter.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main() {
|
||||
print!("{}", 1u32);
|
||||
}
|
3
compiler/tests/macros/print_parameter_fail_empty.leo
Normal file
3
compiler/tests/macros/print_parameter_fail_empty.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main() {
|
||||
print!("{}");
|
||||
}
|
3
compiler/tests/macros/print_parameter_fail_none.leo
Normal file
3
compiler/tests/macros/print_parameter_fail_none.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main() {
|
||||
print!("", 1u32);
|
||||
}
|
3
compiler/tests/macros/print_parameter_many.leo
Normal file
3
compiler/tests/macros/print_parameter_many.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main() {
|
||||
print!("{} {}", 1u32, true);
|
||||
}
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user