<commit_before>use common::util::*;

static UTIL_NAME: &'static str = "basename";
fn new_ucmd() -> UCommand {
    TestScenario::new(UTIL_NAME).ucmd()
}

fn expect_successful_stdout(input: Vec<&str>, expected: &str) {
    let results = new_ucmd()
        .args(&input).run();
    assert_empty_stderr!(results);
    assert!(results.success);
    assert_eq!(expected, results.stdout.trim_right());
}

#[test]
fn test_directory() {
    let dir = "/root/alpha/beta/gamma/delta/epsilon/omega/";
    expect_successful_stdout(vec![dir], "omega");
}

#[test]
fn test_file() {
    let file = "/etc/passwd";
    expect_successful_stdout(vec![file], "passwd");
}

#[test]
fn test_remove_suffix() {
    let path = "/usr/local/bin/reallylongexecutable.exe";
    expect_successful_stdout(vec![path, ".exe"], "reallylongexecutable");
}

#[test]
fn test_dont_remove_suffix() {
    let path = "/foo/bar/baz";
    expect_successful_stdout(vec![path, "baz"], "baz");
}

fn expect_error(input: Vec<&str>, expected_stdout: &str) {
    let results = new_ucmd()
        .args(&input).run();
    assert!(!results.success);
    assert!(results.stderr.len() > 0);
    assert_eq!(expected_stdout, results.stdout.trim_right());
}

#[cfg_attr(not(feature="test_unimplemented"),ignore)]
#[test]
fn test_multiple_param() {
    for multiple_param in vec!["-a", "--multiple"] {
        let path = "/foo/bar/baz";
        expect_successful_stdout(vec![multiple_param, path, path], "baz\nbaz");
    }
}

#[cfg_attr(not(feature="test_unimplemented"),ignore)]
#[test]
fn test_suffix_param() {
    for suffix_param in vec!["-s", "--suffix"] {
        let path = "/foo/bar/baz.exe";
        let suffix = ".exe";
        expect_successful_stdout(
            vec![suffix_param, suffix, path, path],
            "baz\nbaz"
        );
    }
}

#[cfg_attr(not(feature="test_unimplemented"),ignore)]
#[test]
fn test_zero_param() {
    for zero_param in vec!["-z", "--zero"] {
        let path = "/foo/bar/baz";
        expect_successful_stdout(vec![zero_param, "-a", path, path], "baz\0baz\0");
    }
}

#[test]
fn test_invalid_option() {
    let path = "/foo/bar/baz";
    expect_error(vec!["-q", path], "");
}

#[test]
fn test_no_args() {
    expect_error(vec![], "");
}

#[test]
fn test_too_many_args() {
    expect_error(vec!["a", "b", "c"], "");
}
<commit_msg>tests/basename: use chaining for brevity and consistency<commit_after>use common::util::*;

static UTIL_NAME: &'static str = "basename";
fn new_ucmd() -> UCommand {
    TestScenario::new(UTIL_NAME).ucmd()
}

#[test]
fn test_directory() {
    new_ucmd().args(&["/root/alpha/beta/gamma/delta/epsilon/omega/"])
        .succeeds().stdout_only("omega");
}

#[test]
fn test_file() {
    new_ucmd().args(&["/etc/passwd"]).succeeds().stdout_only("passwd");
}

#[test]
fn test_remove_suffix() {
    new_ucmd().args(&["/usr/local/bin/reallylongexecutable.exe", ".exe"])
        .succeeds().stdout_only("reallylongexecutable");
}

#[test]
fn test_dont_remove_suffix() {
    new_ucmd().args(&["/foo/bar/baz", "baz"]).succeeds().stdout_only( "baz");
}

#[cfg_attr(not(feature="test_unimplemented"),ignore)]
#[test]
fn test_multiple_param() {
    for multiple_param in vec!["-a", "--multiple"] {
        let path = "/foo/bar/baz";
        new_ucmd().args(&[multiple_param, path, path])
            .succeeds().stdout_only("baz\nbaz");
    }
}

#[cfg_attr(not(feature="test_unimplemented"),ignore)]
#[test]
fn test_suffix_param() {
    for suffix_param in vec!["-s", "--suffix"] {
        let path = "/foo/bar/baz.exe";
        new_ucmd()
            .args(&[suffix_param, ".exe", path, path])
            .succeeds().stdout_only("baz\nbaz");
    }
}

#[cfg_attr(not(feature="test_unimplemented"),ignore)]
#[test]
fn test_zero_param() {
    for zero_param in vec!["-z", "--zero"] {
        let path = "/foo/bar/baz";
        new_ucmd().args(&[zero_param, "-a", path, path])
            .succeeds().stdout_only("baz\0baz\0");
    }
}


fn expect_error(input: Vec<&str>) {
    assert!(new_ucmd().args(&input)
                .fails().no_stdout().stderr.len() > 0);
}

#[test]
fn test_invalid_option() {
    let path = "/foo/bar/baz";
    expect_error(vec!["-q", path]);
}

#[test]
fn test_no_args() {
    expect_error(vec![]);
}

#[test]
fn test_too_many_args() {
    expect_error(vec!["a", "b", "c"]);
}

{'fraction_non_alphanumeric': 0.20422371779995357, 'fraction_numerical': 0.001392434439545138, 'mean_word_length': 3.7155361050328226, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3791304', 'n_tokens_mistral': 1621, 'n_tokens_neox': 1590, 'n_words': 257}