Skip to content

Commit

Permalink
fix: add PATHS
Browse files Browse the repository at this point in the history
  • Loading branch information
foolishell committed Aug 6, 2024
1 parent 2009f3b commit c736536
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions fake/src/impls/url/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,45 @@
use crate::{Dummy, Fake, Faker};
use rand::seq::SliceRandom;
use rand::Rng;
use url::Url;

const FQDN: &str = "https://example.com";
const PATHS: [&str; 30] = [
"/apple",
"/orange",
"/banana",
"/grape",
"/pear",
"/peach/sweet",
"/melon/fresh",
"/kiwi/season",
"/lemon/acidic",
"/lime/citrus",
"/cherry?sweet=true",
"/berry#mixed",
"/mango?seasonal=true",
"/apricot#dried",
"/avocado?ripe=true",
"/papaya#exotic",
"/fig?type=black",
"/date#sweet",
"/olive?type=black",
"/tomato#fresh",
"/onion?type=red",
"/carrot#organic",
"/potato?type=russet",
"/spinach#fresh",
"/lettuce?crispy=true",
"/cabbage#green",
"/cucumber?seedless=true",
"/pepper#bell",
"/garlic?organic=true",
"/ginger#spicy",
];

impl Dummy<Faker> for Url {
fn dummy_with_rng<R: Rng + ?Sized>(_: &Faker, rng: &mut R) -> Self {
let path: String = Faker.fake_with_rng(rng);
Url::parse(&format!("{FQDN}/{path}")).unwrap()
let path: &str = PATHS.choose(rng).unwrap();
Url::parse(&format!("{FQDN}{path}")).unwrap()
}
}

0 comments on commit c736536

Please sign in to comment.