зеркало из
https://github.com/glebtv/tui-textarea.git
synced 2026-08-28 11:36:17 +03:00
support generating random CursorMove with arbitrary
Этот коммит содержится в:
@@ -10,7 +10,7 @@ cargo-fuzz = true
|
||||
|
||||
[dependencies]
|
||||
libfuzzer-sys = "0.4"
|
||||
arbitrary = "1"
|
||||
arbitrary = { version = "1", features = ["derive"] }
|
||||
tui-textarea = { path = "..", features = ["search", "arbitrary"] }
|
||||
tui-textarea-bench = { path = "../bench" }
|
||||
|
||||
|
||||
@@ -2,21 +2,35 @@
|
||||
|
||||
use arbitrary::{Arbitrary, Result, Unstructured};
|
||||
use libfuzzer_sys::fuzz_target;
|
||||
use std::iter;
|
||||
use std::str;
|
||||
use tui_textarea::{Input, TextArea};
|
||||
use tui_textarea::{CursorMove, Input, TextArea};
|
||||
use tui_textarea_bench::{dummy_terminal, TerminalExt};
|
||||
|
||||
#[derive(Arbitrary)]
|
||||
enum RandomInput {
|
||||
Input(Input),
|
||||
Cursor(CursorMove),
|
||||
}
|
||||
|
||||
impl RandomInput {
|
||||
fn apply(self, t: &mut TextArea<'_>) {
|
||||
match self {
|
||||
Self::Input(input) => {
|
||||
t.input(input);
|
||||
}
|
||||
Self::Cursor(m) => t.move_cursor(m),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn fuzz(data: &[u8]) -> Result<()> {
|
||||
let mut term = dummy_terminal();
|
||||
let mut data = Unstructured::new(data);
|
||||
let inputs: Vec<_> = iter::repeat_with(|| Input::arbitrary(&mut data))
|
||||
.take(100)
|
||||
.collect::<Result<_>>()?;
|
||||
let text = <&str>::arbitrary(&mut data)?;
|
||||
let mut textarea = TextArea::from(text.lines());
|
||||
for input in inputs {
|
||||
textarea.input(input);
|
||||
for _ in 0..100 {
|
||||
let input = RandomInput::arbitrary(&mut data)?;
|
||||
input.apply(&mut textarea);
|
||||
term.draw_textarea(&mut textarea);
|
||||
}
|
||||
Ok(())
|
||||
|
||||
Ссылка в новой задаче
Block a user