#![cfg_attr(feature = "clippy", feature(plugin))]
#![cfg_attr(feature = "clippy", plugin(clippy))]
#[macro_export]
macro_rules! trail {
( $($segment:expr),* ) => ( ::std::path::Path::new(__trail!($($segment),*)) );
}
#[doc(hidden)]
#[cfg(not(windows))]
#[macro_export]
macro_rules! __trail {
() => ( "" );
( $base:expr ) => ( $base );
( $base:expr, $($segment:expr),+ ) => ( concat!($base, $("/", $segment),+) );
}
#[doc(hidden)]
#[cfg(windows)]
#[macro_export]
macro_rules! __trail {
() => ( "" );
( $base:expr ) => ( $base );
( $base:expr, $($segment:expr),+ ) => ( concat!($base, $("\\", $segment),+) );
}
#[cfg(test)]
mod tests {
use std::path::Path;
#[test]
fn trail() {
if cfg!(windows) {
assert_eq!(trail!(), Path::new(""));
assert_eq!(trail!(""), Path::new(""));
assert_eq!(trail!("hello"), Path::new("hello"));
assert_eq!(trail!("hello", "world"), Path::new("hello\\world"));
assert_eq!(trail!("", "hello", "world"), Path::new("\\hello\\world"));
} else {
assert_eq!(trail!(), Path::new(""));
assert_eq!(trail!(""), Path::new(""));
assert_eq!(trail!("hello"), Path::new("hello"));
assert_eq!(trail!("hello", "world"), Path::new("hello/world"));
assert_eq!(trail!("", "hello", "world"), Path::new("/hello/world"));
}
}
}