use super::*;

const SYNTHETIC: &str = "AREA BRIEFING FOR 3857N07727W WITHIN 25 NM\n\
METAR KIAD 041952Z 28008KT 10SM FEW250 29/13 A3003=\n\
SPECI KIAD 042015Z 28012G18KT 10SM FEW250 30/13 A3002=\n\
TAF KIAD 041730Z 0418/0524 30015KT P6SM BKN040=\n\
METAR KJYO 041952Z 27005KT 10SM CLR 28/14 A3003=\n\
END OF BRIEFING";

#[test]
fn extracts_metar_speci_and_taf_with_station_and_kind() {
    let products = extract_products(SYNTHETIC);
    assert_eq!(
        products.len(),
        4,
        "two METAR-class, one SPECI, one TAF; prose lines ignored"
    );

    let kinds: Vec<&ProductKind> = products.iter().map(|p| &p.kind).collect();
    assert_eq!(
        kinds,
        vec![
            &ProductKind::Metar,
            &ProductKind::Metar,
            &ProductKind::Taf,
            &ProductKind::Metar,
        ]
    );
    assert_eq!(products[0].location.as_deref(), Some("KIAD"));
    assert_eq!(products[3].location.as_deref(), Some("KJYO"));
}

#[test]
fn keeps_the_verbatim_line_including_label_and_separator() {
    let products = extract_products(SYNTHETIC);
    assert_eq!(
        products[0].raw_text,
        "METAR KIAD 041952Z 28008KT 10SM FEW250 29/13 A3003="
    );
    assert!(products[2].raw_text.starts_with("TAF KIAD"));
}

#[test]
fn prose_and_blank_lines_yield_no_products() {
    let products = extract_products("AREA BRIEFING\n\n  \nEND OF BRIEFING\nNOTAMS: NONE");
    assert!(products.is_empty());
}

#[test]
fn a_label_without_a_valid_station_is_skipped() {
    // `METAR` with no following station id, and a too-long token.
    let products = extract_products("METAR\nMETAR TOOLONGID 1234Z");
    assert!(products.is_empty());
}
