Update tests with basic init

This commit is contained in:
2025-12-13 20:29:52 -06:00
parent 4113570eb3
commit fecef26e2f
12 changed files with 17349 additions and 56 deletions

53
src/debug.rs Normal file
View File

@@ -0,0 +1,53 @@
use std::num::NonZeroUsize;
pub struct DebugLog {
current: String,
history: Vec<String>,
max_history: Option<NonZeroUsize>,
pos: usize,
}
impl DebugLog {
pub fn new() -> Self {
Self {
current: String::new(),
history: vec![],
max_history: None,
pos: 0,
}
}
pub fn rotate(&mut self) {
let rot = std::mem::take(&mut self.current);
if let Some(max) = self.max_history {
if self.history.len() < max.into() {
self.history.push(rot);
} else {
self.history[self.pos] = rot;
self.pos = (self.pos + 1) % max.get();
}
} else {
self.history.push(rot);
}
}
}
impl std::fmt::Write for DebugLog {
fn write_str(&mut self, s: &str) -> std::fmt::Result {
self.current.write_str(s)
}
fn write_char(&mut self, c: char) -> std::fmt::Result {
self.current.write_char(c)
}
fn write_fmt(&mut self, args: std::fmt::Arguments<'_>) -> std::fmt::Result {
self.current.write_fmt(args)
}
}
impl Default for DebugLog {
fn default() -> Self {
Self::new()
}
}