leo/asg/tests/pass/import/mod.rs

159 lines
5.1 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-11 19:38:08 +03:00
use leo_asg::new_context;
2021-01-25 18:17:42 +03:00
use crate::{load_asg, load_asg_imports, mocked_resolver};
#[test]
fn test_basic() {
let context = new_context();
let mut imports = mocked_resolver(&context);
2021-01-25 18:17:42 +03:00
imports.packages.insert(
"test-import".to_string(),
load_asg(&context, include_str!("src/test-import.leo")).unwrap(),
2021-01-25 18:17:42 +03:00
);
let program_string = include_str!("basic.leo");
load_asg_imports(&context, program_string, &mut imports).unwrap();
2021-01-25 18:17:42 +03:00
}
#[test]
fn test_multiple() {
let context = new_context();
let mut imports = mocked_resolver(&context);
2021-01-25 18:17:42 +03:00
imports.packages.insert(
"test-import".to_string(),
load_asg(&context, include_str!("src/test-import.leo")).unwrap(),
2021-01-25 18:17:42 +03:00
);
let program_string = include_str!("multiple.leo");
load_asg_imports(&context, program_string, &mut imports).unwrap();
2021-01-25 18:17:42 +03:00
}
#[test]
fn test_star() {
let context = new_context();
let mut imports = mocked_resolver(&context);
2021-01-25 18:17:42 +03:00
imports.packages.insert(
"test-import".to_string(),
load_asg(&context, include_str!("src/test-import.leo")).unwrap(),
2021-01-25 18:17:42 +03:00
);
let program_string = include_str!("star.leo");
load_asg_imports(&context, program_string, &mut imports).unwrap();
2021-01-25 18:17:42 +03:00
}
#[test]
fn test_alias() {
let context = new_context();
let mut imports = mocked_resolver(&context);
2021-01-25 18:17:42 +03:00
imports.packages.insert(
"test-import".to_string(),
load_asg(&context, include_str!("src/test-import.leo")).unwrap(),
2021-01-25 18:17:42 +03:00
);
let program_string = include_str!("alias.leo");
load_asg_imports(&context, program_string, &mut imports).unwrap();
2021-01-25 18:17:42 +03:00
}
// naming tests
#[test]
fn test_name() {
let context = new_context();
let mut imports = mocked_resolver(&context);
2021-01-25 18:17:42 +03:00
imports.packages.insert(
"hello-world".to_string(),
load_asg(&context, include_str!("src/hello-world.leo")).unwrap(),
2021-02-11 19:38:08 +03:00
);
imports.packages.insert(
"a0-f".to_string(),
load_asg(&context, include_str!("src/a0-f.leo")).unwrap(),
);
imports.packages.insert(
"a-9".to_string(),
load_asg(&context, include_str!("src/a-9.leo")).unwrap(),
2021-01-25 18:17:42 +03:00
);
let program_string = include_str!("names.leo");
load_asg_imports(&context, program_string, &mut imports).unwrap();
2021-01-25 18:17:42 +03:00
}
// more complex tests
#[test]
fn test_many_import() {
let context = new_context();
let mut imports = mocked_resolver(&context);
2021-01-25 18:17:42 +03:00
imports.packages.insert(
"test-import".to_string(),
load_asg(&context, include_str!("src/test-import.leo")).unwrap(),
2021-01-25 18:17:42 +03:00
);
imports.packages.insert(
"bar".to_string(),
load_asg(&context, include_str!("imports/bar/src/lib.leo")).unwrap(),
2021-01-25 18:17:42 +03:00
);
imports.packages.insert(
"bar.baz".to_string(),
load_asg(&context, include_str!("imports/bar/src/baz.leo")).unwrap(),
2021-01-25 18:17:42 +03:00
);
imports.packages.insert(
"bar.baz".to_string(),
load_asg(&context, include_str!("imports/bar/src/baz.leo")).unwrap(),
2021-01-25 18:17:42 +03:00
);
imports.packages.insert(
"bar.bat.bat".to_string(),
load_asg(&context, include_str!("imports/bar/src/bat/bat.leo")).unwrap(),
2021-01-25 18:17:42 +03:00
);
imports.packages.insert(
"car".to_string(),
load_asg(&context, include_str!("imports/car/src/lib.leo")).unwrap(),
2021-01-25 18:17:42 +03:00
);
let program_string = include_str!("many_import.leo");
load_asg_imports(&context, program_string, &mut imports).unwrap();
2021-01-25 18:17:42 +03:00
}
#[test]
fn test_many_import_star() {
let context = new_context();
let mut imports = mocked_resolver(&context);
2021-01-25 18:17:42 +03:00
imports.packages.insert(
"test-import".to_string(),
load_asg(&context, include_str!("src/test-import.leo")).unwrap(),
2021-01-25 18:17:42 +03:00
);
imports.packages.insert(
"bar".to_string(),
load_asg(&context, include_str!("imports/bar/src/lib.leo")).unwrap(),
2021-01-25 18:17:42 +03:00
);
imports.packages.insert(
"bar.baz".to_string(),
load_asg(&context, include_str!("imports/bar/src/baz.leo")).unwrap(),
2021-01-25 18:17:42 +03:00
);
imports.packages.insert(
"bar.baz".to_string(),
load_asg(&context, include_str!("imports/bar/src/baz.leo")).unwrap(),
2021-01-25 18:17:42 +03:00
);
imports.packages.insert(
"bar.bat.bat".to_string(),
load_asg(&context, include_str!("imports/bar/src/bat/bat.leo")).unwrap(),
2021-01-25 18:17:42 +03:00
);
imports.packages.insert(
"car".to_string(),
load_asg(&context, include_str!("imports/car/src/lib.leo")).unwrap(),
2021-01-25 18:17:42 +03:00
);
let program_string = include_str!("many_import_star.leo");
load_asg_imports(&context, program_string, &mut imports).unwrap();
2021-01-25 18:17:42 +03:00
}