224ae2718a
Index: frontmatter properties (200 per note, 4 KiB per value, 500 list items, 3 levels), size and times; persistent cache format version 2 (old caches are replaced). Engine: base.list, base.read, base.properties, base.query over the index (limit 200 default, over 2000 is an error), base.write (validated; never replaces an unreadable file), base.create, base.view.add|remove|rename|duplicate|reorder, base.row.set (types.json, one undo step in an open buffer, file.name renames with links; other file.* and formula.* are read-only). Bases tasks 9, 10, 11 (Claude Sonnet). Verified with the full cargo xtask ci on a copy of the tree (4526 tests, clippy -D warnings, layers, tree, i18n). Gaps: no result cache keyed by index generation, no 15k-note perf test, base.row.set writes numbers as 5.0. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
66 lines
2.8 KiB
Rust
66 lines
2.8 KiB
Rust
//! Frontmatter properties, file stats and their bounds.
|
|
|
|
use notescraft_index::{Index, MAX_LIST_ITEMS, MAX_PROPS, MAX_VALUE_BYTES};
|
|
use notescraft_markdown::{PropType, Value};
|
|
|
|
#[test]
|
|
fn keys_values_and_types() {
|
|
let mut index = Index::new();
|
|
index.update_note("a.md", "---\nyear: 1999\ntitle: Dune\ndone: true\ndue: 2026-01-02\ntags: [x, y]\nrel: [p, q]\n---\nbody\n").unwrap();
|
|
index.update_note("b.md", "---\nyear: 2001\n---\n").unwrap();
|
|
let props = index.note_props("a.md").unwrap();
|
|
assert_eq!(props.len(), 6);
|
|
assert_eq!(props[0], ("year".to_string(), Value::Number(1999.0)));
|
|
assert_eq!(props[1], ("title".to_string(), Value::String("Dune".into())));
|
|
assert!(matches!(&props[3].1, Value::Date(d) if d == "2026-01-02"));
|
|
assert!(matches!(&props[5].1, Value::List(items) if items.len() == 2));
|
|
let keys = index.property_keys();
|
|
let find = |name: &str| keys.iter().find(|(k, ..)| k == name).cloned().unwrap();
|
|
assert_eq!(find("year"), ("year".into(), PropType::Number, 2));
|
|
assert_eq!(find("done").1, PropType::Checkbox);
|
|
assert_eq!(find("due").1, PropType::Date);
|
|
assert_eq!(find("rel").1, PropType::List);
|
|
assert_eq!(find("tags").1, PropType::Tags);
|
|
assert_eq!(find("title").2, 1);
|
|
assert!(index.note_props("none.md").is_none());
|
|
}
|
|
|
|
#[test]
|
|
fn too_many_properties_are_capped_and_flagged() {
|
|
let lines: Vec<String> = (0..300).map(|i| format!("k{i}: {i}")).collect();
|
|
let text = format!("---\n{}\n---\n", lines.join("\n"));
|
|
let mut index = Index::new();
|
|
index.update_note("big.md", &text).unwrap();
|
|
let info = index.note("big.md").unwrap();
|
|
assert_eq!(info.props.len(), MAX_PROPS);
|
|
assert!(info.props_truncated);
|
|
assert!(!{
|
|
index.update_note("ok.md", "---\na: 1\n---\n").unwrap();
|
|
index.note("ok.md").unwrap().props_truncated
|
|
});
|
|
}
|
|
|
|
#[test]
|
|
fn long_values_and_lists_are_cut() {
|
|
let long = "é".repeat(MAX_VALUE_BYTES);
|
|
let items = (0..MAX_LIST_ITEMS + 10).map(|i| i.to_string()).collect::<Vec<_>>().join(", ");
|
|
let mut index = Index::new();
|
|
index.update_note("n.md", &format!("---\ns: {long}\nl: [{items}]\n---\n")).unwrap();
|
|
let info = index.note("n.md").unwrap();
|
|
assert!(info.props_truncated);
|
|
assert!(matches!(&info.props[0].1, Value::String(s) if s.len() <= MAX_VALUE_BYTES && s.chars().all(|c| c == 'é')));
|
|
assert!(matches!(&info.props[1].1, Value::List(v) if v.len() == MAX_LIST_ITEMS));
|
|
}
|
|
|
|
#[test]
|
|
fn rename_keeps_props_and_stats() {
|
|
let mut index = Index::new();
|
|
index.update_note("a.md", "---\nyear: 1\n---\n").unwrap();
|
|
index.set_file_stats("a.md", 42, 1000, 2000);
|
|
index.rename_note("a.md", "b.md").unwrap();
|
|
let info = index.note("b.md").unwrap();
|
|
assert_eq!((info.size, info.ctime_ms, info.mtime_ms), (42, 1000, 2000));
|
|
assert_eq!(info.props.len(), 1);
|
|
assert_eq!(index.property_keys().len(), 1);
|
|
}
|