зеркало из
https://github.com/glebtv/tui-textarea.git
synced 2026-09-08 00:15:50 +03:00
include rendering in fuzzing tests
Этот коммит содержится в:
@@ -29,6 +29,7 @@ pub struct DummyBackend {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Default for DummyBackend {
|
impl Default for DummyBackend {
|
||||||
|
#[inline]
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
width: 40,
|
width: 40,
|
||||||
@@ -39,6 +40,7 @@ impl Default for DummyBackend {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Backend for DummyBackend {
|
impl Backend for DummyBackend {
|
||||||
|
#[inline]
|
||||||
fn draw<'a, I>(&mut self, _content: I) -> Result<(), io::Error>
|
fn draw<'a, I>(&mut self, _content: I) -> Result<(), io::Error>
|
||||||
where
|
where
|
||||||
I: Iterator<Item = (u16, u16, &'a Cell)>,
|
I: Iterator<Item = (u16, u16, &'a Cell)>,
|
||||||
@@ -46,27 +48,33 @@ impl Backend for DummyBackend {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn hide_cursor(&mut self) -> Result<(), io::Error> {
|
fn hide_cursor(&mut self) -> Result<(), io::Error> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn show_cursor(&mut self) -> Result<(), io::Error> {
|
fn show_cursor(&mut self) -> Result<(), io::Error> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn get_cursor(&mut self) -> Result<(u16, u16), io::Error> {
|
fn get_cursor(&mut self) -> Result<(u16, u16), io::Error> {
|
||||||
Ok(self.cursor)
|
Ok(self.cursor)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn set_cursor(&mut self, x: u16, y: u16) -> Result<(), io::Error> {
|
fn set_cursor(&mut self, x: u16, y: u16) -> Result<(), io::Error> {
|
||||||
self.cursor = (x, y);
|
self.cursor = (x, y);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn clear(&mut self) -> Result<(), io::Error> {
|
fn clear(&mut self) -> Result<(), io::Error> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn size(&self) -> Result<Rect, io::Error> {
|
fn size(&self) -> Result<Rect, io::Error> {
|
||||||
Ok(Rect {
|
Ok(Rect {
|
||||||
x: 0,
|
x: 0,
|
||||||
@@ -76,11 +84,13 @@ impl Backend for DummyBackend {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
fn flush(&mut self) -> Result<(), io::Error> {
|
fn flush(&mut self) -> Result<(), io::Error> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
pub fn dummy_terminal() -> Terminal<DummyBackend> {
|
pub fn dummy_terminal() -> Terminal<DummyBackend> {
|
||||||
Terminal::new(DummyBackend::default()).unwrap()
|
Terminal::new(DummyBackend::default()).unwrap()
|
||||||
}
|
}
|
||||||
@@ -90,6 +100,7 @@ pub trait TerminalExt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl TerminalExt for Terminal<DummyBackend> {
|
impl TerminalExt for Terminal<DummyBackend> {
|
||||||
|
#[inline]
|
||||||
fn draw_textarea(&mut self, textarea: &TextArea<'_>) {
|
fn draw_textarea(&mut self, textarea: &TextArea<'_>) {
|
||||||
self.draw(|f| f.render_widget(textarea.widget(), f.size()))
|
self.draw(|f| f.render_widget(textarea.widget(), f.size()))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|||||||
9
fuzz/Cargo.lock
сгенерированный
9
fuzz/Cargo.lock
сгенерированный
@@ -289,6 +289,14 @@ dependencies = [
|
|||||||
"tui",
|
"tui",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "tui-textarea-bench"
|
||||||
|
version = "0.0.0"
|
||||||
|
dependencies = [
|
||||||
|
"tui",
|
||||||
|
"tui-textarea",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tui-textarea-fuzz"
|
name = "tui-textarea-fuzz"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
@@ -296,6 +304,7 @@ dependencies = [
|
|||||||
"arbitrary",
|
"arbitrary",
|
||||||
"libfuzzer-sys",
|
"libfuzzer-sys",
|
||||||
"tui-textarea",
|
"tui-textarea",
|
||||||
|
"tui-textarea-bench",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ cargo-fuzz = true
|
|||||||
libfuzzer-sys = "0.4"
|
libfuzzer-sys = "0.4"
|
||||||
arbitrary = "1"
|
arbitrary = "1"
|
||||||
tui-textarea = { path = "..", features = ["search", "arbitrary"] }
|
tui-textarea = { path = "..", features = ["search", "arbitrary"] }
|
||||||
|
tui-textarea-bench = { path = "../bench" }
|
||||||
|
|
||||||
# Prevent this from interfering with workspaces
|
# Prevent this from interfering with workspaces
|
||||||
[workspace]
|
[workspace]
|
||||||
|
|||||||
@@ -5,17 +5,19 @@ use libfuzzer_sys::fuzz_target;
|
|||||||
use std::iter;
|
use std::iter;
|
||||||
use std::str;
|
use std::str;
|
||||||
use tui_textarea::{Input, TextArea};
|
use tui_textarea::{Input, TextArea};
|
||||||
|
use tui_textarea_bench::{dummy_terminal, TerminalExt};
|
||||||
|
|
||||||
fn fuzz(data: &[u8]) -> Result<()> {
|
fn fuzz(data: &[u8]) -> Result<()> {
|
||||||
let mut u = Unstructured::new(data);
|
let mut term = dummy_terminal();
|
||||||
let inputs: Vec<_> = iter::repeat_with(|| Input::arbitrary(&mut u))
|
let mut data = Unstructured::new(data);
|
||||||
|
let inputs: Vec<_> = iter::repeat_with(|| Input::arbitrary(&mut data))
|
||||||
.take(100)
|
.take(100)
|
||||||
.collect::<Result<_>>()?;
|
.collect::<Result<_>>()?;
|
||||||
let text = <&str>::arbitrary(&mut u)?;
|
let text = <&str>::arbitrary(&mut data)?;
|
||||||
let mut textarea = TextArea::from(text.lines());
|
let mut textarea = TextArea::from(text.lines());
|
||||||
for input in inputs {
|
for input in inputs {
|
||||||
textarea.input(input);
|
textarea.input(input);
|
||||||
let _ = textarea.widget();
|
term.draw_textarea(&mut textarea);
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user