зеркало из
https://github.com/glebtv/tui-textarea.git
synced 2026-09-06 23:55:49 +03:00
chore(fuzz): upgrade targets, fix false positives, and add invariant assertions (#11)
- Fix insert_delete target using .unwrap() causing false-positive crashes on arbitrary::Error (input exhaustion) - Fix fuzz Cargo.toml referencing wrong package name (tui-textarea vs tui-textarea-2) - Add invariant assertions (cursor bounds, lines non-empty, selection validity) to all targets - Add 4 new fuzz targets: undo_redo, selection, wrap_render, search - Expand existing targets with full delete/insert variant coverage, input_without_shortcuts, set_yank_text, set_max_histories, and clear - Add DummyBackend::resize() for variable-width wrap rendering tests
Этот коммит содержится в:
@@ -9,6 +9,7 @@ use tui_textarea_bench::{dummy_terminal, TerminalExt};
|
||||
#[derive(Arbitrary)]
|
||||
enum RandomInput {
|
||||
Input(Input),
|
||||
InputWithoutShortcuts(Input),
|
||||
Cursor(CursorMove),
|
||||
}
|
||||
|
||||
@@ -18,11 +19,30 @@ impl RandomInput {
|
||||
Self::Input(input) => {
|
||||
t.input(input);
|
||||
}
|
||||
Self::InputWithoutShortcuts(input) => {
|
||||
t.input_without_shortcuts(input);
|
||||
}
|
||||
Self::Cursor(m) => t.move_cursor(m),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn assert_invariants(textarea: &TextArea<'_>) {
|
||||
let lines = textarea.lines();
|
||||
assert!(!lines.is_empty(), "lines must never be empty");
|
||||
let (row, col) = textarea.cursor();
|
||||
assert!(
|
||||
row < lines.len(),
|
||||
"cursor row {row} out of bounds (lines: {})",
|
||||
lines.len()
|
||||
);
|
||||
assert!(
|
||||
col <= lines[row].chars().count(),
|
||||
"cursor col {col} out of bounds (line {row} chars: {})",
|
||||
lines[row].chars().count(),
|
||||
);
|
||||
}
|
||||
|
||||
fn fuzz(data: &[u8]) -> Result<()> {
|
||||
let mut term = dummy_terminal();
|
||||
let mut data = Unstructured::new(data);
|
||||
@@ -32,6 +52,7 @@ fn fuzz(data: &[u8]) -> Result<()> {
|
||||
let input = RandomInput::arbitrary(&mut data)?;
|
||||
input.apply(&mut textarea);
|
||||
term.draw_textarea(&textarea);
|
||||
assert_invariants(&textarea);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user