Repository navigation
test(import): cover issue 416 fixtures, nesting and section groups #652
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
alientechsw
merged 5 commits into
AlienTechSoftware:main
from
mameen:test/import-issue-416
Dec 2, 2026
+245
−3
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b064084
test(import): add the issue 416 package as a generic fixture
alientechsw fa95a33
test(import): cover issue 416 shape, nested levels and section groups
alientechsw 603c597
Merge branch 'main' into test/import-issue-416
alientechsw 8ce8177
test(import): match group folders by name and require page order
alientechsw 73bde9a
Merge remote-tracking branch 'origin/main' into test/import-issue-416
alientechsw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
crates/import/tests/fixtures/issue-416-empty-titled-pages/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # Issue 416: empty titled pages | ||
|
|
||
| `empty-titled-pages.onepkg` is a generic OneNote package with 4 sections and 32 pages (titles such as | ||
| "Page 01", "Subpage 03a"). It has no personal data: section and page names are generic and there are no | ||
| author names, paths or addresses. It was reported in issue #416 (import of pages with wrong titles and | ||
| missing pictures). Its page bodies import as empty in the current build; whether the source pages really | ||
| are empty is still open. |
Binary file added
BIN
+18.3 KB
crates/import/tests/fixtures/issue-416-empty-titled-pages/empty-titled-pages.onepkg
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file added
BIN
+2.65 KB
crates/import/tests/fixtures/synthetic/groups/Outer/Inner/Inner section.one
Binary file not shown.
Binary file added
BIN
+2.65 KB
crates/import/tests/fixtures/synthetic/groups/Outer/Outer section.one
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| //! Issue #416: a OneNote package with empty titled pages imports every section and page. | ||
|
|
||
| use std::fs; | ||
| use std::path::{Path, PathBuf}; | ||
|
|
||
| use notecraft_import::{Options, run}; | ||
| use notecraft_model::PageFormat; | ||
| use notecraft_store::testing::TempDir; | ||
|
|
||
| const PACKAGE: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/tests/fixtures/issue-416-empty-titled-pages/empty-titled-pages.onepkg"); | ||
|
|
||
| fn quiet(_: ¬ecraft_import::Event<'_>) {} | ||
|
|
||
| /// Every page folder (one with an `index.md` or `index.html`) under `root`, not counting version copies. | ||
| fn page_folders(root: &Path, out: &mut Vec<PathBuf>) { | ||
| for entry in fs::read_dir(root).expect("read dir").flatten() { | ||
| let path = entry.path(); | ||
| if !path.is_dir() || path.file_name().is_some_and(|n| n == ".notecraft") { | ||
| continue; | ||
| } | ||
| if path.join("index.md").exists() || path.join("index.html").exists() { | ||
| out.push(path.clone()); | ||
| } | ||
| page_folders(&path, out); | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn issue_416_package_imports_all_sections_and_pages_in_both_formats() { | ||
| for format in [PageFormat::Html, PageFormat::Cmgfm] { | ||
| let temp = TempDir::new("issue-416-import"); | ||
| let dest = temp.path().join("notebooks"); | ||
| let options = Options { format, ..Options::new(PACKAGE, dest.clone()) }; | ||
| let report = run(&options, &mut quiet).expect("import the package"); | ||
| assert_eq!(report.sections_imported, 4, "sections imported in {format:?}"); | ||
| assert_eq!(report.pages, 32, "pages counted in {format:?}"); | ||
| let mut pages = Vec::new(); | ||
| page_folders(&dest, &mut pages); | ||
| assert_eq!(pages.len(), 32, "pages imported in {format:?}: {pages:?}"); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| //! Section shapes from the synthetic corpus, imported in both page formats: titles and text kept in | ||
| //! order (issue #416), page levels nested under the right parent, and section groups as folders. | ||
|
|
||
| use std::fs; | ||
| use std::path::{Path, PathBuf}; | ||
|
|
||
| use notecraft_import::{Options, run}; | ||
| use notecraft_model::PageFormat; | ||
| use notecraft_store::testing::TempDir; | ||
|
|
||
| const FIXTURES: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/tests/fixtures/synthetic"); | ||
| const FORMATS: [PageFormat; 2] = [PageFormat::Html, PageFormat::Cmgfm]; | ||
|
|
||
| fn quiet(_: ¬ecraft_import::Event<'_>) {} | ||
|
|
||
| struct Page { | ||
| dir: PathBuf, | ||
| title: String, | ||
| order: u64, | ||
| body: String, | ||
| } | ||
|
|
||
| /// The text between `open` and the next `close`, or an empty string. | ||
| fn between<'a>(text: &'a str, open: &str, close: &str) -> &'a str { | ||
| text.split_once(open).and_then(|(_, rest)| rest.split_once(close)).map_or("", |(inner, _)| inner) | ||
| } | ||
|
|
||
| fn parse(dir: &Path, text: &str) -> Page { | ||
| if text.contains("<title>") { | ||
| // HTML pages: the title in `<title>`, the order in a `notecraft:order` meta tag, the words in `<body>`. | ||
| let title = between(text, "<title>", "</title>").trim().to_string(); | ||
| let order = between(text, "name=\"notecraft:order\" content=\"", "\"").trim().parse().expect("HTML page has a notecraft:order meta tag"); | ||
| let body = text.split_once("<body>").map_or("", |(_, rest)| rest).trim().to_string(); | ||
| return Page { dir: dir.to_path_buf(), title, order, body }; | ||
| } | ||
| let mut parts = text.splitn(3, "---"); | ||
| parts.next(); | ||
| let front = parts.next().unwrap_or(""); | ||
| let body = parts.next().unwrap_or("").trim().to_string(); | ||
| let title = front.lines().find_map(|l| l.strip_prefix("title:")).map(|t| t.trim().trim_matches('"').to_string()).unwrap_or_default(); | ||
| let order = front.lines().find_map(|l| l.strip_prefix("order:")).and_then(|o| o.trim().parse().ok()).expect("Markdown page has an order field"); | ||
| Page { dir: dir.to_path_buf(), title, order, body } | ||
| } | ||
|
|
||
| /// Every page folder under `root`, skipping version copies. | ||
| fn pages(root: &Path) -> Vec<Page> { | ||
| let mut out = Vec::new(); | ||
| collect(root, &mut out); | ||
| out | ||
| } | ||
|
|
||
| fn collect(root: &Path, out: &mut Vec<Page>) { | ||
| for entry in fs::read_dir(root).expect("read dir").flatten() { | ||
| let path = entry.path(); | ||
| if !path.is_dir() || path.file_name().is_some_and(|n| n == ".notecraft") { | ||
| continue; | ||
| } | ||
| if let Some(index) = ["index.md", "index.html"].iter().map(|f| path.join(f)).find(|p| p.exists()) { | ||
| out.push(parse(&path, &fs::read_to_string(index).expect("page index"))); | ||
| } | ||
| collect(&path, out); | ||
| } | ||
| } | ||
|
|
||
| fn import(source: &Path, format: PageFormat) -> (TempDir, PathBuf) { | ||
| let temp = TempDir::new("section-shapes"); | ||
| let dest = temp.path().join("notebooks"); | ||
| let options = Options { format, ..Options::new(source, &dest) }; | ||
| run(&options, &mut quiet).expect("import the synthetic section"); | ||
| (temp, dest) | ||
| } | ||
|
|
||
| fn fixture(name: &str) -> PathBuf { | ||
| Path::new(FIXTURES).join(name) | ||
| } | ||
|
|
||
| #[test] | ||
| fn issue_416_shape_keeps_each_title_with_its_own_text_in_order() { | ||
| for format in FORMATS { | ||
| let (_temp, dest) = import(&fixture("issue-416-shape.one"), format); | ||
| let mut found = pages(&dest); | ||
| found.sort_by_key(|p| (p.dir.parent().map(Path::to_path_buf), p.order)); | ||
| let titles: Vec<&str> = found.iter().map(|p| p.title.as_str()).collect(); | ||
| assert_eq!(titles, ["Overview", "Solar", "Mini System", "Overview", "Wind"], "{format:?}: titles in order"); | ||
| assert!(!found[0].body.contains("synthetic"), "{format:?}: the blank page stays blank, got {:?}", found[0].body); | ||
| for (page, text) in | ||
| found[1..].iter().zip(["synthetic solar text", "synthetic mini system text", "synthetic second overview text", "synthetic wind text"]) | ||
| { | ||
| assert!(page.body.contains(text), "{format:?}: {:?} holds {text:?}, got {:?}", page.title, page.body); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn nested_levels_sit_under_the_nearest_page_above_with_a_lower_level() { | ||
| // Expected parent of each page: the title of the page it sits under, or None for a top-level page. | ||
| let expected = [ | ||
| ("Alpha", None), | ||
| ("Alpha one", Some("Alpha")), | ||
| ("Alpha one a", Some("Alpha one")), | ||
| ("Alpha one b", Some("Alpha one")), | ||
| ("Alpha two", Some("Alpha")), | ||
| ("Beta", None), | ||
| ("Beta deep", Some("Beta")), | ||
| ("Beta one", Some("Beta")), | ||
| ]; | ||
| for format in FORMATS { | ||
| let (_temp, dest) = import(&fixture("nested-levels.one"), format); | ||
| let found = pages(&dest); | ||
| assert_eq!(found.len(), expected.len(), "{format:?}: page count"); | ||
| for (title, parent) in expected { | ||
| let page = found.iter().find(|p| p.title == title).unwrap_or_else(|| panic!("{format:?}: page {title:?} exists")); | ||
| let actual_parent = page.dir.parent().and_then(|dir| found.iter().find(|p| p.dir == dir)).map(|p| p.title.as_str()); | ||
| assert_eq!(actual_parent, parent, "{format:?}: parent of {title:?}"); | ||
| assert!(page.body.contains(&format!("synthetic {} text", title.to_lowercase())), "{format:?}: {title:?} body {:?}", page.body); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn section_groups_become_folders_with_their_sections_inside() { | ||
| for format in FORMATS { | ||
| let (_temp, dest) = import(&fixture("groups"), format); | ||
| let found = pages(&dest); | ||
| let title_of = |text: &str| found.iter().find(|p| p.body.contains(text)).unwrap_or_else(|| panic!("{format:?}: page with {text:?}")); | ||
| // Folder names between the notebook root and the page, one per level. | ||
| let levels = |text: &str| -> Vec<String> { | ||
| let dir = &title_of(text).dir; | ||
| dir.strip_prefix(&dest) | ||
| .expect("page under the notebooks folder") | ||
| .components() | ||
| .map(|c| c.as_os_str().to_string_lossy().to_lowercase()) | ||
| .collect() | ||
| }; | ||
|
|
||
| let inner = levels("synthetic inner section text"); | ||
| let outer_at = inner.iter().position(|l| l == "outer").unwrap_or_else(|| panic!("{format:?}: outer group folder: {inner:?}")); | ||
| let inner_at = inner.iter().position(|l| l == "inner").unwrap_or_else(|| panic!("{format:?}: inner group folder: {inner:?}")); | ||
| assert!(outer_at < inner_at, "{format:?}: inner group nests under outer: {inner:?}"); | ||
|
|
||
| let outer = levels("synthetic outer section text"); | ||
| assert!( | ||
| outer.contains(&"outer".to_string()) && !outer.contains(&"inner".to_string()), | ||
| "{format:?}: outer section in the outer group only: {outer:?}" | ||
| ); | ||
|
|
||
| let loose = levels("synthetic loose section text"); | ||
| assert!(!loose.iter().any(|l| l == "outer" || l == "inner"), "{format:?}: loose section sits at the top: {loose:?}"); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The groups test never checks an outer section group.
importleavesOptions.notebookasNone. The planner then makes the top folderOutera notebook, not a section group. The outer-section assertions atcrates/import/tests/section_shapes.rs:136-145match any path component namedouter, so they pass for the notebook folder. The test passes without creating the outer group that its name describes.Set an explicit notebook for this fixture so that
OuterandInnerbecome section groups beneath it. Then assert that each group folder sits under that notebook. If the backup layout should also stay covered, keep the currentNonecase as a separate assertion thatOuteris a notebook.