5e8020aa38
Editor previews (colour swatches, arrows, embeds), the 18 obsidian-basics tasks (find and replace with regex, back/forward, auto-pair, footnotes, folding, search operators, split view, PDF/audio/ video embeds, spelling, drag and drop, pinned tabs, settings) and round 2: ```query blocks, stacked tabs, pop-out windows, tasks ticked inside embeds, text around an embed, embeds that follow edits, block menu shortcut. New crates: notescraft-regex (linear-time engine) and notescraft-syntax. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
79 lines
2.6 KiB
Rust
79 lines
2.6 KiB
Rust
//! The bounded pre-count behind the large-folder warning: it runs before a vault is opened,
|
|
//! so it must not write anything, and it must stop early on a huge folder.
|
|
|
|
mod common;
|
|
|
|
use std::fs;
|
|
|
|
use notescraft_vault::{FileCount, count_files};
|
|
|
|
fn touch(dir: &std::path::Path, count: usize, ext: &str) {
|
|
for n in 0..count {
|
|
fs::write(dir.join(format!("f{n}.{ext}")), b"x").unwrap();
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn counts_files_and_notes_without_creating_the_state_folder() {
|
|
let dir = common::TempDir::new("count");
|
|
touch(dir.path(), 3, "md");
|
|
touch(dir.path(), 2, "png");
|
|
fs::create_dir(dir.path().join("sub")).unwrap();
|
|
touch(&dir.path().join("sub"), 4, "md");
|
|
|
|
let counted = count_files(dir.path(), 100).unwrap();
|
|
assert_eq!(counted, FileCount { files: 9, notes: 7, over_limit: false });
|
|
assert!(!dir.path().join(".notescraft").exists(), "counting must not write to the folder");
|
|
}
|
|
|
|
#[test]
|
|
fn stops_walking_once_the_limit_is_passed() {
|
|
let dir = common::TempDir::new("count-over");
|
|
touch(dir.path(), 6, "md");
|
|
for sub in 0..50 {
|
|
let sub_dir = dir.path().join(format!("d{sub}"));
|
|
fs::create_dir(&sub_dir).unwrap();
|
|
touch(&sub_dir, 10, "md");
|
|
}
|
|
|
|
let counted = count_files(dir.path(), 5).unwrap();
|
|
assert!(counted.over_limit);
|
|
assert!(counted.files < 506, "the walk stopped before reading every folder");
|
|
}
|
|
|
|
#[test]
|
|
fn a_folder_exactly_at_the_limit_is_not_over() {
|
|
let dir = common::TempDir::new("count-edge");
|
|
touch(dir.path(), 5, "md");
|
|
assert_eq!(count_files(dir.path(), 5).unwrap(), FileCount { files: 5, notes: 5, over_limit: false });
|
|
}
|
|
|
|
#[test]
|
|
fn skips_hidden_entries_like_list_does() {
|
|
let dir = common::TempDir::new("count-hidden");
|
|
touch(dir.path(), 2, "md");
|
|
fs::create_dir(dir.path().join(".git")).unwrap();
|
|
touch(&dir.path().join(".git"), 20, "md");
|
|
fs::write(dir.path().join(".dotfile.md"), b"x").unwrap();
|
|
assert_eq!(count_files(dir.path(), 100).unwrap().files, 2);
|
|
}
|
|
|
|
#[cfg(unix)]
|
|
#[test]
|
|
fn does_not_follow_symlinks() {
|
|
use std::os::unix::fs::symlink;
|
|
|
|
let dir = common::TempDir::new("count-links");
|
|
let outside = common::TempDir::new("count-outside");
|
|
touch(outside.path(), 10, "md");
|
|
symlink(outside.path(), dir.path().join("escape")).unwrap();
|
|
symlink(outside.path().join("f0.md"), dir.path().join("link.md")).unwrap();
|
|
assert_eq!(count_files(dir.path(), 100).unwrap().files, 0);
|
|
}
|
|
|
|
#[test]
|
|
fn a_missing_folder_is_an_error() {
|
|
let dir = common::TempDir::new("count-missing");
|
|
assert!(count_files(&dir.path().join("nope"), 10).is_err());
|
|
}
|