зеркало из
https://github.com/glebtv/tui-textarea.git
synced 2026-09-07 16:05:50 +03:00
add arbitrary crate as optional dependency
to avoid converting `Input` in fuzz test for making arbitrary inputs
Этот коммит содержится в:
@@ -31,6 +31,7 @@ crossterm = { version = "0.23", optional = true }
|
|||||||
regex = { version = "1", optional = true }
|
regex = { version = "1", optional = true }
|
||||||
termion = { version = "1.5", optional = true }
|
termion = { version = "1.5", optional = true }
|
||||||
tui = { version = "0.18", default-features = false }
|
tui = { version = "0.18", default-features = false }
|
||||||
|
arbitrary = { version = "1", features = ["derive"], optional = true }
|
||||||
|
|
||||||
[[example]]
|
[[example]]
|
||||||
name = "minimal"
|
name = "minimal"
|
||||||
|
|||||||
40
fuzz/Cargo.lock
сгенерированный
40
fuzz/Cargo.lock
сгенерированный
@@ -2,6 +2,15 @@
|
|||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 3
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "aho-corasick"
|
||||||
|
version = "0.7.18"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f"
|
||||||
|
dependencies = [
|
||||||
|
"memchr",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "arbitrary"
|
name = "arbitrary"
|
||||||
version = "1.1.2"
|
version = "1.1.2"
|
||||||
@@ -113,6 +122,12 @@ dependencies = [
|
|||||||
"cfg-if",
|
"cfg-if",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "memchr"
|
||||||
|
version = "2.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mio"
|
name = "mio"
|
||||||
version = "0.8.3"
|
version = "0.8.3"
|
||||||
@@ -181,6 +196,23 @@ dependencies = [
|
|||||||
"bitflags",
|
"bitflags",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex"
|
||||||
|
version = "1.6.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b"
|
||||||
|
dependencies = [
|
||||||
|
"aho-corasick",
|
||||||
|
"memchr",
|
||||||
|
"regex-syntax",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex-syntax"
|
||||||
|
version = "0.6.27"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "scopeguard"
|
name = "scopeguard"
|
||||||
version = "1.1.0"
|
version = "1.1.0"
|
||||||
@@ -219,9 +251,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "smallvec"
|
name = "smallvec"
|
||||||
version = "1.8.0"
|
version = "1.9.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83"
|
checksum = "2fd0db749597d91ff862fd1d55ea87f7855a744a8425a64695b6fca237d1dad1"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
@@ -249,9 +281,11 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tui-textarea"
|
name = "tui-textarea"
|
||||||
version = "0.0.0"
|
version = "0.1.4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"arbitrary",
|
||||||
"crossterm",
|
"crossterm",
|
||||||
|
"regex",
|
||||||
"tui",
|
"tui",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -10,10 +10,8 @@ cargo-fuzz = true
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
libfuzzer-sys = "0.4"
|
libfuzzer-sys = "0.4"
|
||||||
arbitrary = { version = "1", features = ["derive"] }
|
arbitrary = "1"
|
||||||
|
tui-textarea = { path = "..", features = ["search", "arbitrary"] }
|
||||||
[dependencies.tui-textarea]
|
|
||||||
path = ".."
|
|
||||||
|
|
||||||
# Prevent this from interfering with workspaces
|
# Prevent this from interfering with workspaces
|
||||||
[workspace]
|
[workspace]
|
||||||
|
|||||||
@@ -4,77 +4,19 @@ use arbitrary::{Arbitrary, Result, Unstructured};
|
|||||||
use libfuzzer_sys::fuzz_target;
|
use libfuzzer_sys::fuzz_target;
|
||||||
use std::iter;
|
use std::iter;
|
||||||
use std::str;
|
use std::str;
|
||||||
use tui_textarea::{Input, Key, TextArea};
|
use tui_textarea::{Input, TextArea};
|
||||||
|
|
||||||
macro_rules! arbitrary_key_enum {
|
|
||||||
($($p:ident$(($x:ident))?,)+) => {
|
|
||||||
|
|
||||||
#[derive(Arbitrary)]
|
|
||||||
enum ArbitraryKey {
|
|
||||||
$(
|
|
||||||
$p$(($x))?,
|
|
||||||
)+
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<ArbitraryKey> for Key {
|
|
||||||
fn from(k: ArbitraryKey) -> Key {
|
|
||||||
match k {
|
|
||||||
$(
|
|
||||||
ArbitraryKey::$p$(($x))? => Key::$p$(($x))?,
|
|
||||||
)+
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
arbitrary_key_enum!(
|
|
||||||
Char(char),
|
|
||||||
F(u8),
|
|
||||||
Backspace,
|
|
||||||
Enter,
|
|
||||||
Left,
|
|
||||||
Right,
|
|
||||||
Up,
|
|
||||||
Down,
|
|
||||||
Tab,
|
|
||||||
Delete,
|
|
||||||
Home,
|
|
||||||
End,
|
|
||||||
PageUp,
|
|
||||||
PageDown,
|
|
||||||
Esc,
|
|
||||||
Null,
|
|
||||||
);
|
|
||||||
|
|
||||||
#[derive(Arbitrary)]
|
|
||||||
struct ArbitraryInput {
|
|
||||||
key: ArbitraryKey,
|
|
||||||
ctrl: bool,
|
|
||||||
alt: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<ArbitraryInput> for Input {
|
|
||||||
fn from(i: ArbitraryInput) -> Input {
|
|
||||||
Input {
|
|
||||||
key: i.key.into(),
|
|
||||||
ctrl: i.ctrl,
|
|
||||||
alt: i.alt,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn fuzz(data: &[u8]) -> Result<()> {
|
fn fuzz(data: &[u8]) -> Result<()> {
|
||||||
let mut u = Unstructured::new(data);
|
let mut u = Unstructured::new(data);
|
||||||
let inputs: Vec<_> = iter::repeat_with(|| ArbitraryInput::arbitrary(&mut u))
|
let inputs: Vec<_> = iter::repeat_with(|| Input::arbitrary(&mut u))
|
||||||
.take(10)
|
.take(100)
|
||||||
.collect::<Result<_>>()?;
|
.collect::<Result<_>>()?;
|
||||||
let text = <&str>::arbitrary(&mut u)?;
|
let text = <&str>::arbitrary(&mut u)?;
|
||||||
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();
|
||||||
}
|
}
|
||||||
let _ = textarea.widget();
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
#[cfg(feature = "arbitrary")]
|
||||||
|
use arbitrary::Arbitrary;
|
||||||
#[cfg(feature = "crossterm")]
|
#[cfg(feature = "crossterm")]
|
||||||
use crossterm::event::{Event as CrosstermEvent, KeyCode, KeyEvent, KeyModifiers};
|
use crossterm::event::{Event as CrosstermEvent, KeyCode, KeyEvent, KeyModifiers};
|
||||||
#[cfg(feature = "termion")]
|
#[cfg(feature = "termion")]
|
||||||
@@ -6,6 +8,7 @@ use termion::event::{Event as TerimonEvent, Key as TermionKey};
|
|||||||
/// Backend-agnostic key input kind.
|
/// Backend-agnostic key input kind.
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
|
#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
|
||||||
pub enum Key {
|
pub enum Key {
|
||||||
/// Normal letter key input.
|
/// Normal letter key input.
|
||||||
Char(char),
|
Char(char),
|
||||||
@@ -62,6 +65,7 @@ pub enum Key {
|
|||||||
/// });
|
/// });
|
||||||
/// ```
|
/// ```
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
#[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
|
||||||
pub struct Input {
|
pub struct Input {
|
||||||
/// Typed key.
|
/// Typed key.
|
||||||
pub key: Key,
|
pub key: Key,
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user