mirror of
https://github.com/storytold/wordcraft.git
synced 2026-10-31 05:47:00 -06:00
- A text box whose story doesn't fit what is left of the paste's byte budget gets no story, but later boxes with smaller stories are still copied while the budget lasts (it used to zero the budget). Each source story is costed once per paste, so skipping a big story many times doesn't walk it again. The paste logs one warning with the number of boxes left empty. wordcraft-doc now depends on log. - Document::media_index is a private field and MediaIndex a private type: a lookup cache, not API. The one struct-update literal outside the crate (a formats test) builds the document field by field. - kept_control_markers documents that delete_range relies on its sorted, deduplicated output; delete_range sorts it if it ever isn't, and control_markers_kept_are_sorted pins it. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CX1hMKX28764Lrx5moxs1o
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())))
|
|
}
|