Skip to content

Commit

Permalink
started testing for import
Browse files Browse the repository at this point in the history
  • Loading branch information
amitu committed Nov 12, 2024
1 parent a5c6c81 commit 8d4f8e4
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions v0.5/Cargo.lock

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

3 changes: 3 additions & 0 deletions v0.5/fastn-unresolved/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ homepage.workspace = true
[dependencies]
fastn-section.workspace = true
serde.workspace = true

[dev-dependencies]
serde_json.workspace = true
33 changes: 33 additions & 0 deletions v0.5/fastn-unresolved/src/parser/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,36 @@ fn parse_exposing(
) {
todo!()
}

#[cfg(test)]
mod tests {
#[track_caller]
fn t1(source: &str, expected: serde_json::Value) {
let (mut document, sections) =
fastn_unresolved::Document::new(fastn_section::Document::parse(source));

let section = {
assert_eq!(sections.len(), 1);
sections.into_iter().next().unwrap()
};

super::import(source, section, &mut document);
assert_eq!(serde_json::to_value(document.imports).unwrap(), expected);
}

macro_rules! t {
($source:expr, $debug:tt) => {
t1($source, serde_json::json!($debug));
};
}

#[test]
fn test_import() {
t!("-- import: foo", { "import": "foo" });
t!("-- import: foo.fifthtry.site/bar", { "import": "foo.fifthtry.site/bar" });
t!("-- import: foo as f", { "import": "foo=>f" });
t!("-- import: foo as f\nexposing: x", { "import": "foo=>f", "exposing": ["x"] });
t!("-- import: foo\nexposing: x", { "import": "foo", "exposing": ["x"] });
t!("-- import: foo as f\nexposing: x as y", { "import": "foo as f", "exposing": ["x=>y"] });
}
}

0 comments on commit 8d4f8e4

Please sign in to comment.