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>
30 lines
1.5 KiB
Rust
30 lines
1.5 KiB
Rust
//! The `spelling` rule: a word the vault uses in fewer than two notes is flagged once the rule is on.
|
|
|
|
mod common;
|
|
|
|
use common::{temp_config, temp_vault};
|
|
use notescraft_engine::{Registry, Session, register_core};
|
|
use serde_json::json;
|
|
|
|
#[test]
|
|
fn unknown_words_are_flagged_with_a_suggestion_only_when_spelling_is_on() {
|
|
let vault = temp_vault("spelling");
|
|
let config = temp_config("spelling");
|
|
for (name, text) in [("a.md", "Please receive the letter today.\n"), ("b.md", "We receive letters often.\n"), ("c.md", "Did you recieve the letter?\n")] {
|
|
std::fs::write(vault.path().join(name), text).expect("write");
|
|
}
|
|
let mut registry = Registry::new();
|
|
register_core(&mut registry).expect("register");
|
|
let mut session = Session::open(vault.path()).expect("open");
|
|
session.use_settings_dir(config.path());
|
|
let spelling = |registry: &Registry<Session>, session: &mut Session| -> Vec<serde_json::Value> {
|
|
let result = registry.run("lint.check", session, &json!({ "path": "c.md" })).expect("check");
|
|
result["issues"].as_array().cloned().unwrap_or_default().into_iter().filter(|issue| issue["rule"] == "spelling").collect()
|
|
};
|
|
assert!(spelling(®istry, &mut session).is_empty(), "off by default");
|
|
registry.run("settings.set", &mut session, &json!({ "key": "session.lint.spelling", "value": true })).expect("enable");
|
|
let issues = spelling(®istry, &mut session);
|
|
assert_eq!(issues.len(), 1, "{issues:?}");
|
|
assert_eq!(issues[0]["fix"]["label"], "Change to receive");
|
|
}
|