Skip to content

Commit

Permalink
Merge pull request #190 from foolishell/master
Browse files Browse the repository at this point in the history
feat: add url feature
  • Loading branch information
cksac authored Aug 8, 2024
2 parents edef685 + c736536 commit 93c02c0
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Available features:
- `time`
- `zerocopy`
- `glam`
- `url`
- `always-true-rng`: expose AlwaysTrueRng
- `maybe-non-empty-collections`: allow to use AlwaysTrueRng to generate non-empty collections

Expand Down
1 change: 1 addition & 0 deletions fake/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ rand_core = { version = "0.6", optional = true }
glam = { version = "0.28.0", optional = true }
url-escape = { version = "0.1", optional = true }
bson = { version = "2.10", optional = true }
url = { version = "2.5.2", optional = true }

[dev-dependencies]
chrono = { version = "0.4", features = ["clock"], default-features = false }
Expand Down
1 change: 1 addition & 0 deletions fake/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Available features:
- `time`
- `zerocopy`
- `glam`
- `url`
- `always-true-rng`: expose AlwaysTrueRng
- `maybe-non-empty-collections`: allow to use AlwaysTrueRng to generate non-empty collections

Expand Down
2 changes: 2 additions & 0 deletions fake/src/impls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ pub mod std;
pub mod time;
#[cfg(feature = "ulid")]
pub mod ulid;
#[cfg(feature = "url")]
pub mod url;
#[cfg(feature = "uuid")]
pub mod uuid;
#[cfg(feature = "zerocopy")]
Expand Down
45 changes: 45 additions & 0 deletions fake/src/impls/url/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +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: &str = PATHS.choose(rng).unwrap();
Url::parse(&format!("{FQDN}{path}")).unwrap()
}
}

0 comments on commit 93c02c0

Please sign in to comment.