Skip to content

Commit

Permalink
Add a unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
jneem committed Nov 15, 2024
1 parent 7deae72 commit cbd7329
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ codespan.workspace = true
codespan-reporting.workspace = true
colorchoice.workspace = true
cxx = { workspace = true, optional = true }
gix-hash = { workspace = true, features = ["serde"] }
logos.workspace = true
nickel-lang-vector.workspace = true
smallvec.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion core/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1482,7 +1482,7 @@ impl ImportResolver for Cache {
let pkg_path = package_map.get(parent_path, pkg, *pos)?;
(
vec![pkg_path.to_owned()],
Path::new("lib.ncl"),
Path::new("main.ncl"),
Some(pkg_path.to_owned()),
// Packages are always in nickel format
InputFormat::Nickel,
Expand Down
29 changes: 29 additions & 0 deletions core/src/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,32 @@ impl PackageMap {
})
}
}

#[cfg(test)]
mod tests {
use std::io::Cursor;

use super::*;
use crate::{eval::cache::CacheImpl, program::Program, term::Term};
use nickel_lang_utils::project_root::project_root;

// Test basic package map functionality by building one manually out of
// files in our integration test folder. More thorough integration tests
// will be possible once the cli is wired up with lock-files.
#[test]
fn package_import() {
let pkg1 = project_root().join("core/tests/integration/inputs/imports/imported/pkg1");
let pkg2 = project_root().join("core/tests/integration/inputs/imports/imported/pkg2");

let map = PackageMap {
top_level: std::iter::once((Ident::new("pkg"), pkg1.clone())).collect(),
packages: std::iter::once(((pkg1, Ident::new("dep")), pkg2)).collect(),
};

let mut p: Program<CacheImpl> =
Program::new_from_source(Cursor::new("import pkg"), "<test>", std::io::sink()).unwrap();
p.set_package_map(map);

assert_eq!(p.eval_full().unwrap().as_ref(), &Term::Num(44.into()));
}
}

0 comments on commit cbd7329

Please sign in to comment.