mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-12-24 18:52:58 +03:00
undeprecate parse_program_from_string and add test
This commit is contained in:
parent
65b77be8ac
commit
ca36d06022
@ -229,9 +229,6 @@ impl<F: Field + PrimeField, G: GroupType<F>> Compiler<F, G> {
|
||||
/// Equivalent to parse_and_check_program but uses the given program_string instead of a main
|
||||
/// file path.
|
||||
///
|
||||
/// Used for testing only.
|
||||
///
|
||||
#[deprecated(note = "Please use the 'parse_program' method instead.")]
|
||||
pub fn parse_program_from_string(&mut self, program_string: &str) -> Result<(), CompilerError> {
|
||||
// Use the given bytes to construct the abstract syntax tree.
|
||||
let ast = Grammar::new(&self.main_file_path, &program_string).map_err(|mut e| {
|
||||
|
3
compiler/tests/compiler/main.leo
Normal file
3
compiler/tests/compiler/main.leo
Normal file
@ -0,0 +1,3 @@
|
||||
function main() {
|
||||
let a: u32 = 1 + 2;
|
||||
}
|
46
compiler/tests/compiler/mod.rs
Normal file
46
compiler/tests/compiler/mod.rs
Normal file
@ -0,0 +1,46 @@
|
||||
// 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 crate::{assert_satisfied, get_output, parse_program, EdwardsTestCompiler};
|
||||
|
||||
use std::{env::current_dir, path::PathBuf};
|
||||
|
||||
static MAIN_FILE_NAME: &str = "tests/compiler/main.leo";
|
||||
|
||||
// Compiler tests rely on knowledge of local directories. They should be run locally only.
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn test_parse_program_from_string() {
|
||||
// Parse program from string with compiler.
|
||||
let program_string = include_str!("main.leo");
|
||||
let mut compiler_no_path = EdwardsTestCompiler::new("".to_string(), PathBuf::new(), PathBuf::new());
|
||||
|
||||
compiler_no_path.parse_program_from_string(program_string).unwrap();
|
||||
|
||||
// Parse program from file path with compiler.
|
||||
let mut local = current_dir().unwrap();
|
||||
local.push(MAIN_FILE_NAME);
|
||||
|
||||
let compiler_with_path =
|
||||
EdwardsTestCompiler::parse_program_without_input("".to_string(), local, PathBuf::new()).unwrap();
|
||||
|
||||
// Compare output bytes.
|
||||
let expected_output = get_output(compiler_no_path);
|
||||
let actual_output = get_output(compiler_with_path);
|
||||
|
||||
assert_eq!(expected_output, actual_output);
|
||||
}
|
@ -21,6 +21,7 @@ pub mod address;
|
||||
pub mod array;
|
||||
pub mod boolean;
|
||||
pub mod circuits;
|
||||
pub mod compiler;
|
||||
pub mod console;
|
||||
pub mod core;
|
||||
pub mod definition;
|
||||
|
Loading…
Reference in New Issue
Block a user