зеркало из
https://github.com/glebtv/tui-textarea.git
synced 2026-08-28 11:36:17 +03:00
- 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
94 строки
2.5 KiB
Rust
94 строки
2.5 KiB
Rust
#![no_main]
|
|
|
|
use arbitrary::{Arbitrary, Result, Unstructured};
|
|
use libfuzzer_sys::fuzz_target;
|
|
use tui_textarea::{CursorMove, TextArea};
|
|
use tui_textarea_bench::{dummy_terminal, TerminalExt};
|
|
|
|
#[derive(Arbitrary)]
|
|
enum Op {
|
|
Move(CursorMove),
|
|
InsertStr(String),
|
|
InsertChar(char),
|
|
InsertTab,
|
|
InsertNewline,
|
|
DeleteStr(usize),
|
|
DeleteChar,
|
|
DeleteNextChar,
|
|
DeleteWord,
|
|
DeleteNextWord,
|
|
DeleteLineByEnd,
|
|
DeleteLineByHead,
|
|
DeleteNewline,
|
|
Clear,
|
|
}
|
|
|
|
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 textarea = TextArea::default();
|
|
let mut data = Unstructured::new(data);
|
|
for _ in 0..100 {
|
|
match Op::arbitrary(&mut data)? {
|
|
Op::Move(m) => textarea.move_cursor(m),
|
|
Op::InsertStr(s) => {
|
|
textarea.insert_str(s);
|
|
}
|
|
Op::InsertChar(c) => textarea.insert_char(c),
|
|
Op::InsertTab => {
|
|
textarea.insert_tab();
|
|
}
|
|
Op::InsertNewline => textarea.insert_newline(),
|
|
Op::DeleteStr(n) => {
|
|
textarea.delete_str(n);
|
|
}
|
|
Op::DeleteChar => {
|
|
textarea.delete_char();
|
|
}
|
|
Op::DeleteNextChar => {
|
|
textarea.delete_next_char();
|
|
}
|
|
Op::DeleteWord => {
|
|
textarea.delete_word();
|
|
}
|
|
Op::DeleteNextWord => {
|
|
textarea.delete_next_word();
|
|
}
|
|
Op::DeleteLineByEnd => {
|
|
textarea.delete_line_by_end();
|
|
}
|
|
Op::DeleteLineByHead => {
|
|
textarea.delete_line_by_head();
|
|
}
|
|
Op::DeleteNewline => {
|
|
textarea.delete_newline();
|
|
}
|
|
Op::Clear => {
|
|
textarea.clear();
|
|
}
|
|
}
|
|
term.draw_textarea(&textarea);
|
|
assert_invariants(&textarea);
|
|
}
|
|
Ok(())
|
|
}
|
|
|
|
fuzz_target!(|data: &[u8]| {
|
|
let _ = fuzz(data);
|
|
});
|