Skip to content

Commit 58997f7

Browse files
committed
Add fuzzers
1 parent e86a69b commit 58997f7

File tree

4 files changed

+61
-0
lines changed

4 files changed

+61
-0
lines changed

fuzz/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
target
3+
libfuzzer

fuzz/Cargo.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
[package]
3+
name = "unicode-segmentation-fuzz"
4+
version = "0.0.1"
5+
authors = ["Automatically generated"]
6+
7+
[dependencies.unicode-segmentation]
8+
path = ".."
9+
10+
# Prevent this from interfering with workspaces
11+
[workspace]
12+
members = ["."]
13+
14+
[[bin]]
15+
name = "graphemes"
16+
path = "fuzzers/graphemes.rs"
17+
18+
[[bin]]
19+
name = "words"
20+
path = "fuzzers/words.rs"

fuzz/fuzzers/graphemes.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#![no_main]
2+
3+
4+
extern crate fuzzer_sys;
5+
6+
7+
extern crate unicode_segmentation;
8+
9+
use unicode_segmentation::UnicodeSegmentation;
10+
use std::str;
11+
12+
13+
#[export_name="rust_fuzzer_test_input"]
14+
pub extern fn go(data: &[u8]) {
15+
if let Ok(s) = str::from_utf8(data) {
16+
let g = UnicodeSegmentation::graphemes(s, true).collect::<Vec<_>>();
17+
assert!(UnicodeSegmentation::graphemes(s, true).rev().eq(g.iter().rev().cloned()));
18+
}
19+
}

fuzz/fuzzers/words.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#![no_main]
2+
3+
4+
extern crate fuzzer_sys;
5+
6+
7+
extern crate unicode_segmentation;
8+
9+
use unicode_segmentation::UnicodeSegmentation;
10+
use std::str;
11+
12+
13+
#[export_name="rust_fuzzer_test_input"]
14+
pub extern fn go(data: &[u8]) {
15+
if let Ok(s) = str::from_utf8(data) {
16+
let g = s.split_word_bounds().collect::<Vec<_>>();
17+
assert!(s.split_word_bounds().rev().eq(g.iter().rev().cloned()));
18+
}
19+
}

0 commit comments

Comments
 (0)