mirror of
https://github.com/AleoHQ/leo.git
synced 2024-12-30 05:02:04 +03:00
23 lines
719 B
Rust
23 lines
719 B
Rust
|
use leo_ast::LeoAst;
|
||
|
|
||
|
use std::path::PathBuf;
|
||
|
|
||
|
#[test]
|
||
|
fn test_serialization() {
|
||
|
let mut program_filepath = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||
|
program_filepath.push("tests/serialization/main.leo");
|
||
|
|
||
|
let expected = include_str!("./expected_ast.json");
|
||
|
|
||
|
// Loads the Leo code as a string from the given file path.
|
||
|
let program_string = LeoAst::load_file(&program_filepath).unwrap();
|
||
|
|
||
|
// Parses the Leo file and constructs an abstract syntax tree.
|
||
|
let ast = LeoAst::new(&program_filepath, &program_string).unwrap();
|
||
|
|
||
|
// Serializes the abstract syntax tree into JSON format.
|
||
|
let serialized_ast = LeoAst::to_json_string(&ast).unwrap();
|
||
|
|
||
|
assert_eq!(expected, serialized_ast);
|
||
|
}
|