mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-02 08:11:12 +00:00
Test loading with builtins
This commit is contained in:
parent
f2f02817ea
commit
2387862d87
2 changed files with 88 additions and 19 deletions
|
@ -191,3 +191,8 @@ where
|
|||
pub fn fixtures_dir<'a>() -> PathBuf {
|
||||
Path::new("tests").join("fixtures").join("build")
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn builtins_dir<'a>() -> PathBuf {
|
||||
PathBuf::new().join("builtins")
|
||||
}
|
||||
|
|
|
@ -11,8 +11,9 @@ mod helpers;
|
|||
|
||||
#[cfg(test)]
|
||||
mod test_load {
|
||||
use crate::helpers::{fixtures_dir, send_set_from};
|
||||
use roc::load::{load, LoadedModule};
|
||||
use crate::helpers::{fixtures_dir, builtins_dir};
|
||||
use roc::load::{load, Loaded, LoadedModule};
|
||||
use roc::can::module::Module;
|
||||
|
||||
fn test_async<F: std::future::Future>(future: F) -> F::Output {
|
||||
use tokio::runtime::Runtime;
|
||||
|
@ -24,33 +25,96 @@ mod test_load {
|
|||
rt.block_on(future)
|
||||
}
|
||||
|
||||
fn expect_module(loaded: Loaded) -> Module {
|
||||
match loaded.requested_module {
|
||||
LoadedModule::Valid(module) => module,
|
||||
LoadedModule::FileProblem{ filename, error } => panic!(
|
||||
"{:?} failed to load with FileProblem: {:?}",
|
||||
filename, error
|
||||
),
|
||||
LoadedModule::ParsingFailed{ filename, fail } => panic!(
|
||||
"{:?} failed to load with ParsingFailed: {:?}",
|
||||
filename, fail
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
async fn load_builtins(deps: &mut Vec<LoadedModule>) {
|
||||
let src_dir = builtins_dir();
|
||||
let filename = src_dir.join("Defaults.roc");
|
||||
|
||||
load(src_dir, filename, deps).await;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn interface_with_deps() {
|
||||
let mut deps = Vec::new();
|
||||
let src_dir = fixtures_dir().join("interface_with_deps");
|
||||
let filename = src_dir.join("Primary.roc");
|
||||
|
||||
test_async(async {
|
||||
let loaded = load(src_dir, filename).await;
|
||||
|
||||
let module = match loaded.requested_module {
|
||||
LoadedModule::Valid(module) => module,
|
||||
LoadedModule::FileProblem(err) => panic!(
|
||||
"requested_module failed to load with FileProblem: {:?}",
|
||||
err
|
||||
),
|
||||
LoadedModule::ParsingFailed(fail) => panic!(
|
||||
"requested_module failed to load with ParsingFailed: {:?}",
|
||||
fail
|
||||
),
|
||||
};
|
||||
let module = expect_module(load(src_dir, filename, &mut deps).await);
|
||||
|
||||
assert_eq!(module.name, Some("Primary".into()));
|
||||
assert_eq!(module.defs.len(), 6);
|
||||
|
||||
assert_eq!(
|
||||
loaded.deps,
|
||||
send_set_from(vec!["Dep1".into(), "Dep2".into(), "Dep3.Blah".into()])
|
||||
);
|
||||
let module_names: Vec<Option<Box<str>>> =
|
||||
deps.into_iter().map(|dep| dep.into_module().unwrap().name).collect();
|
||||
|
||||
assert_eq!(module_names, vec![
|
||||
Some("Dep1".into()),
|
||||
Some("Dep3.Blah".into()),
|
||||
Some("Dep2".into())
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn builtins() {
|
||||
let mut deps = Vec::new();
|
||||
let src_dir = builtins_dir();
|
||||
let filename = src_dir.join("Defaults.roc");
|
||||
|
||||
test_async(async {
|
||||
let module = expect_module(load(src_dir, filename, &mut deps).await);
|
||||
|
||||
assert_eq!(module.name, Some("Defaults".into()));
|
||||
assert_eq!(module.defs.len(), 0);
|
||||
|
||||
let module_names: Vec<Option<Box<str>>> =
|
||||
deps.into_iter().map(|dep| dep.into_module().unwrap().name).collect();
|
||||
|
||||
assert_eq!(module_names, vec![
|
||||
Some("Map".into()),
|
||||
Some("Set".into()),
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn interface_with_builtins() {
|
||||
let mut deps = Vec::new();
|
||||
|
||||
test_async(async {
|
||||
load_builtins(&mut deps).await;
|
||||
|
||||
let src_dir = fixtures_dir().join("interface_with_deps");
|
||||
let filename = src_dir.join("Primary.roc");
|
||||
let module = expect_module(load(src_dir, filename, &mut deps).await);
|
||||
|
||||
assert_eq!(module.name, Some("Primary".into()));
|
||||
assert_eq!(module.defs.len(), 6);
|
||||
|
||||
let module_names: Vec<Option<Box<str>>> =
|
||||
deps.into_iter().map(|dep| dep.into_module().unwrap().name).collect();
|
||||
|
||||
assert_eq!(module_names, vec![
|
||||
Some("Map".into()),
|
||||
Some("Set".into()),
|
||||
Some("Dep1".into()),
|
||||
Some("Dep3.Blah".into()),
|
||||
Some("Dep2".into())
|
||||
]);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue