Files
radicle-git/radicle-git-ext/t/src/git_ref_format/gen.rs
T
Fintan Halpenny b570fa1435 Re-License to "MIT OR Aapache-2.0"
The main dependant of `radicle-git`, and its crates, is [`heartwood`].
It is licensed under MIT or Apache-2.0, which has been incompatible with the GPL-3.0 license.
Since the intellectual property of this code base is with the Better Internet Foundation, it was
decided to re-license code in this repository to make the upstream repository compatible.

 - Remove the license headers (and instructions to add them)
 - Add MIT and Apache-2.0 licenses
 - Remove the GPL-3.0 license
 - Change the license declarations in the `Cargo.toml` files

[`heartwood`]: https://app.radicle.xyz/nodes/seed.radicle.xyz/rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5
2025-11-14 12:52:22 +01:00

99 lines
2.3 KiB
Rust

use proptest::prelude::*;
/// Any unicode "word" is trivially a valid refname.
pub fn trivial() -> impl Strategy<Value = String> {
"\\w+"
}
pub fn valid() -> impl Strategy<Value = String> {
prop::collection::vec(trivial(), 1..20).prop_map(|xs| xs.join("/"))
}
pub fn invalid_char() -> impl Strategy<Value = char> {
prop_oneof![
Just('\0'),
Just('\\'),
Just('~'),
Just('^'),
Just(':'),
Just('?'),
Just('[')
]
}
pub fn with_invalid_char() -> impl Strategy<Value = String> {
("\\w*", invalid_char(), "\\w*").prop_map(|(mut pre, invalid, suf)| {
pre.push(invalid);
pre.push_str(&suf);
pre
})
}
pub fn ends_with_dot_lock() -> impl Strategy<Value = String> {
"\\w*\\.lock"
}
pub fn with_double_dot() -> impl Strategy<Value = String> {
"\\w*\\.\\.\\w*"
}
pub fn starts_with_dot() -> impl Strategy<Value = String> {
"\\.\\w*"
}
pub fn ends_with_dot() -> impl Strategy<Value = String> {
"\\w+\\."
}
pub fn with_control_char() -> impl Strategy<Value = String> {
"\\w*[\x01-\x1F\x7F]+\\w*"
}
pub fn with_space() -> impl Strategy<Value = String> {
"\\w* +\\w*"
}
pub fn with_consecutive_slashes() -> impl Strategy<Value = String> {
"\\w*//\\w*"
}
pub fn with_glob() -> impl Strategy<Value = String> {
"\\w*\\*\\w*"
}
pub fn multi_glob() -> impl Strategy<Value = String> {
(
prop::collection::vec(with_glob(), 2..5),
prop::collection::vec(trivial(), 0..5),
)
.prop_map(|(mut globs, mut valids)| {
globs.append(&mut valids);
globs
})
.prop_shuffle()
.prop_map(|xs| xs.join("/"))
}
pub fn invalid() -> impl Strategy<Value = String> {
fn path(s: impl Strategy<Value = String>) -> impl Strategy<Value = String> {
prop::collection::vec(s, 1..20).prop_map(|xs| xs.join("/"))
}
prop_oneof![
Just(String::from("")),
Just(String::from("@")),
path(with_invalid_char()),
path(ends_with_dot_lock()),
path(with_double_dot()),
path(starts_with_dot()),
path(ends_with_dot()),
path(with_control_char()),
path(with_space()),
path(with_consecutive_slashes()),
path(trivial()).prop_map(|mut p| {
p.push('/');
p
}),
]
}