mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-11-24 07:48:04 +03:00
use include_str in program input tests
This commit is contained in:
parent
b2246f1151
commit
675937ba13
@ -18,27 +18,27 @@ use crate::{assert_satisfied, parse_input_and_state, parse_program_with_input_an
|
||||
|
||||
#[test]
|
||||
fn test_basic() {
|
||||
let input_bytes = include_bytes!("input/basic.in");
|
||||
let state_bytes = include_bytes!("input/basic.state");
|
||||
let input_string = include_str!("input/basic.in");
|
||||
let state_string = include_str!("input/basic.state");
|
||||
|
||||
parse_input_and_state(input_bytes, state_bytes).unwrap();
|
||||
parse_input_and_state(input_string, state_string).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_full() {
|
||||
let input_bytes = include_bytes!("input/token_withdraw.in");
|
||||
let state_bytes = include_bytes!("input/token_withdraw.state");
|
||||
let input_string = include_str!("input/token_withdraw.in");
|
||||
let state_string = include_str!("input/token_withdraw.state");
|
||||
|
||||
parse_input_and_state(input_bytes, state_bytes).unwrap();
|
||||
parse_input_and_state(input_string, state_string).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_access() {
|
||||
let program_bytes = include_bytes!("access.leo");
|
||||
let input_bytes = include_bytes!("input/token_withdraw.in");
|
||||
let state_bytes = include_bytes!("input/token_withdraw.state");
|
||||
let program_string = include_str!("access.leo");
|
||||
let input_string = include_str!("input/token_withdraw.in");
|
||||
let state_string = include_str!("input/token_withdraw.state");
|
||||
|
||||
let program = parse_program_with_input_and_state(program_bytes, input_bytes, state_bytes).unwrap();
|
||||
let program = parse_program_with_input_and_state(program_strin, input_string, state_string).unwrap();
|
||||
|
||||
assert_satisfied(program);
|
||||
}
|
||||
|
@ -73,12 +73,11 @@ pub(crate) fn parse_program(bytes: &[u8]) -> Result<EdwardsTestCompiler, Compile
|
||||
Ok(compiler)
|
||||
}
|
||||
|
||||
pub(crate) fn parse_input(bytes: &[u8]) -> Result<EdwardsTestCompiler, CompilerError> {
|
||||
pub(crate) fn parse_input(input_string: &str) -> Result<EdwardsTestCompiler, CompilerError> {
|
||||
let mut compiler = new_compiler();
|
||||
let input_string = String::from_utf8_lossy(bytes);
|
||||
let path = PathBuf::new();
|
||||
|
||||
compiler.parse_input(&input_string, &path, EMPTY_FILE, &path)?;
|
||||
compiler.parse_input(input_string, &path, EMPTY_FILE, &path)?;
|
||||
|
||||
Ok(compiler)
|
||||
}
|
||||
@ -87,21 +86,19 @@ pub(crate) fn parse_state(state_string: &str) -> Result<EdwardsTestCompiler, Com
|
||||
let mut compiler = new_compiler();
|
||||
let path = PathBuf::new();
|
||||
|
||||
compiler.parse_input(EMPTY_FILE, &path, &state_string, &path)?;
|
||||
compiler.parse_input(EMPTY_FILE, &path, state_string, &path)?;
|
||||
|
||||
Ok(compiler)
|
||||
}
|
||||
|
||||
pub(crate) fn parse_input_and_state(
|
||||
input_bytes: &[u8],
|
||||
state_bytes: &[u8],
|
||||
input_string: &str,
|
||||
state_string: &str,
|
||||
) -> Result<EdwardsTestCompiler, CompilerError> {
|
||||
let mut compiler = new_compiler();
|
||||
let input_string = String::from_utf8_lossy(input_bytes);
|
||||
let state_string = String::from_utf8_lossy(state_bytes);
|
||||
let path = PathBuf::new();
|
||||
|
||||
compiler.parse_input(&input_string, &path, &state_string, &path)?;
|
||||
compiler.parse_input(input_string, &path, state_string, &path)?;
|
||||
|
||||
Ok(compiler)
|
||||
}
|
||||
@ -127,9 +124,6 @@ pub fn parse_program_with_state(
|
||||
state_string: &str,
|
||||
) -> Result<EdwardsTestCompiler, CompilerError> {
|
||||
let mut compiler = new_compiler();
|
||||
|
||||
// let program_string = String::from_utf8_lossy(program_bytes);
|
||||
// let state_string = String::from_utf8_lossy(state_bytes);
|
||||
let path = PathBuf::new();
|
||||
|
||||
compiler.parse_input(EMPTY_FILE, &path, state_string, &path)?;
|
||||
@ -139,18 +133,14 @@ pub fn parse_program_with_state(
|
||||
}
|
||||
|
||||
pub fn parse_program_with_input_and_state(
|
||||
program_bytes: &[u8],
|
||||
input_bytes: &[u8],
|
||||
state_bytes: &[u8],
|
||||
program_string: &str,
|
||||
input_string: &str,
|
||||
state_string: &str,
|
||||
) -> Result<EdwardsTestCompiler, CompilerError> {
|
||||
let mut compiler = new_compiler();
|
||||
|
||||
let program_string = String::from_utf8_lossy(program_bytes);
|
||||
let input_string = String::from_utf8_lossy(input_bytes);
|
||||
let state_string = String::from_utf8_lossy(state_bytes);
|
||||
let path = PathBuf::new();
|
||||
|
||||
compiler.parse_input(&input_string, &path, &state_string, &path)?;
|
||||
compiler.parse_input(input_string, &path, state_string, &path)?;
|
||||
compiler.parse_program_from_string(&program_string)?;
|
||||
|
||||
Ok(compiler)
|
||||
|
@ -63,10 +63,9 @@ fn test_undefined() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn input_syntax_error() {
|
||||
let bytes = include_bytes!("input_semicolon.leo");
|
||||
let error = parse_input(bytes).err().unwrap();
|
||||
let input_string = include_str!("input_semicolon.leo");
|
||||
let error = parse_input(input_string).err().unwrap();
|
||||
|
||||
// Expect an input parser error.
|
||||
match error {
|
||||
|
Loading…
Reference in New Issue
Block a user