зеркало из
https://github.com/glebtv/tui-textarea.git
synced 2026-09-03 14:26:17 +03:00
add arbitrary crate as optional dependency
to avoid converting `Input` in fuzz test for making arbitrary inputs
Этот коммит содержится в:
40
fuzz/Cargo.lock
сгенерированный
40
fuzz/Cargo.lock
сгенерированный
@@ -2,6 +2,15 @@
|
||||
# It is not intended for manual editing.
|
||||
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]]
|
||||
name = "arbitrary"
|
||||
version = "1.1.2"
|
||||
@@ -113,6 +122,12 @@ dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
|
||||
|
||||
[[package]]
|
||||
name = "mio"
|
||||
version = "0.8.3"
|
||||
@@ -181,6 +196,23 @@ dependencies = [
|
||||
"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]]
|
||||
name = "scopeguard"
|
||||
version = "1.1.0"
|
||||
@@ -219,9 +251,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "smallvec"
|
||||
version = "1.8.0"
|
||||
version = "1.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83"
|
||||
checksum = "2fd0db749597d91ff862fd1d55ea87f7855a744a8425a64695b6fca237d1dad1"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
@@ -249,9 +281,11 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "tui-textarea"
|
||||
version = "0.0.0"
|
||||
version = "0.1.4"
|
||||
dependencies = [
|
||||
"arbitrary",
|
||||
"crossterm",
|
||||
"regex",
|
||||
"tui",
|
||||
]
|
||||
|
||||
|
||||
@@ -10,10 +10,8 @@ cargo-fuzz = true
|
||||
|
||||
[dependencies]
|
||||
libfuzzer-sys = "0.4"
|
||||
arbitrary = { version = "1", features = ["derive"] }
|
||||
|
||||
[dependencies.tui-textarea]
|
||||
path = ".."
|
||||
arbitrary = "1"
|
||||
tui-textarea = { path = "..", features = ["search", "arbitrary"] }
|
||||
|
||||
# Prevent this from interfering with workspaces
|
||||
[workspace]
|
||||
|
||||
@@ -4,77 +4,19 @@ use arbitrary::{Arbitrary, Result, Unstructured};
|
||||
use libfuzzer_sys::fuzz_target;
|
||||
use std::iter;
|
||||
use std::str;
|
||||
use tui_textarea::{Input, Key, 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,
|
||||
}
|
||||
}
|
||||
}
|
||||
use tui_textarea::{Input, TextArea};
|
||||
|
||||
fn fuzz(data: &[u8]) -> Result<()> {
|
||||
let mut u = Unstructured::new(data);
|
||||
let inputs: Vec<_> = iter::repeat_with(|| ArbitraryInput::arbitrary(&mut u))
|
||||
.take(10)
|
||||
let inputs: Vec<_> = iter::repeat_with(|| Input::arbitrary(&mut u))
|
||||
.take(100)
|
||||
.collect::<Result<_>>()?;
|
||||
let text = <&str>::arbitrary(&mut u)?;
|
||||
let mut textarea = TextArea::from(text.lines());
|
||||
for input in inputs {
|
||||
textarea.input(input);
|
||||
let _ = textarea.widget();
|
||||
}
|
||||
let _ = textarea.widget();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user