mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-15 06:52:23 +00:00
* Add craft-wordmodel: WordCraft's document model without its editing code WordCraft's crates/doc (wordcraft-doc, at 07f97737) moved as it is, so the DOCX, RTF, ODT and other text-format crates can read into and write from one model. Module paths, type names and serde attributes are unchanged: an app that re-exports the crate keeps its native file format. Left in the app: range editing (edit.rs), IME text and equation editing. Not model, and already in craft-libs: code pages (craft-rtf), the ZIP entry-count check (craft-opc), the compound-file guard (craft-cfb). The paragraph walks moved to walk.rs and the unit helpers of wordcraft-geom to geom.rs. * craft-wordmodel: math_tree, the arguments of an equation node and a walk over its runs The DOCX reader and writer walk an equation's runs. The walk and the child accessors it uses were in WordCraft's equation editor (math_edit.rs), which stays in the app; they are structure, not editing. * craft-wordmodel: keep the document operations (edit.rs) with the model The DOCX and RTF readers use them: alternative-format chunks are merged into a document with adopt_blocks, and a reader formats ranges with format_range and inserts objects. They operate on the document, not on a view, so they belong beside it. The tests that drove them come back with them; the paragraph walks stay in walk.rs and edit re-exports them. base64 0.23, as WordCraft and craft-offcrypto use.
37 lines
1.1 KiB
Rust
37 lines
1.1 KiB
Rust
//! Test helper: the warnings this crate logs, captured per test thread, so a test can check that
|
|
//! a limit which leaves something out says so.
|
|
|
|
use std::cell::RefCell;
|
|
|
|
struct Capture;
|
|
|
|
thread_local! {
|
|
static LINES: RefCell<Vec<String>> = const { RefCell::new(Vec::new()) };
|
|
}
|
|
|
|
impl log::Log for Capture {
|
|
fn enabled(&self, m: &log::Metadata) -> bool {
|
|
m.level() <= log::Level::Warn
|
|
}
|
|
|
|
fn log(&self, r: &log::Record) {
|
|
if self.enabled(r.metadata()) {
|
|
LINES.with(|l| l.borrow_mut().push(r.args().to_string()));
|
|
}
|
|
}
|
|
|
|
fn flush(&self) {}
|
|
}
|
|
|
|
static CAPTURE: Capture = Capture;
|
|
|
|
/// `f`'s result and the warnings logged on this thread while it ran.
|
|
pub(crate) fn warnings<T>(f: impl FnOnce() -> T) -> (T, Vec<String>) {
|
|
// Only this logger is ever installed in a test binary; a second call keeps it.
|
|
let _ = log::set_logger(&CAPTURE);
|
|
log::set_max_level(log::LevelFilter::Warn);
|
|
LINES.with(|l| l.borrow_mut().clear());
|
|
let out = f();
|
|
(out, LINES.with(|l| std::mem::take(&mut *l.borrow_mut())))
|
|
}
|