treeflow 0.2.1

CLI tool for simplified Git worktree management to speed up switching contexts when working collaboratively.
Documentation
pub trait StringExtensions {
    /// Trim all carriage return characters (\r, \n) from the end of a string.
    fn trim_cr_end(&self) -> String;
}

impl<T> StringExtensions for T
where
    T: AsRef<str>,
{
    fn trim_cr_end(&self) -> String {
        let mut result = self.as_ref().to_string();
        while result.ends_with('\r') || result.ends_with('\n') {
            result.truncate(result.len() - 1);
        }

        result
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn linux() {
        let input = "hello\n";
        let result = input.trim_cr_end();
        assert_eq!(result, "hello");
    }

    #[test]
    fn mac() {
        let input = "hello\r";
        let result = input.trim_cr_end();
        assert_eq!(result, "hello");
    }

    #[test]
    fn windows() {
        let input = "hello\r\n";
        let result = input.trim_cr_end();
        assert_eq!(result, "hello");
    }

    #[test]
    fn no_carriage_returns() {
        let input = "hello";
        let result = input.trim_cr_end();
        assert_eq!(result, "hello");
    }

    #[test]
    fn empty_string() {
        let input = "";
        let result = input.trim_cr_end();
        assert_eq!(result, "");
    }

    #[test]
    fn only_carriage_returns() {
        let input = "\n\r\n";
        let result = input.trim_cr_end();
        assert_eq!(result, "");
    }

    #[test]
    fn string_type() {
        let input = String::from("hello\n");
        let result = input.trim_cr_end();
        assert_eq!(result, "hello");
    }

    #[test]
    fn mixed() {
        let input = "hello\n\r";
        let result = input.trim_cr_end();
        assert_eq!(result, "hello");
    }
}