<commit_before>extern crate clap;

use clap::{App, Arg, ErrorKind};

#[test]
fn posix_compatible_flags_long() {
    let m = App::new("posix")
        .arg(Arg::from_usage("--flag  'some flag'").overrides_with("color"))
        .arg(Arg::from_usage("--color 'some other flag'"))
        .get_matches_from(vec!["", "--flag", "--color"]);
    assert!(m.is_present("color"));
    assert!(!m.is_present("flag"));
}

#[test]
fn posix_compatible_flags_long_rev() {
    let m = App::new("posix")
        .arg(Arg::from_usage("--flag  'some flag'").overrides_with("color"))
        .arg(Arg::from_usage("--color 'some other flag'"))
        .get_matches_from(vec!["", "--color", "--flag"]);
    assert!(!m.is_present("color"));
    assert!(m.is_present("flag"));
}

#[test]
fn posix_compatible_flags_short() {
    let m = App::new("posix")
        .arg(Arg::from_usage("-f, --flag  'some flag'").overrides_with("color"))<commit_msg>tests(Self Overrides): adds tests for args that override themselves<commit_after>extern crate clap;

use clap::{App, Arg, ErrorKind};
#[test]
fn flag_overrides_itself() {
    let res = App::new("posix")
                .arg(Arg::from_usage("--flag  'some flag'").overrides_with("flag"))
                .get_matches_from_safe(vec!["", "--flag", "--flag"]);
    assert!(res.is_ok());
    let m = res.unwrap();
    assert!(m.is_present("flag"));
    assert_eq!(m.occurrences_of("flag"), 1);
}

#[test]
fn mult_flag_overrides_itself() {
    let res = App::new("posix")
                .arg(Arg::from_usage("--flag...  'some flag'").overrides_with("flag"))
                .get_matches_from_safe(vec!["", "--flag", "--flag", "--flag", "--flag"]);
    assert!(res.is_ok());
    let m = res.unwrap();
    assert!(m.is_present("flag"));
    assert_eq!(m.occurrences_of("flag"), 4);
}

#[test]
fn option_overrides_itself() {
    let res = App::new("posix")
                .arg(Arg::from_usage("--opt [val] 'some option'").overrides_with("opt"))
                .get_matches_from_safe(vec!["", "--opt=some", "--opt=other"]);
    assert!(res.is_ok());
    let m = res.unwrap();
    assert!(m.is_present("opt"));
    assert_eq!(m.occurrences_of("opt"), 1);
    assert_eq!(m.value_of("opt"), Some("other"));
}

#[test]
fn mult_option_require_delim_overrides_itself() {
    let res = App::new("posix")
                .arg(Arg::from_usage("--opt [val]... 'some option'")
                    .overrides_with("opt")
                    .number_of_values(1)
                    .require_delimiter(true))
                .get_matches_from_safe(vec!["", "--opt=some", "--opt=other", "--opt=one,two"]);
    assert!(res.is_ok());
    let m = res.unwrap();
    assert!(m.is_present("opt"));
    assert_eq!(m.occurrences_of("opt"), 3);
    assert_eq!(m.values_of("opt").unwrap().collect::<Vec<_>>(), &["some", "other", "one", "two"]);
}

#[test]
fn mult_option_overrides_itself() {
    let res = App::new("posix")
                .arg(Arg::from_usage("--opt [val]... 'some option'")
                    .overrides_with("opt"))
                .get_matches_from_safe(vec!["", "--opt", "first", "overides", "--opt", "some", "other", "val"]);
    assert!(res.is_ok());
    let m = res.unwrap();
    assert!(m.is_present("opt"));
    assert_eq!(m.occurrences_of("opt"), 2);
    assert_eq!(m.values_of("opt").unwrap().collect::<Vec<_>>(), &["first", "overides", "some", "other", "val"]);
}

#[test]
fn option_use_delim_false_override_itself() {

    let m = App::new("posix")
                .arg(Arg::from_usage("--opt [val] 'some option'")
                    .overrides_with("opt"))
                .get_matches_from(vec!["", "--opt=some,other", "--opt=one,two"]);
    assert!(m.is_present("opt"));
    assert_eq!(m.occurrences_of("opt"), 1);
    assert_eq!(m.values_of("opt").unwrap().collect::<Vec<_>>(), &["one,two"]);
}

#[test]
fn pos_mult_overrides_itself() {
    // opts with multiple
    let res = App::new("posix")
                .arg(Arg::from_usage("[val]... 'some pos'").overrides_with("val"))
                .get_matches_from_safe(vec!["", "some", "other", "value"]);
    assert!(res.is_ok());
    let m = res.unwrap();
    assert!(m.is_present("val"));
    assert_eq!(m.occurrences_of("val"), 3);
    assert_eq!(m.values_of("val").unwrap().collect::<Vec<_>>(), &["some", "other", "value"]);
}
#[test]
fn posix_compatible_flags_long() {
    let m = App::new("posix")
        .arg(Arg::from_usage("--flag  'some flag'").overrides_with("color"))
        .arg(Arg::from_usage("--color 'some other flag'"))
        .get_matches_from(vec!["", "--flag", "--color"]);
    assert!(m.is_present("color"));
    assert!(!m.is_present("flag"));
}

#[test]
fn posix_compatible_flags_long_rev() {
    let m = App::new("posix")
        .arg(Arg::from_usage("--flag  'some flag'").overrides_with("color"))
        .arg(Arg::from_usage("--color 'some other flag'"))
        .get_matches_from(vec!["", "--color", "--flag"]);
    assert!(!m.is_present("color"));
    assert!(m.is_present("flag"));
}

#[test]
fn posix_compatible_flags_short() {
    let m = App::new("posix")
        .arg(Arg::from_usage("-f, --flag  'some flag'").overrides_with("color"))
{'fraction_non_alphanumeric': 0.23335274703940984, 'fraction_numerical': 0.0015530964861192001, 'mean_word_length': 3.3661016949152542, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '3188726', 'n_tokens_mistral': 1843, 'n_tokens_neox': 1845, 'n_words': 282}