use chumsky::Parser;

use crate::{__internal__parse_include_str, __internal__span_macro_include_str, ast::Type};

use super::ty;

use pretty_assertions::assert_eq;

#[test]
fn test_ty() {
    __internal__span_macro_include_str!(
        crate::Span,
        "../../../../../testdata/partial/complex_type.cctmpl"
    );

    assert_eq!(
        __internal__parse_include_str!(
            ty().padded(),
            "../../../../../testdata/partial/complex_type.cctmpl"
        )
        .into_result()
        .unwrap(),
        Type::Array((
            Some(Box::new(Type::Struct(vec![
                (
                    ("id", s!(2..4)),
                    (
                        Some(Type::Options(vec![
                            (Type::Ident("int"), s!(6..9)),
                            (Type::Ident("text"), s!(12..16))
                        ])),
                        s!(6..16)
                    )
                ),
                (("name", s!(18..22)), (None, s!(22..22))),
                (
                    ("recent", s!(24..30)),
                    (Some(Type::Ident("bool")), s!(32..36))
                ),
                (
                    ("coordinates", s!(38..49)),
                    (
                        Some(Type::Options(vec![
                            (
                                Type::Tuple(vec![
                                    (Type::Ident("float"), s!(52..57)),
                                    (Type::Ident("float"), s!(59..64))
                                ]),
                                s!(51..65)
                            ),
                            (
                                Type::Tuple(vec![
                                    (Type::Ident("int"), s!(69..72)),
                                    (Type::Ident("int"), s!(74..77))
                                ]),
                                s!(68..78)
                            ),
                            (
                                Type::Tuple(vec![
                                    (Type::Ident("bool"), s!(82..86)),
                                    (Type::Ident("bool"), s!(88..92))
                                ]),
                                s!(81..93)
                            )
                        ])),
                        s!(51..93)
                    )
                )
            ]))),
            s!(1..94)
        ))
    );
}
