2024-07-30 21:02:25 +03:00
mod normalize_branch_name {
use gitbutler_reference ::normalize_branch_name ;
#[ test ]
fn valid_substitutions ( ) {
for ( input , expected ) in [
( " a " , " a " ) ,
( " a+b " , " a-b " ) ,
( " a^b " , " a-b " ) ,
( " a~b " , " a-b " ) ,
( " a<b " , " a-b " ) ,
( " a>b " , " a-b " ) ,
( " a \\ b " , " a-b " ) ,
( " a:b " , " a-b " ) ,
( " a*b " , " a-b " ) ,
( " a b " , " a-b " ) ,
( " a \t b " , " a-b " ) ,
( " a \n b " , " a-b " ) ,
( " a \r b " , " a-b " ) ,
( " a \r \n b " , " a-b " ) ,
( " -a- " , " a " ) ,
( " /a/ " , " a " ) ,
( " -/a/- " , " a " ) ,
( " /-a-/ " , " a " ) ,
] {
assert_eq! ( normalize_branch_name ( input ) . expect ( " valid " ) , expected ) ;
}
}
#[ test ]
fn clear_error_on_failure ( ) {
assert_eq! (
normalize_branch_name ( " - " ) . unwrap_err ( ) . to_string ( ) ,
" Could not turn \" \" into a valid reference name "
) ;
assert_eq! (
normalize_branch_name ( " #[test] " ) . unwrap_err ( ) . to_string ( ) ,
" Could not turn \" #[test] \" into a valid reference name "
) ;
2024-08-01 23:03:48 +03:00
let input = r #" Revert " GitButler Integration Commit "
This reverts commit d6efa5fd96d36da445d5d1345b84163f05f5f229 . " #;
let err = normalize_branch_name ( input ) . unwrap_err ( ) . to_string ( ) ;
assert_eq! (
err ,
" Could not turn \" Revert- \\ \" GitButler-Integration-Commit \\ \" -This-reverts-commit-d6efa5fd96d36da445d5d1345b84163f05f5f229. \" into a valid reference name "
) ;
2024-07-30 21:02:25 +03:00
}
#[ test ]
fn complex_valid ( ) -> anyhow ::Result < ( ) > {
assert_eq! ( normalize_branch_name ( " feature/branch " ) ? , " feature/branch " ) ;
assert_eq! ( normalize_branch_name ( " foo#branch " ) ? , " foo#branch " ) ;
assert_eq! ( normalize_branch_name ( " foo!branch " ) ? , " foo!branch " ) ;
Ok ( ( ) )
}
}