From c736536a9b80d557bd52662aab13e1cea2086ea3 Mon Sep 17 00:00:00 2001 From: Kai Fukushima <38278379+foolishell@users.noreply.github.com> Date: Tue, 6 Aug 2024 12:15:00 +0900 Subject: [PATCH] fix: add PATHS --- fake/src/impls/url/mod.rs | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/fake/src/impls/url/mod.rs b/fake/src/impls/url/mod.rs index 7d41172..e235157 100644 --- a/fake/src/impls/url/mod.rs +++ b/fake/src/impls/url/mod.rs @@ -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 for Url { fn dummy_with_rng(_: &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() } }