mirror of
https://seed.radicle.dev/rad:z6cFWeWpnZNHh9rUW8phgA3b5yGt.git
synced 2026-11-29 22:20:27 +08:00
move git-ref-format to under radicle-git-ext
Signed-off-by: Han Xu <keepsimple@gmail.com>
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
// Copyright © 2022 The Radicle Link Contributors
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
use std::convert::TryFrom;
|
||||
|
||||
use proptest::prelude::*;
|
||||
use radicle_git_ext::ref_format::{name, refname, Error, RefStr, RefString};
|
||||
use test_helpers::roundtrip;
|
||||
|
||||
use crate::git_ref_format::gen;
|
||||
|
||||
proptest! {
|
||||
#[test]
|
||||
fn valid(input in gen::valid()) {
|
||||
assert_eq!(input.as_str(), RefStr::try_from_str(&input).unwrap().as_str())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_char(input in gen::with_invalid_char()) {
|
||||
assert_matches!(RefString::try_from(input), Err(Error::InvalidChar(_)))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dot_lock(input in gen::ends_with_dot_lock()) {
|
||||
assert_matches!(RefString::try_from(input), Err(Error::DotLock))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn double_dot(input in gen::with_double_dot()) {
|
||||
assert_matches!(RefString::try_from(input), Err(Error::DotDot))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn starts_dot(input in gen::starts_with_dot()) {
|
||||
assert_matches!(RefString::try_from(input), Err(Error::StartsDot))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ends_dot(input in gen::ends_with_dot()) {
|
||||
assert_matches!(RefString::try_from(input), Err(Error::EndsDot))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn control_char(input in gen::with_control_char()) {
|
||||
assert_matches!(RefString::try_from(input), Err(Error::Control))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn space(input in gen::with_space()) {
|
||||
assert_matches!(RefString::try_from(input), Err(Error::Space))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn consecutive_slashes(input in gen::with_consecutive_slashes()) {
|
||||
assert_matches!(RefString::try_from(input), Err(Error::Slash))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn glob(input in gen::with_glob()) {
|
||||
assert_matches!(RefString::try_from(input), Err(Error::InvalidChar('*')))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid(input in gen::invalid()) {
|
||||
assert_matches!(RefString::try_from(input), Err(_))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn roundtrip_components(input in gen::valid()) {
|
||||
assert_eq!(
|
||||
input.as_str(),
|
||||
RefStr::try_from_str(&input).unwrap().components().collect::<RefString>().as_str()
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn json(input in gen::valid()) {
|
||||
let input = RefString::try_from(input).unwrap();
|
||||
roundtrip::json(input.clone());
|
||||
let qualified = refname!("refs/heads").and(input).qualified().unwrap().into_owned();
|
||||
roundtrip::json(qualified.clone());
|
||||
let namespaced = qualified.with_namespace(name::component!("foo"));
|
||||
roundtrip::json(namespaced);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn json_value(input in gen::valid()) {
|
||||
let input = RefString::try_from(input).unwrap();
|
||||
roundtrip::json_value(input.clone());
|
||||
let qualified = refname!("refs/heads").and(input).qualified().unwrap().into_owned();
|
||||
roundtrip::json_value(qualified.clone());
|
||||
let namespaced = qualified.with_namespace(name::component!("foo"));
|
||||
roundtrip::json_value(namespaced);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cbor(input in gen::valid()) {
|
||||
roundtrip::cbor(RefString::try_from(input).unwrap())
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
// Copyright © 2022 The Radicle Link Contributors
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
use std::convert::TryFrom;
|
||||
|
||||
use proptest::prelude::*;
|
||||
use radicle_git_ext::ref_format::{refspec, Error};
|
||||
use test_helpers::roundtrip;
|
||||
|
||||
use crate::git_ref_format::gen;
|
||||
|
||||
proptest! {
|
||||
#[test]
|
||||
fn valid(input in gen::with_glob()) {
|
||||
assert_eq!(input.as_str(), refspec::PatternStr::try_from_str(&input).unwrap().as_str())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn refname_is_pattern(input in gen::valid()) {
|
||||
assert_eq!(input.as_str(), refspec::PatternStr::try_from_str(&input).unwrap().as_str())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_more_than_one_star(input in gen::multi_glob()) {
|
||||
assert_matches!(refspec::PatternString::try_from(input), Err(Error::Pattern))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_refname_is_invalid_pattern(input in gen::invalid()) {
|
||||
assert_matches!(refspec::PatternString::try_from(input), Err(_))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn roundtrip_components(input in gen::with_glob()) {
|
||||
assert_eq!(
|
||||
input.as_str(),
|
||||
refspec::PatternStr::try_from_str(&input)
|
||||
.unwrap()
|
||||
.components()
|
||||
.collect::<Result<refspec::PatternString, _>>()
|
||||
.unwrap()
|
||||
.as_str()
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn json(input in gen::with_glob()) {
|
||||
roundtrip::json(refspec::PatternString::try_from(input).unwrap())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn json_value(input in gen::with_glob()) {
|
||||
roundtrip::json_value(refspec::PatternString::try_from(input).unwrap())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cbor(input in gen::with_glob()) {
|
||||
roundtrip::cbor(refspec::PatternString::try_from(input).unwrap())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user