Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ utf-8 = "0.7"
criterion = "0.6"
env_logger = "0.10"
libtest-mimic = "0.8.1"
rand = "0.4"
rand = "0.9"
serde_json = "1.0"
typed-arena = "2.0.2"
19 changes: 10 additions & 9 deletions tendril/examples/fuzz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ extern crate tendril;

use std::borrow::ToOwned;

use rand::distributions::{IndependentSample, Range};
use rand::distr::uniform::Uniform as Range;
use rand::distr::Distribution;
use rand::Rng;
use tendril::StrTendril;

fn fuzz() {
let mut rng = rand::thread_rng();
let capacity = Range::new(0u32, 1 << 14).ind_sample(&mut rng);
let mut rng = rand::rng();
let capacity = Range::new(0u32, 1 << 14).unwrap().sample(&mut rng);
let mut buf_string = String::with_capacity(capacity as usize);
let mut buf_tendril = StrTendril::with_capacity(capacity);
let mut string_slices = vec![];
Expand All @@ -34,8 +35,8 @@ fn fuzz() {
buf_tendril.clear();
}

let dist_action = Range::new(0, 100);
match dist_action.ind_sample(&mut rng) {
let dist_action = Range::new(0, 100).unwrap();
match dist_action.sample(&mut rng) {
0..=15 => {
let (start, end) = random_slice(&mut rng, TEXT);
let snip = &TEXT[start..end];
Expand Down Expand Up @@ -82,7 +83,7 @@ fn fuzz() {
},

91..=96 => {
let c = rng.gen();
let c = rng.random();
buf_string.push(c);
assert!(buf_tendril.try_push_char(c).is_ok());
assert_eq!(&*buf_string, &*buf_tendril);
Expand Down Expand Up @@ -110,7 +111,7 @@ fn fuzz() {

fn random_boundary<R: Rng>(rng: &mut R, text: &str) -> usize {
loop {
let i = Range::new(0, text.len() + 1).ind_sample(rng);
let i = Range::new(0, text.len() + 1).unwrap().sample(rng);
if text.is_char_boundary(i) {
return i;
}
Expand All @@ -119,8 +120,8 @@ fn random_boundary<R: Rng>(rng: &mut R, text: &str) -> usize {

fn random_slice<R: Rng>(rng: &mut R, text: &str) -> (usize, usize) {
loop {
let start = Range::new(0, text.len() + 1).ind_sample(rng);
let end = Range::new(start, text.len() + 1).ind_sample(rng);
let start = Range::new(0, text.len() + 1).unwrap().sample(rng);
let end = Range::new(start, text.len() + 1).unwrap().sample(rng);
if !text.is_char_boundary(start) {
continue;
}
Expand Down