Skip to content

Commit

Permalink
Add fuzzers
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Feb 23, 2017
1 parent e86a69b commit 6b63bd2
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 0 deletions.
3 changes: 3 additions & 0 deletions fuzz/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

target
libfuzzer
24 changes: 24 additions & 0 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
14 changes: 14 additions & 0 deletions fuzz/fuzzers/equality.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#![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::<String>();
assert_eq!(s, result);

}
}
19 changes: 19 additions & 0 deletions fuzz/fuzzers/graphemes.rs
Original file line number Diff line number Diff line change
@@ -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::<Vec<_>>();
assert!(UnicodeSegmentation::graphemes(s, true).rev().eq(g.iter().rev().cloned()));
}
}
19 changes: 19 additions & 0 deletions fuzz/fuzzers/words.rs
Original file line number Diff line number Diff line change
@@ -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::<Vec<_>>();
assert!(s.split_word_bounds().rev().eq(g.iter().rev().cloned()));
}
}

0 comments on commit 6b63bd2

Please sign in to comment.