Skip to content

Commit

Permalink
[ref #152] basic test setup for namespace expansion
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Aug 9, 2021
1 parent b4d3934 commit e852399
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 0 deletions.
2 changes: 2 additions & 0 deletions git-ref/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ pub mod mutable;
///
pub mod name;
///
pub mod namespace;
///
pub mod transaction;

/// A validated and potentially partial reference name - it can safely be used for common operations.
Expand Down
1 change: 1 addition & 0 deletions git-ref/src/name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ mod error {

quick_error! {
/// The error used in the [`PartialName`][super::PartialName]::try_from(…) implementations.
/// TODO: remove this error, turning it into the inner one. This is an unnecessary proxy
#[derive(Debug)]
#[allow(missing_docs)]
pub enum Error {
Expand Down
35 changes: 35 additions & 0 deletions git-ref/src/namespace.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#![allow(missing_docs)]

use crate::PartialName;
use std::convert::TryInto;

pub fn expand<'a, Name, E>(namespace: Name) -> Result<crate::mutable::FullName, expand::Error>
where
Name: TryInto<PartialName<'a>, Error = E>,
expand::Error: From<E>,
{
let _namespace = namespace.try_into()?;
todo!("impl")
}

pub mod expand {
use quick_error::quick_error;
use std::convert::Infallible;

quick_error! {
#[derive(Debug)]
pub enum Error {
RefnameValidation(err: crate::name::Error) {
display("The ref name or path is not a valid ref name")
from()
source(err)
}
}
}

impl From<Infallible> for Error {
fn from(_: Infallible) -> Self {
unreachable!("this impl is needed to allow passing a known valid partial path as parameter")
}
}
}
28 changes: 28 additions & 0 deletions git-ref/tests/namespace/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
mod expand {
#[test]
fn each_component_expands_to_the_namespace_prefix_individually() {
assert_eq!(
git_ref::namespace::expand("foo/bar").unwrap().as_bstr(),
"refs/namespaces/foo/refs/namespaces/bar/"
)
}

#[test]
#[ignore]
fn only_backslashes_are_valid_component_separators() {}

#[test]
#[ignore]
fn trailing_slashes_do_nothing() {}

#[test]
fn empty_namespaces_are_not_allowed() {
assert!(matches!(
git_ref::namespace::expand("").expect_err("empty invalid"),
git_ref::namespace::expand::Error::RefnameValidation(git_ref::name::Error::RefnameValidation {
err: git_validate::refname::Error::Tag(git_validate::tag::name::Error::Empty),
..
})
))
}
}
1 change: 1 addition & 0 deletions git-ref/tests/refs-parallel.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
type Result<T = ()> = std::result::Result<T, Box<dyn std::error::Error>>;

mod file;
mod namespace;
mod packed;
mod transaction;
1 change: 1 addition & 0 deletions git-ref/tests/refs.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
type Result<T = ()> = std::result::Result<T, Box<dyn std::error::Error>>;

mod file;
mod namespace;
mod packed;
mod transaction;

0 comments on commit e852399

Please sign in to comment.