use slash_lang::parser::ast::Urgency;
use slash_lang::parser::errors::ParseError;
use slash_lang::parser::parse;
use slash_lang::parser::suffixes::strip_optional;

#[test]
fn strip_optional_suffix() {
    assert_eq!(strip_optional("/foo?"), Ok(("/foo", true)));
    assert_eq!(strip_optional("/foo"), Ok(("/foo", false)));
    assert_eq!(strip_optional("/foo??"), Err(()));
}

#[test]
fn double_optional_is_parse_error() {
    assert_eq!(
        parse("/foo??"),
        Err(ParseError::InvalidSuffix {
            token: "/foo??".to_string(),
            position: 0
        })
    );
}

#[test]
fn parses_optional_command() {
    let prog = parse("/foo?").unwrap();
    let cmd = &prog.pipelines[0].commands[0];
    assert!(cmd.optional);
    assert_eq!(cmd.name, "foo");
}

#[test]
fn parses_optional_with_urgency() {
    let prog = parse("/foo?!!").unwrap();
    let cmd = &prog.pipelines[0].commands[0];
    assert!(cmd.optional);
    assert_eq!(cmd.urgency, Urgency::Medium);
    assert_eq!(cmd.name, "foo");
}

#[test]
fn non_optional_command_has_optional_false() {
    let prog = parse("/foo!!").unwrap();
    let cmd = &prog.pipelines[0].commands[0];
    assert!(!cmd.optional);
}
