2020-10-07 03:20:51 +03:00
|
|
|
// Copyright (C) 2019-2020 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 leo_ast::LeoAst;
|
|
|
|
use leo_dynamic_check::DynamicCheck;
|
|
|
|
|
2020-10-13 19:06:52 +03:00
|
|
|
use leo_static_check::StaticCheck;
|
2020-10-07 03:20:51 +03:00
|
|
|
use leo_typed::LeoTypedAst;
|
|
|
|
use std::path::PathBuf;
|
|
|
|
|
|
|
|
const TEST_PROGRAM_PATH: &str = "";
|
|
|
|
const TEST_PROGRAM_NAME: &str = "test";
|
|
|
|
|
|
|
|
/// A helper struct to test a `DynamicCheck`.
|
|
|
|
pub struct TestDynamicCheck {
|
|
|
|
dynamic_check: DynamicCheck,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TestDynamicCheck {
|
|
|
|
pub fn new(bytes: &[u8]) -> Self {
|
|
|
|
// Get file string from bytes.
|
|
|
|
let file_string = String::from_utf8_lossy(bytes);
|
|
|
|
|
|
|
|
// Get test file path.
|
|
|
|
let file_path = PathBuf::from(TEST_PROGRAM_PATH);
|
|
|
|
|
|
|
|
// Get parser syntax tree.
|
|
|
|
let ast = LeoAst::new(&file_path, &*file_string).unwrap();
|
|
|
|
|
|
|
|
// Get typed syntax tree.
|
|
|
|
let typed = LeoTypedAst::new(TEST_PROGRAM_NAME, &ast);
|
|
|
|
let program = typed.into_repr();
|
|
|
|
|
2020-10-13 19:06:52 +03:00
|
|
|
// Create static check.
|
2020-10-27 01:51:46 +03:00
|
|
|
let symbol_table = StaticCheck::run_with_input(&program).unwrap();
|
2020-10-07 03:20:51 +03:00
|
|
|
|
|
|
|
// Create dynamic check
|
2020-10-24 03:00:11 +03:00
|
|
|
let dynamic_check = DynamicCheck::new(&program, symbol_table).unwrap();
|
2020-10-07 03:20:51 +03:00
|
|
|
|
|
|
|
Self { dynamic_check }
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn solve(self) {
|
2020-10-22 22:40:35 +03:00
|
|
|
self.dynamic_check.solve().unwrap();
|
2020-10-07 03:20:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_new() {
|
|
|
|
let bytes = include_bytes!("empty.leo");
|
|
|
|
|
|
|
|
let dynamic_check = TestDynamicCheck::new(bytes);
|
|
|
|
|
|
|
|
dynamic_check.solve()
|
|
|
|
}
|