diff --git a/fuzz/.gitignore b/fuzz/.gitignore new file mode 100644 index 0000000..08ba2bb --- /dev/null +++ b/fuzz/.gitignore @@ -0,0 +1,3 @@ + +target +libfuzzer diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml new file mode 100644 index 0000000..dcedb4e --- /dev/null +++ b/fuzz/Cargo.toml @@ -0,0 +1,24 @@ + +[package] +name = "unicode-segmentation-fuzz" +version = "0.0.1" +authors = ["Automatically generated"] + +[dependencies.unicode-segmentation] +path = ".." + +# Prevent this from interfering with workspaces +[workspace] +members = ["."] + +[[bin]] +name = "graphemes" +path = "fuzzers/graphemes.rs" + +[[bin]] +name = "words" +path = "fuzzers/words.rs" + +[[bin]] +name = "equality" +path = "fuzzers/equality.rs" diff --git a/fuzz/fuzzers/equality.rs b/fuzz/fuzzers/equality.rs new file mode 100644 index 0000000..89715f4 --- /dev/null +++ b/fuzz/fuzzers/equality.rs @@ -0,0 +1,16 @@ +#![no_main] + +extern crate libfuzzer_sys; +extern crate unicode_segmentation; +use std::str; +use unicode_segmentation::UnicodeSegmentation; +#[export_name="rust_fuzzer_test_input"] +pub extern fn go(data: &[u8]) { + if let Ok(s) = str::from_utf8(data) { + let result = UnicodeSegmentation::graphemes(s, true).flat_map(|s| s.chars()).collect::(); + assert_eq!(s, result); + let result = s.split_word_bounds().flat_map(|s| s.chars()).collect::(); + assert_eq!(s, result); + + } +} diff --git a/fuzz/fuzzers/graphemes.rs b/fuzz/fuzzers/graphemes.rs new file mode 100644 index 0000000..6c985da --- /dev/null +++ b/fuzz/fuzzers/graphemes.rs @@ -0,0 +1,19 @@ +#![no_main] + + +extern crate libfuzzer_sys; + + +extern crate unicode_segmentation; + +use unicode_segmentation::UnicodeSegmentation; +use std::str; + + +#[export_name="rust_fuzzer_test_input"] +pub extern fn go(data: &[u8]) { + if let Ok(s) = str::from_utf8(data) { + let g = UnicodeSegmentation::graphemes(s, true).collect::>(); + assert!(UnicodeSegmentation::graphemes(s, true).rev().eq(g.iter().rev().cloned())); + } +} diff --git a/fuzz/fuzzers/words.rs b/fuzz/fuzzers/words.rs new file mode 100644 index 0000000..6daf056 --- /dev/null +++ b/fuzz/fuzzers/words.rs @@ -0,0 +1,19 @@ +#![no_main] + + +extern crate libfuzzer_sys; + + +extern crate unicode_segmentation; + +use unicode_segmentation::UnicodeSegmentation; +use std::str; + + +#[export_name="rust_fuzzer_test_input"] +pub extern fn go(data: &[u8]) { + if let Ok(s) = str::from_utf8(data) { + let g = s.split_word_bounds().collect::>(); + assert!(s.split_word_bounds().rev().eq(g.iter().rev().cloned())); + } +}