leo/asg/tests/pass/form_ast.rs

91 lines
2.6 KiB
Rust
Raw Normal View History

2021-02-02 07:26:56 +03:00
// Copyright (C) 2019-2021 Aleo Systems Inc.
2021-01-25 18:17:42 +03:00
// 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/>.
2021-02-25 18:40:47 +03:00
use crate::{load_asg, make_test_context};
use leo_parser::parse_ast;
2021-01-25 18:17:42 +03:00
#[test]
fn test_basic() {
let program_string = include_str!("./circuits/pedersen_mock.leo");
2021-02-25 18:40:47 +03:00
let asg = load_asg(program_string).unwrap();
2021-01-25 18:17:42 +03:00
let reformed_ast = leo_asg::reform_ast(&asg);
println!("{}", reformed_ast);
2021-01-25 21:26:13 +03:00
// panic!();
2021-01-25 18:17:42 +03:00
}
#[test]
fn test_function_rename() {
let program_string = r#"
function iteration() -> u32 {
let a = 0u32;
2021-01-25 18:17:42 +03:00
for i in 0..10 {
a += 1;
}
return a
}
function main() {
const total = iteration() + iteration();
2021-01-25 18:17:42 +03:00
console.assert(total == 20);
}
"#;
2021-02-25 18:40:47 +03:00
let asg = load_asg(program_string).unwrap();
2021-01-25 18:17:42 +03:00
let reformed_ast = leo_asg::reform_ast(&asg);
println!("{}", reformed_ast);
2021-01-25 21:26:13 +03:00
// panic!();
2021-01-25 18:17:42 +03:00
}
#[test]
fn test_imports() {
let import_name = "test-import".to_string();
2021-02-25 18:40:47 +03:00
let context = make_test_context();
let mut imports = crate::mocked_resolver(&context);
2021-01-25 18:17:42 +03:00
let test_import = r#"
circuit Point {
x: u32
y: u32
}
function foo() -> u32 {
return 1u32
}
"#;
imports
.packages
.insert(import_name.clone(), load_asg(test_import).unwrap());
2021-01-25 18:17:42 +03:00
let program_string = r#"
import test-import.foo;
function main() {
console.assert(foo() == 1u32);
}
"#;
let test_import_ast = parse_ast(&import_name, test_import).unwrap();
println!("{}", serde_json::to_string(test_import_ast.as_repr()).unwrap());
let test_ast = parse_ast("test.leo", program_string).unwrap();
println!("{}", serde_json::to_string(test_ast.as_repr()).unwrap());
let asg = crate::load_asg_imports(&context, program_string, &mut imports).unwrap();
2021-01-25 18:17:42 +03:00
let reformed_ast = leo_asg::reform_ast(&asg);
println!("{}", serde_json::to_string(&reformed_ast).unwrap());
2021-01-25 21:26:13 +03:00
// panic!();
2021-01-25 18:17:42 +03:00
}