use crate::ast::*;
use crate::parser::parse_markdown;

#[test]
fn callout() {
    let doc = parse_markdown("> [!info]\n> a\n").unwrap();
    assert_eq!(
        doc,
        Document {
            blocks: vec![Block::Callout(Callout {
                level: "info".to_owned(),
                title: None,
                foldable: false,
                open: true,
                blocks: vec![Block::Paragraph(vec![Inline::Text("a".to_owned())]),]
            })]
        }
    );
}

#[test]
fn callout_title() {
    let doc = parse_markdown("> [!info] hello\n> a\n").unwrap();
    assert_eq!(
        doc,
        Document {
            blocks: vec![Block::Callout(Callout {
                level: "info".to_owned(),
                title: Some("hello".to_owned()),
                foldable: false,
                open: true,
                blocks: vec![Block::Paragraph(vec![Inline::Text("a".to_owned())]),]
            })]
        }
    );
}

#[test]
fn callout_nested() {
    let doc = parse_markdown("> [!info]\n>\n> > [!warning]\n> >\n> > nested\n").unwrap();
    assert_eq!(
        doc,
        Document {
            blocks: vec![Block::Callout(Callout {
                level: "info".to_owned(),
                title: None,
                foldable: false,
                open: true,
                blocks: vec![Block::Callout(Callout {
                    level: "warning".to_owned(),
                    title: None,
                    foldable: false,
                    open: true,
                    blocks: vec![Block::Paragraph(vec![Inline::Text("nested".to_owned())]),]
                })]
            })]
        }
    );
}

#[test]
fn callout_nested_title() {
    let doc = parse_markdown("> [!info]\n>\n> > [!warning] oops\n> >\n> > nested\n").unwrap();
    assert_eq!(
        doc,
        Document {
            blocks: vec![Block::Callout(Callout {
                level: "info".to_owned(),
                title: None,
                foldable: false,
                open: true,
                blocks: vec![Block::Callout(Callout {
                    level: "warning".to_owned(),
                    title: Some("oops".to_owned()),
                    foldable: false,
                    open: true,
                    blocks: vec![Block::Paragraph(vec![Inline::Text("nested".to_owned())]),]
                })]
            })]
        }
    );
}

#[test]
fn callout_foldable_open() {
    let doc = parse_markdown("> [!info]+\n> a\n").unwrap();
    assert_eq!(
        doc,
        Document {
            blocks: vec![Block::Callout(Callout {
                level: "info".to_owned(),
                title: None,
                foldable: true,
                open: true,
                blocks: vec![Block::Paragraph(vec![Inline::Text("a".to_owned())]),]
            })]
        }
    );
}

#[test]
fn callout_foldable_open_title() {
    let doc = parse_markdown("> [!info]+ hello\n> a\n").unwrap();
    assert_eq!(
        doc,
        Document {
            blocks: vec![Block::Callout(Callout {
                level: "info".to_owned(),
                title: Some("hello".to_owned()),
                foldable: true,
                open: true,
                blocks: vec![Block::Paragraph(vec![Inline::Text("a".to_owned())]),]
            })]
        }
    );
}

#[test]
fn callout_foldable_closed() {
    let doc = parse_markdown("> [!info]-\n> a\n").unwrap();
    assert_eq!(
        doc,
        Document {
            blocks: vec![Block::Callout(Callout {
                level: "info".to_owned(),
                title: None,
                foldable: true,
                open: false,
                blocks: vec![Block::Paragraph(vec![Inline::Text("a".to_owned())]),]
            })]
        }
    );
}

#[test]
fn callout_foldable_closed_title() {
    let doc = parse_markdown("> [!info]- hello\n> a\n").unwrap();
    assert_eq!(
        doc,
        Document {
            blocks: vec![Block::Callout(Callout {
                level: "info".to_owned(),
                title: Some("hello".to_owned()),
                foldable: true,
                open: false,
                blocks: vec![Block::Paragraph(vec![Inline::Text("a".to_owned())]),]
            })]
        }
    );
}
