// Author: Mario Sieg
// Project: Corium
//
//                                  Apache License
//                            Version 2.0, January 2004
//                         http://www.apache.org/licenses/
//
//    TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
//
//    1. Definitions.
//
//       "License" shall mean the terms and conditions for use, reproduction,
//       and distribution as defined by Sections 1 through 9 of this document.
//
//       "Licensor" shall mean the copyright owner or entity authorized by
//       the copyright owner that is granting the License.
//
//       "Legal Entity" shall mean the union of the acting entity and all
//       other entities that control, are controlled by, or are under common
//       control with that entity. For the purposes of this definition,
//       "control" means (i) the power, direct or indirect, to cause the
//       direction or management of such entity, whether by contract or
//       otherwise, or (ii) ownership of fifty percent (50%) or more of the
//       outstanding shares, or (iii) beneficial ownership of such entity.
//
//       "You" (or "Your") shall mean an individual or Legal Entity
//       exercising permissions granted by this License.
//
//       "Source" form shall mean the preferred form for making modifications,
//       including but not limited to software source code, documentation
//       source, and configuration files.
//
//       "Object" form shall mean any form resulting from mechanical
//       transformation or translation of a Source form, including but
//       not limited to compiled object code, generated documentation,
//       and conversions to other media types.
//
//       "Work" shall mean the work of authorship, whether in Source or
//       Object form, made available under the License, as indicated by a
//       copyright notice that is included in or attached to the work
//       (an example is provided in the Appendix below).
//
//       "Derivative Works" shall mean any work, whether in Source or Object
//       form, that is based on (or derived from) the Work and for which the
//       editorial revisions, annotations, elaborations, or other modifications
//       represent, as a whole, an original work of authorship. For the purposes
//       of this License, Derivative Works shall not include works that remain
//       separable from, or merely link (or bind by name) to the interfaces of,
//       the Work and Derivative Works thereof.
//
//       "Contribution" shall mean any work of authorship, including
//       the original version of the Work and any modifications or additions
//       to that Work or Derivative Works thereof, that is intentionally
//       submitted to Licensor for inclusion in the Work by the copyright owner
//       or by an individual or Legal Entity authorized to submit on behalf of
//       the copyright owner. For the purposes of this definition, "submitted"
//       means any form of electronic, verbal, or written communication sent
//       to the Licensor or its representatives, including but not limited to
//       communication on electronic mailing lists, source code control systems,
//       and issue tracking systems that are managed by, or on behalf of, the
//       Licensor for the purpose of discussing and improving the Work, but
//       excluding communication that is conspicuously marked or otherwise
//       designated in writing by the copyright owner as "Not a Contribution."
//
//       "Contributor" shall mean Licensor and any individual or Legal Entity
//       on behalf of whom a Contribution has been received by Licensor and
//       subsequently incorporated within the Work.
//
//    2. Grant of Copyright License. Subject to the terms and conditions of
//       this License, each Contributor hereby grants to You a perpetual,
//       worldwide, non-exclusive, no-charge, royalty-free, irrevocable
//       copyright license to reproduce, prepare Derivative Works of,
//       publicly display, publicly perform, sublicense, and distribute the
//       Work and such Derivative Works in Source or Object form.
//
//    3. Grant of Patent License. Subject to the terms and conditions of
//       this License, each Contributor hereby grants to You a perpetual,
//       worldwide, non-exclusive, no-charge, royalty-free, irrevocable
//       (except as stated in this section) patent license to make, have made,
//       use, offer to sell, sell, import, and otherwise transfer the Work,
//       where such license applies only to those patent claims licensable
//       by such Contributor that are necessarily infringed by their
//       Contribution(s) alone or by combination of their Contribution(s)
//       with the Work to which such Contribution(s) was submitted. If You
//       institute patent litigation against any entity (including a
//       cross-claim or counterclaim in a lawsuit) alleging that the Work
//       or a Contribution incorporated within the Work constitutes direct
//       or contributory patent infringement, then any patent licenses
//       granted to You under this License for that Work shall terminate
//       as of the date such litigation is filed.
//
//    4. Redistribution. You may reproduce and distribute copies of the
//       Work or Derivative Works thereof in any medium, with or without
//       modifications, and in Source or Object form, provided that You
//       meet the following conditions:
//
//       (a) You must give any other recipients of the Work or
//           Derivative Works a copy of this License; and
//
//       (b) You must cause any modified files to carry prominent notices
//           stating that You changed the files; and
//
//       (c) You must retain, in the Source form of any Derivative Works
//           that You distribute, all copyright, patent, trademark, and
//           attribution notices from the Source form of the Work,
//           excluding those notices that do not pertain to any part of
//           the Derivative Works; and
//
//       (d) If the Work includes a "NOTICE" text file as part of its
//           distribution, then any Derivative Works that You distribute must
//           include a readable copy of the attribution notices contained
//           within such NOTICE file, excluding those notices that do not
//           pertain to any part of the Derivative Works, in at least one
//           of the following places: within a NOTICE text file distributed
//           as part of the Derivative Works; within the Source form or
//           documentation, if provided along with the Derivative Works; or,
//           within a display generated by the Derivative Works, if and
//           wherever such third-party notices normally appear. The contents
//           of the NOTICE file are for informational purposes only and
//           do not modify the License. You may add Your own attribution
//           notices within Derivative Works that You distribute, alongside
//           or as an addendum to the NOTICE text from the Work, provided
//           that such additional attribution notices cannot be construed
//           as modifying the License.
//
//       You may add Your own copyright statement to Your modifications and
//       may provide additional or different license terms and conditions
//       for use, reproduction, or distribution of Your modifications, or
//       for any such Derivative Works as a whole, provided Your use,
//       reproduction, and distribution of the Work otherwise complies with
//       the conditions stated in this License.
//
//    5. Submission of Contributions. Unless You explicitly state otherwise,
//       any Contribution intentionally submitted for inclusion in the Work
//       by You to the Licensor shall be under the terms and conditions of
//       this License, without any additional terms or conditions.
//       Notwithstanding the above, nothing herein shall supersede or modify
//       the terms of any separate license agreement you may have executed
//       with Licensor regarding such Contributions.
//
//    6. Trademarks. This License does not grant permission to use the trade
//       names, trademarks, service marks, or product names of the Licensor,
//       except as required for reasonable and customary use in describing the
//       origin of the Work and reproducing the content of the NOTICE file.
//
//    7. Disclaimer of Warranty. Unless required by applicable law or
//       agreed to in writing, Licensor provides the Work (and each
//       Contributor provides its Contributions) on an "AS IS" BASIS,
//       WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
//       implied, including, without limitation, any warranties or conditions
//       of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
//       PARTICULAR PURPOSE. You are solely responsible for determining the
//       appropriateness of using or redistributing the Work and assume any
//       risks associated with Your exercise of permissions under this License.
//
//    8. Limitation of Liability. In no event and under no legal theory,
//       whether in tort (including negligence), contract, or otherwise,
//       unless required by applicable law (such as deliberate and grossly
//       negligent acts) or agreed to in writing, shall any Contributor be
//       liable to You for damages, including any direct, indirect, special,
//       incidental, or consequential damages of any character arising as a
//       result of this License or out of the use or inability to use the
//       Work (including but not limited to damages for loss of goodwill,
//       work stoppage, computer failure or malfunction, or any and all
//       other commercial damages or losses), even if such Contributor
//       has been advised of the possibility of such damages.
//
//    9. Accepting Warranty or Additional Liability. While redistributing
//       the Work or Derivative Works thereof, You may choose to offer,
//       and charge a fee for, acceptance of support, warranty, indemnity,
//       or other liability obligations and/or rights consistent with this
//       License. However, in accepting such obligations, You may act only
//       on Your own behalf and on Your sole responsibility, not on behalf
//       of any other Contributor, and only if You agree to indemnify,
//       defend, and hold each Contributor harmless for any liability
//       incurred by, or claims asserted against, such Contributor by reason
//       of your accepting any such warranty or additional liability.
//
//    END OF TERMS AND CONDITIONS
//
//    APPENDIX: How to apply the Apache License to your work.
//
//       To apply the Apache License to your work, attach the following
//       boilerplate notice, with the fields enclosed by brackets "[]"
//       replaced with your own identifying information. (Don't include
//       the brackets!)  The text should be enclosed in the appropriate
//       comment syntax for the file format. We also recommend that a
//       file or class name and description of purpose be included on the
//       same "printed page" as the copyright notice for easier
//       identification within third-party archives.
//
//    Copyright 2021 Mario Sieg "pinsrq" <mt3000@gmx.de>
//
//    Licensed under the Apache License, Version 2.0 (the "License");
//    you may not use this file except in compliance with the License.
//    You may obtain a copy of the License at
//
//        http://www.apache.org/licenses/LICENSE-2.0
//
//    Unless required by applicable law or agreed to in writing, software
//    distributed under the License is distributed on an "AS IS" BASIS,
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//    See the License for the specific language governing permissions and
//    limitations under the License.

use crate::ast::tree::function_signature::FunctionSignature;
use crate::ast::tree::identifier::Identifier;
use crate::ast::tree::parameter::Parameter;
use crate::ast::tree::parameter_list::ParameterList;
use crate::parser::*;

#[test]
fn mangled_name_no_params() {
    let fun = FunctionSignature {
        name: Identifier::new("f"),
        parameters: None,
        return_type: None,
    };
    assert_eq!(fun.overloaded_mangled_name(), "f");
}

#[test]
fn mangled_name_one_param() {
    let fun = FunctionSignature {
        name: Identifier::new("myFunc"),
        parameters: Some(ParameterList(vec![Parameter {
            name: Identifier::new("y"),
            type_hint: Identifier::new("std.Blob"),
            value: None,
        }])),
        return_type: None,
    };
    assert_eq!(fun.overloaded_mangled_name(), "myFunc_std.Blob");
}

#[test]
fn mangled_name_params() {
    let fun = FunctionSignature {
        name: Identifier::new("myFunc"),
        parameters: Some(ParameterList(vec![
            Parameter {
                name: Identifier::new("y"),
                type_hint: Identifier::new("int"),
                value: None,
            },
            Parameter {
                name: Identifier::new("x"),
                type_hint: Identifier::new("float"),
                value: None,
            },
            Parameter {
                name: Identifier::new("z"),
                type_hint: Identifier::new("char"),
                value: None,
            },
        ])),
        return_type: None,
    };
    assert_eq!(fun.overloaded_mangled_name(), "myFunc_int_float_char");
}

mod populators {
    use super::*;

    mod identifier {
        use super::*;
        use crate::ast::populator::NestedAstPopulator;
        use crate::ast::tree::Rule;

        #[test]
        fn alphanumeric() {
            let mut result = CoriumParser::parse(Rule::Identifier, "MyClass").unwrap();
            let ast = Identifier::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.full, "MyClass");
        }

        #[test]
        fn mixed() {
            let mut result = CoriumParser::parse(Rule::Identifier, "My2Class32LOl").unwrap();
            let ast = Identifier::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.full, "My2Class32LOl");
        }

        #[test]
        fn numeric() {
            let mut result = CoriumParser::parse(Rule::Identifier, "X278247842877284").unwrap();
            let ast = Identifier::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.full, "X278247842877284");
        }

        #[test]
        fn simple() {
            let mut result = CoriumParser::parse(Rule::Identifier, "MyPackage").unwrap();
            let ast = Identifier::new(result.next().unwrap().into_inner().as_str());
            assert_eq!(ast.full, "MyPackage");
            assert_eq!(ast.split.len(), 1);
            assert_eq!(ast.split[0], "MyPackage");
        }

        #[test]
        fn nested() {
            let mut result = CoriumParser::parse(Rule::Identifier, "MyPackage.Class").unwrap();
            let ast = Identifier::new(result.next().unwrap().into_inner().as_str());
            assert_eq!(ast.full, "MyPackage.Class");
            assert_eq!(ast.split.len(), 2);
            assert_eq!(ast.split[0], "MyPackage");
            assert_eq!(ast.split[1], "Class");
        }

        #[test]
        fn nested2() {
            let mut result =
                CoriumParser::parse(Rule::Identifier, "MyPackage.Class.StaticMember").unwrap();
            let ast = Identifier::new(result.next().unwrap().into_inner().as_str());
            assert_eq!(ast.full, "MyPackage.Class.StaticMember");
            assert_eq!(ast.split.len(), 3);
            assert_eq!(ast.split[0], "MyPackage");
            assert_eq!(ast.split[1], "Class");
            assert_eq!(ast.split[2], "StaticMember");
        }

        #[test]
        fn nested3() {
            let mut result =
                CoriumParser::parse(Rule::Identifier, "MyPackage.Class.StaticMember.Field")
                    .unwrap();
            let ast = Identifier::new(result.next().unwrap().into_inner().as_str());
            assert_eq!(ast.full, "MyPackage.Class.StaticMember.Field");
            assert_eq!(ast.split.len(), 4);
            assert_eq!(ast.split[0], "MyPackage");
            assert_eq!(ast.split[1], "Class");
            assert_eq!(ast.split[2], "StaticMember");
            assert_eq!(ast.split[3], "Field");
        }
    }

    mod literal {
        use super::*;
        use crate::ast::populator::NestedAstPopulator;
        use crate::ast::tree::literal::Literal;
        use crate::ast::tree::Rule;

        #[test]
        fn float() {
            let mut result = CoriumParser::parse(Rule::Literal, "2.5").unwrap();
            let ast = Literal::populate(result.next().unwrap().into_inner());
            let _f = Literal::Float(2.5);
            assert!(matches!(ast, _f));
        }

        #[test]
        fn int() {
            let mut result = CoriumParser::parse(Rule::Literal, "3").unwrap();
            let ast = Literal::populate(result.next().unwrap().into_inner());
            assert!(matches!(ast, Literal::Int(3)));
        }

        #[test]
        fn boolean() {
            let mut result = CoriumParser::parse(Rule::Literal, "true").unwrap();
            let ast = Literal::populate(result.next().unwrap().into_inner());
            assert!(matches!(ast, Literal::Bool(true)));
        }

        #[test]
        fn character() {
            let mut result = CoriumParser::parse(Rule::Literal, "'X'").unwrap();
            let ast = Literal::populate(result.next().unwrap().into_inner());
            assert!(matches!(ast, Literal::Char('X')));
        }

        #[test]
        fn string() {
            let mut result = CoriumParser::parse(Rule::Literal, "\"Hallo zusammen ;)\"").unwrap();
            let ast = Literal::populate(result.next().unwrap().into_inner());
            assert!(matches!(ast, Literal::String("Hallo zusammen ;)")));
        }

        #[test]
        fn string_empty() {
            let mut result = CoriumParser::parse(Rule::Literal, "\"\"").unwrap();
            let ast = Literal::populate(result.next().unwrap().into_inner());
            assert!(matches!(ast, Literal::String("")));
        }
    }

    mod expression {
        use super::*;
        use crate::ast::populator::NestedAstPopulator;
        use crate::ast::tree::expression::Expression;
        use crate::ast::tree::literal::Literal;
        use crate::ast::tree::Rule;

        #[test]
        fn float_literal() {
            let mut result = CoriumParser::parse(Rule::Expression, "2.5").unwrap();
            let ast = Expression::populate(result.next().unwrap().into_inner());
            let _f = Literal::Float(2.5);
            assert!(matches!(ast, Expression::Literal(_f)));
        }

        #[test]
        fn int_literal() {
            let mut result = CoriumParser::parse(Rule::Expression, "10").unwrap();
            let ast = Expression::populate(result.next().unwrap().into_inner());
            assert!(matches!(ast, Expression::Literal(Literal::Int(10))));
        }

        #[test]
        fn boolean_literal() {
            let mut result = CoriumParser::parse(Rule::Expression, "true").unwrap();
            let ast = Expression::populate(result.next().unwrap().into_inner());
            assert!(matches!(ast, Expression::Literal(Literal::Bool(true))));
        }

        #[test]
        fn character_literal() {
            let mut result = CoriumParser::parse(Rule::Expression, "'X'").unwrap();
            let ast = Expression::populate(result.next().unwrap().into_inner());
            assert!(matches!(ast, Expression::Literal(Literal::Char('X'))));
        }

        #[test]
        fn string_literal() {
            let mut result =
                CoriumParser::parse(Rule::Expression, "\"Hallo zusammen ;)\"").unwrap();
            let ast = Expression::populate(result.next().unwrap().into_inner());
            assert!(matches!(
                ast,
                Expression::Literal(Literal::String("Hallo zusammen ;)"))
            ));
        }

        #[test]
        fn ident() {
            let mut result = CoriumParser::parse(Rule::Expression, "lololo").unwrap();
            let ast = Expression::populate(result.next().unwrap().into_inner());
            let _ident = Identifier::new("lololo");
            assert!(matches!(ast, Expression::Identifier(_ident)));
        }

        #[test]
        fn nested1() {
            let mut result = CoriumParser::parse(Rule::Expression, "(10)").unwrap();
            let ast = Expression::populate(result.next().unwrap().into_inner());
            let _n1 = Box::new(Expression::Literal(Literal::Int(10)));
            assert!(matches!(ast, Expression::Parenthesis(_n1)));
        }

        #[test]
        fn nested2() {
            let mut result = CoriumParser::parse(Rule::Expression, "((10))").unwrap();
            let ast = Expression::populate(result.next().unwrap().into_inner());
            let _n1 = Box::new(Expression::Literal(Literal::Int(10)));
            let _n2 = Box::new(Expression::Parenthesis(_n1));
            assert!(matches!(ast, Expression::Parenthesis(_n2)));
        }

        #[test]
        fn nested3() {
            let mut result = CoriumParser::parse(Rule::Expression, "(((10)))").unwrap();
            let ast = Expression::populate(result.next().unwrap().into_inner());
            let _n1 = Box::new(Expression::Literal(Literal::Int(10)));
            let _n2 = Box::new(Expression::Parenthesis(_n1));
            let _n3 = Box::new(Expression::Parenthesis(_n2));
            assert!(matches!(ast, Expression::Parenthesis(_n3)));
        }

        mod chain_2_tree {
            use super::*;
            use crate::ast::tree::binary_operator::BinaryOperator;

            #[test]
            fn literal_addition() {
                let mut result = CoriumParser::parse(Rule::Expression, "66 + 1").unwrap();
                let ast = Expression::populate(result.next().unwrap().into_inner());
                let _expr = Expression::Binary {
                    lhs: Box::new(Expression::Literal(Literal::Int(66))),
                    op: BinaryOperator::Addition,
                    rhs: Box::new(Expression::Literal(Literal::Int(1))),
                };
                assert!(matches!(ast, _expr));
            }

            #[test]
            fn identifier_addition() {
                let mut result = CoriumParser::parse(Rule::Expression, "66 + x").unwrap();
                let ast = Expression::populate(result.next().unwrap().into_inner());
                let _expr = Expression::Binary {
                    lhs: Box::new(Expression::Literal(Literal::Int(66))),
                    op: BinaryOperator::Addition,
                    rhs: Box::new(Expression::Identifier(Identifier::new("x"))),
                };
                assert!(matches!(ast, _expr));
            }

            mod precedence {
                use super::*;
                use crate::ast::tree::binary_operator::BinaryOperator;

                #[test]
                fn multiply_addition_right() {
                    let mut result = CoriumParser::parse(Rule::Expression, "66 + 1 * 5").unwrap();
                    let result = result.next().unwrap().into_inner();
                    let ast = crate::parser::precedence::climb_expression(result);
                    let _expr = Expression::Binary {
                        lhs: Box::new(Expression::Literal(Literal::Int(66))),
                        op: BinaryOperator::Addition,
                        rhs: Box::new(Expression::Binary {
                            lhs: Box::new(Expression::Literal(Literal::Int(1))),
                            op: BinaryOperator::Multiplication,
                            rhs: Box::new(Expression::Literal(Literal::Int(5))),
                        }),
                    };
                    println!("{}", ast);
                    assert_eq!(ast, _expr);
                }

                #[test]
                fn dual_multiply_addition_right() {
                    let mut result =
                        CoriumParser::parse(Rule::Expression, "66 * 1 & 2 % 5").unwrap();
                    let result = result.next().unwrap().into_inner();
                    let ast = crate::parser::precedence::climb_expression(result);
                    let _expr = Expression::Binary {
                        lhs: Box::new(Expression::Binary {
                            lhs: Box::new(Expression::Literal(Literal::Int(66))),
                            op: BinaryOperator::Multiplication,
                            rhs: Box::new(Expression::Literal(Literal::Int(1))),
                        }),
                        op: BinaryOperator::BitwiseAnd,
                        rhs: Box::new(Expression::Binary {
                            lhs: Box::new(Expression::Literal(Literal::Int(2))),
                            op: BinaryOperator::Modulo,
                            rhs: Box::new(Expression::Literal(Literal::Int(5))),
                        }),
                    };
                    println!("{}", ast);
                    assert_eq!(ast, _expr);
                }

                #[test]
                fn dual_bitwise_calculation_right() {
                    let mut result =
                        CoriumParser::parse(Rule::Expression, "66 ^ 1 | 2 & 5").unwrap();
                    let result = result.next().unwrap().into_inner();
                    let ast = crate::parser::precedence::climb_expression(result);
                    let _expr = Expression::Binary {
                        lhs: Box::new(Expression::Binary {
                            lhs: Box::new(Expression::Literal(Literal::Int(66))),
                            op: BinaryOperator::BitwiseXor,
                            rhs: Box::new(Expression::Literal(Literal::Int(1))),
                        }),
                        op: BinaryOperator::BitwiseOr,
                        rhs: Box::new(Expression::Binary {
                            lhs: Box::new(Expression::Literal(Literal::Int(2))),
                            op: BinaryOperator::BitwiseAnd,
                            rhs: Box::new(Expression::Literal(Literal::Int(5))),
                        }),
                    };
                    println!("{}", ast);
                    assert_eq!(ast, _expr);
                }

                #[test]
                fn multiply_addition_left() {
                    let mut result = CoriumParser::parse(Rule::Expression, "66 * 1 + 5").unwrap();
                    let result = result.next().unwrap().into_inner();
                    let ast = crate::parser::precedence::climb_expression(result);
                    let _expr = Expression::Binary {
                        lhs: Box::new(Expression::Binary {
                            lhs: Box::new(Expression::Literal(Literal::Int(66))),
                            op: BinaryOperator::Multiplication,
                            rhs: Box::new(Expression::Literal(Literal::Int(1))),
                        }),
                        op: BinaryOperator::Addition,
                        rhs: Box::new(Expression::Literal(Literal::Int(5))),
                    };
                    println!("{}", ast);
                    assert_eq!(ast, _expr);
                }

                #[test]
                fn multiply_double_addition() {
                    let mut result =
                        CoriumParser::parse(Rule::Expression, "66 + 1 * 5 + 2").unwrap();
                    let result = result.next().unwrap().into_inner();
                    let ast = crate::parser::precedence::climb_expression(result);
                    let _expr = Expression::Binary {
                        lhs: Box::new(Expression::Binary {
                            lhs: Box::new(Expression::Literal(Literal::Int(66))),
                            op: BinaryOperator::Addition,
                            rhs: Box::new(Expression::Binary {
                                lhs: Box::new(Expression::Literal(Literal::Int(1))),
                                op: BinaryOperator::Multiplication,
                                rhs: Box::new(Expression::Literal(Literal::Int(5))),
                            }),
                        }),
                        op: BinaryOperator::Addition,
                        rhs: Box::new(Expression::Literal(Literal::Int(2))),
                    };
                    println!("{}", ast);
                    assert_eq!(ast, _expr);
                }

                #[test]
                fn dvision_double_addition() {
                    let mut result =
                        CoriumParser::parse(Rule::Expression, "66 + 1 / 5 + 2").unwrap();
                    let result = result.next().unwrap().into_inner();
                    let ast = crate::parser::precedence::climb_expression(result);
                    let _expr = Expression::Binary {
                        lhs: Box::new(Expression::Binary {
                            lhs: Box::new(Expression::Literal(Literal::Int(66))),
                            op: BinaryOperator::Addition,
                            rhs: Box::new(Expression::Binary {
                                lhs: Box::new(Expression::Literal(Literal::Int(1))),
                                op: BinaryOperator::Division,
                                rhs: Box::new(Expression::Literal(Literal::Int(5))),
                            }),
                        }),
                        op: BinaryOperator::Addition,
                        rhs: Box::new(Expression::Literal(Literal::Int(2))),
                    };
                    println!("{}", ast);
                    assert_eq!(ast, _expr);
                }

                #[test]
                fn modulo_double_addition() {
                    let mut result =
                        CoriumParser::parse(Rule::Expression, "66 + 1 % 5 + 2").unwrap();
                    let result = result.next().unwrap().into_inner();
                    let ast = crate::parser::precedence::climb_expression(result);
                    let _expr = Expression::Binary {
                        lhs: Box::new(Expression::Binary {
                            lhs: Box::new(Expression::Literal(Literal::Int(66))),
                            op: BinaryOperator::Addition,
                            rhs: Box::new(Expression::Binary {
                                lhs: Box::new(Expression::Literal(Literal::Int(1))),
                                op: BinaryOperator::Modulo,
                                rhs: Box::new(Expression::Literal(Literal::Int(5))),
                            }),
                        }),
                        op: BinaryOperator::Addition,
                        rhs: Box::new(Expression::Literal(Literal::Int(2))),
                    };
                    println!("{}", ast);
                    assert_eq!(ast, _expr);
                }

                #[test]
                fn multiply_subtraction_right() {
                    let mut result = CoriumParser::parse(Rule::Expression, "66 - 1 * 5").unwrap();
                    let result = result.next().unwrap().into_inner();
                    let ast = crate::parser::precedence::climb_expression(result);
                    let _expr = Expression::Binary {
                        lhs: Box::new(Expression::Literal(Literal::Int(66))),
                        op: BinaryOperator::Subtraction,
                        rhs: Box::new(Expression::Binary {
                            lhs: Box::new(Expression::Literal(Literal::Int(1))),
                            op: BinaryOperator::Multiplication,
                            rhs: Box::new(Expression::Literal(Literal::Int(5))),
                        }),
                    };
                    println!("{}", ast);
                    assert_eq!(ast, _expr);
                }

                #[test]
                fn multiply_subtraction_left() {
                    let mut result = CoriumParser::parse(Rule::Expression, "66 * 1 - 5").unwrap();
                    let result = result.next().unwrap().into_inner();
                    let ast = crate::parser::precedence::climb_expression(result);
                    let _expr = Expression::Binary {
                        lhs: Box::new(Expression::Binary {
                            lhs: Box::new(Expression::Literal(Literal::Int(66))),
                            op: BinaryOperator::Multiplication,
                            rhs: Box::new(Expression::Literal(Literal::Int(1))),
                        }),
                        op: BinaryOperator::Subtraction,
                        rhs: Box::new(Expression::Literal(Literal::Int(5))),
                    };
                    println!("{}", ast);
                    assert_eq!(ast, _expr);
                }

                #[test]
                fn multiply_double_subtraction() {
                    let mut result =
                        CoriumParser::parse(Rule::Expression, "66 - 1 * 5 - 2").unwrap();
                    let result = result.next().unwrap().into_inner();
                    let ast = crate::parser::precedence::climb_expression(result);
                    let _expr = Expression::Binary {
                        lhs: Box::new(Expression::Binary {
                            lhs: Box::new(Expression::Literal(Literal::Int(66))),
                            op: BinaryOperator::Subtraction,
                            rhs: Box::new(Expression::Binary {
                                lhs: Box::new(Expression::Literal(Literal::Int(1))),
                                op: BinaryOperator::Multiplication,
                                rhs: Box::new(Expression::Literal(Literal::Int(5))),
                            }),
                        }),
                        op: BinaryOperator::Subtraction,
                        rhs: Box::new(Expression::Literal(Literal::Int(2))),
                    };
                    println!("{}", ast);
                    assert_eq!(ast, _expr);
                }

                #[test]
                fn dvision_double_subtraction() {
                    let mut result =
                        CoriumParser::parse(Rule::Expression, "66 - 1 / 5 - 2").unwrap();
                    let result = result.next().unwrap().into_inner();
                    let ast = crate::parser::precedence::climb_expression(result);
                    let _expr = Expression::Binary {
                        lhs: Box::new(Expression::Binary {
                            lhs: Box::new(Expression::Literal(Literal::Int(66))),
                            op: BinaryOperator::Subtraction,
                            rhs: Box::new(Expression::Binary {
                                lhs: Box::new(Expression::Literal(Literal::Int(1))),
                                op: BinaryOperator::Division,
                                rhs: Box::new(Expression::Literal(Literal::Int(5))),
                            }),
                        }),
                        op: BinaryOperator::Subtraction,
                        rhs: Box::new(Expression::Literal(Literal::Int(2))),
                    };
                    println!("{}", ast);
                    assert_eq!(ast, _expr);
                }

                #[test]
                fn modulo_double_subtraction() {
                    let mut result =
                        CoriumParser::parse(Rule::Expression, "66 - 1 % 5 - 2").unwrap();
                    let result = result.next().unwrap().into_inner();
                    let ast = crate::parser::precedence::climb_expression(result);
                    let _expr = Expression::Binary {
                        lhs: Box::new(Expression::Binary {
                            lhs: Box::new(Expression::Literal(Literal::Int(66))),
                            op: BinaryOperator::Subtraction,
                            rhs: Box::new(Expression::Binary {
                                lhs: Box::new(Expression::Literal(Literal::Int(1))),
                                op: BinaryOperator::Modulo,
                                rhs: Box::new(Expression::Literal(Literal::Int(5))),
                            }),
                        }),
                        op: BinaryOperator::Subtraction,
                        rhs: Box::new(Expression::Literal(Literal::Int(2))),
                    };
                    println!("{}", ast);
                    assert_eq!(ast, _expr);
                }

                #[test]
                fn bitwise_shift_left_addition_left() {
                    let mut result = CoriumParser::parse(Rule::Expression, "66 << 1 + 5").unwrap();
                    let result = result.next().unwrap().into_inner();
                    let ast = crate::parser::precedence::climb_expression(result);
                    let _expr = Expression::Binary {
                        lhs: Box::new(Expression::Literal(Literal::Int(66))),
                        op: BinaryOperator::BitwiseShiftLeft,
                        rhs: Box::new(Expression::Binary {
                            lhs: Box::new(Expression::Literal(Literal::Int(1))),
                            op: BinaryOperator::Addition,
                            rhs: Box::new(Expression::Literal(Literal::Int(5))),
                        }),
                    };
                    println!("{}", ast);
                    assert_eq!(ast, _expr);
                }

                #[test]
                fn bitwise_shift_right_multiplication_left() {
                    let mut result = CoriumParser::parse(Rule::Expression, "66 >> 1 * 5").unwrap();
                    let result = result.next().unwrap().into_inner();
                    let ast = crate::parser::precedence::climb_expression(result);
                    let _expr = Expression::Binary {
                        lhs: Box::new(Expression::Literal(Literal::Int(66))),
                        op: BinaryOperator::BitwiseShiftRight,
                        rhs: Box::new(Expression::Binary {
                            lhs: Box::new(Expression::Literal(Literal::Int(1))),
                            op: BinaryOperator::Multiplication,
                            rhs: Box::new(Expression::Literal(Literal::Int(5))),
                        }),
                    };
                    println!("{}", ast);
                    assert_eq!(ast, _expr);
                }

                #[test]
                fn bitwise_rotation_left_division_left() {
                    let mut result = CoriumParser::parse(Rule::Expression, "66 <<< 1 / 5").unwrap();
                    let result = result.next().unwrap().into_inner();
                    let ast = crate::parser::precedence::climb_expression(result);
                    let _expr = Expression::Binary {
                        lhs: Box::new(Expression::Literal(Literal::Int(66))),
                        op: BinaryOperator::BitwiseRotationLeft,
                        rhs: Box::new(Expression::Binary {
                            lhs: Box::new(Expression::Literal(Literal::Int(1))),
                            op: BinaryOperator::Division,
                            rhs: Box::new(Expression::Literal(Literal::Int(5))),
                        }),
                    };
                    println!("{}", ast);
                    assert_eq!(ast, _expr);
                }

                #[test]
                fn bitwise_rotation_right_modulo_left() {
                    let mut result = CoriumParser::parse(Rule::Expression, "66 >>> 1 % 5").unwrap();
                    let result = result.next().unwrap().into_inner();
                    let ast = crate::parser::precedence::climb_expression(result);
                    let _expr = Expression::Binary {
                        lhs: Box::new(Expression::Literal(Literal::Int(66))),
                        op: BinaryOperator::BitwiseRotationRight,
                        rhs: Box::new(Expression::Binary {
                            lhs: Box::new(Expression::Literal(Literal::Int(1))),
                            op: BinaryOperator::Modulo,
                            rhs: Box::new(Expression::Literal(Literal::Int(5))),
                        }),
                    };
                    println!("{}", ast);
                    assert_eq!(ast, _expr);
                }

                #[test]
                fn bitwise_and() {
                    let mut result = CoriumParser::parse(Rule::Expression, "66 ^ 1 & 5").unwrap();
                    let result = result.next().unwrap().into_inner();
                    let ast = crate::parser::precedence::climb_expression(result);
                    let _expr = Expression::Binary {
                        lhs: Box::new(Expression::Literal(Literal::Int(66))),
                        op: BinaryOperator::BitwiseXor,
                        rhs: Box::new(Expression::Binary {
                            lhs: Box::new(Expression::Literal(Literal::Int(1))),
                            op: BinaryOperator::BitwiseAnd,
                            rhs: Box::new(Expression::Literal(Literal::Int(5))),
                        }),
                    };
                    println!("{}", ast);
                    assert_eq!(ast, _expr);
                }

                #[test]
                fn bitwise_xor() {
                    let mut result = CoriumParser::parse(Rule::Expression, "66 | 1 ^ 5").unwrap();
                    let result = result.next().unwrap().into_inner();
                    let ast = crate::parser::precedence::climb_expression(result);
                    let _expr = Expression::Binary {
                        lhs: Box::new(Expression::Literal(Literal::Int(66))),
                        op: BinaryOperator::BitwiseOr,
                        rhs: Box::new(Expression::Binary {
                            lhs: Box::new(Expression::Literal(Literal::Int(1))),
                            op: BinaryOperator::BitwiseXor,
                            rhs: Box::new(Expression::Literal(Literal::Int(5))),
                        }),
                    };
                    println!("{}", ast);
                    assert_eq!(ast, _expr);
                }

                #[test]
                fn bitwise_or() {
                    let mut result = CoriumParser::parse(Rule::Expression, "66 and 1 | 5").unwrap();
                    let result = result.next().unwrap().into_inner();
                    let ast = crate::parser::precedence::climb_expression(result);
                    let _expr = Expression::Binary {
                        lhs: Box::new(Expression::Literal(Literal::Int(66))),
                        op: BinaryOperator::LogicalAnd,
                        rhs: Box::new(Expression::Binary {
                            lhs: Box::new(Expression::Literal(Literal::Int(1))),
                            op: BinaryOperator::BitwiseOr,
                            rhs: Box::new(Expression::Literal(Literal::Int(5))),
                        }),
                    };
                    println!("{}", ast);
                    assert_eq!(ast, _expr);
                }

                #[test]
                fn logical_and() {
                    let mut result =
                        CoriumParser::parse(Rule::Expression, "66 or 1 and 5").unwrap();
                    let result = result.next().unwrap().into_inner();
                    let ast = crate::parser::precedence::climb_expression(result);
                    let _expr = Expression::Binary {
                        lhs: Box::new(Expression::Literal(Literal::Int(66))),
                        op: BinaryOperator::LogicalOr,
                        rhs: Box::new(Expression::Binary {
                            lhs: Box::new(Expression::Literal(Literal::Int(1))),
                            op: BinaryOperator::LogicalAnd,
                            rhs: Box::new(Expression::Literal(Literal::Int(5))),
                        }),
                    };
                    println!("{}", ast);
                    assert_eq!(ast, _expr);
                }

                #[test]
                fn logical_or() {
                    let mut result =
                        CoriumParser::parse(Rule::Expression, "true or 1 + 5").unwrap();
                    let result = result.next().unwrap().into_inner();
                    let ast = crate::parser::precedence::climb_expression(result);
                    let _expr = Expression::Binary {
                        lhs: Box::new(Expression::Literal(Literal::Bool(true))),
                        op: BinaryOperator::LogicalOr,
                        rhs: Box::new(Expression::Binary {
                            lhs: Box::new(Expression::Literal(Literal::Int(1))),
                            op: BinaryOperator::Addition,
                            rhs: Box::new(Expression::Literal(Literal::Int(5))),
                        }),
                    };
                    println!("{}", ast);
                    assert_eq!(ast, _expr);
                }

                #[test]
                fn all_binary_operators() {
                    let mut result =
                        CoriumParser::parse(Rule::Expression, "1 + 2 - 3 * 4 / 5 % 6 & 7 | 8 ^ 9 << 10 >> 11 <<< 12 >>> 13 and true or false").unwrap();
                    let result = result.next().unwrap().into_inner();
                    let ast = crate::parser::precedence::climb_expression(result);
                    println!("{}", ast);
                }
            }
        }
    }

    mod binary_operator {
        use super::*;
        use crate::ast::populator::AtomicAstPopulator;
        use crate::ast::tree::binary_operator::BinaryOperator;
        use crate::ast::tree::Rule;

        #[test]
        fn addition() {
            let result = CoriumParser::parse(Rule::BinaryOperator, "+").unwrap();
            let ast = BinaryOperator::merge(result.as_str());
            assert_eq!(ast, BinaryOperator::Addition);
        }

        #[test]
        fn subtraction() {
            let result = CoriumParser::parse(Rule::BinaryOperator, "-").unwrap();
            let ast = BinaryOperator::merge(result.as_str());
            assert_eq!(ast, BinaryOperator::Subtraction);
        }

        #[test]
        fn multiplication() {
            let result = CoriumParser::parse(Rule::BinaryOperator, "*").unwrap();
            let ast = BinaryOperator::merge(result.as_str());
            assert_eq!(ast, BinaryOperator::Multiplication);
        }

        #[test]
        fn division() {
            let result = CoriumParser::parse(Rule::BinaryOperator, "/").unwrap();
            let ast = BinaryOperator::merge(result.as_str());
            assert_eq!(ast, BinaryOperator::Division);
        }

        #[test]
        fn modulo() {
            let result = CoriumParser::parse(Rule::BinaryOperator, "%").unwrap();
            let ast = BinaryOperator::merge(result.as_str());
            assert_eq!(ast, BinaryOperator::Modulo);
        }

        #[test]
        fn bitwise_and() {
            let result = CoriumParser::parse(Rule::BinaryOperator, "&").unwrap();
            let ast = BinaryOperator::merge(result.as_str());
            assert_eq!(ast, BinaryOperator::BitwiseAnd);
        }

        #[test]
        fn bitwise_or() {
            let result = CoriumParser::parse(Rule::BinaryOperator, "|").unwrap();
            let ast = BinaryOperator::merge(result.as_str());
            assert_eq!(ast, BinaryOperator::BitwiseOr);
        }

        #[test]
        fn bitwise_xor() {
            let result = CoriumParser::parse(Rule::BinaryOperator, "^").unwrap();
            let ast = BinaryOperator::merge(result.as_str());
            assert_eq!(ast, BinaryOperator::BitwiseXor);
        }

        #[test]
        fn bitwise_left_rotation() {
            let result = CoriumParser::parse(Rule::BinaryOperator, "<<<").unwrap();
            let ast = BinaryOperator::merge(result.as_str());
            assert_eq!(ast, BinaryOperator::BitwiseRotationLeft);
        }

        #[test]
        fn bitwise_right_rotation() {
            let result = CoriumParser::parse(Rule::BinaryOperator, ">>>").unwrap();
            let ast = BinaryOperator::merge(result.as_str());
            assert_eq!(ast, BinaryOperator::BitwiseRotationRight);
        }

        #[test]
        fn bitwise_left_shift() {
            let result = CoriumParser::parse(Rule::BinaryOperator, "<<").unwrap();
            let ast = BinaryOperator::merge(result.as_str());
            assert_eq!(ast, BinaryOperator::BitwiseShiftLeft);
        }

        #[test]
        fn bitwise_right_shift() {
            let result = CoriumParser::parse(Rule::BinaryOperator, ">>").unwrap();
            let ast = BinaryOperator::merge(result.as_str());
            assert_eq!(ast, BinaryOperator::BitwiseShiftRight);
        }

        #[test]
        fn logical_and() {
            let result = CoriumParser::parse(Rule::BinaryOperator, "and").unwrap();
            let ast = BinaryOperator::merge(result.as_str());
            assert_eq!(ast, BinaryOperator::LogicalAnd);
        }

        #[test]
        fn logical_or() {
            let result = CoriumParser::parse(Rule::BinaryOperator, "or").unwrap();
            let ast = BinaryOperator::merge(result.as_str());
            assert_eq!(ast, BinaryOperator::LogicalOr);
        }
    }

    mod unary_operator {
        use super::*;
        use crate::ast::populator::AtomicAstPopulator;
        use crate::ast::tree::unary_operator::UnaryOperator;
        use crate::ast::tree::Rule;

        #[test]
        fn plus() {
            let result = CoriumParser::parse(Rule::UnaryOperator, "+").unwrap();
            let ast = UnaryOperator::merge(result.as_str());
            assert_eq!(ast, UnaryOperator::Plus);
        }

        #[test]
        fn minus() {
            let result = CoriumParser::parse(Rule::UnaryOperator, "-").unwrap();
            let ast = UnaryOperator::merge(result.as_str());
            assert_eq!(ast, UnaryOperator::Minus);
        }

        #[test]
        fn bitwise_complement() {
            let result = CoriumParser::parse(Rule::UnaryOperator, "~").unwrap();
            let ast = UnaryOperator::merge(result.as_str());
            assert_eq!(ast, UnaryOperator::BitwiseComplement);
        }

        #[test]
        fn logical_not() {
            let result = CoriumParser::parse(Rule::UnaryOperator, "not").unwrap();
            let ast = UnaryOperator::merge(result.as_str());
            assert_eq!(ast, UnaryOperator::LogicalNot);
        }
    }

    mod parameter {
        use super::*;
        use crate::ast::populator::NestedAstPopulator;
        use crate::ast::tree::expression::Expression;
        use crate::ast::tree::literal::Literal;
        use crate::ast::tree::Rule;

        #[test]
        fn int() {
            let mut result = CoriumParser::parse(Rule::Parameter, "myParam int").unwrap();
            let ast = Parameter::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.name.full, "myParam");
            assert_eq!(ast.type_hint.full, "int");
            assert!(ast.value.is_none());
        }

        #[test]
        fn float() {
            let mut result = CoriumParser::parse(Rule::Parameter, "myParam float").unwrap();
            let ast = Parameter::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.name.full, "myParam");
            assert_eq!(ast.type_hint.full, "float");
            assert!(ast.value.is_none());
        }

        #[test]
        fn class() {
            let mut result = CoriumParser::parse(Rule::Parameter, "myParam MyClass").unwrap();
            let ast = Parameter::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.name.full, "myParam");
            assert_eq!(ast.type_hint.full, "MyClass");
            assert!(ast.value.is_none());
        }

        #[test]
        fn package_class() {
            let mut result =
                CoriumParser::parse(Rule::Parameter, "myParam MyPackage.MyClass").unwrap();
            let ast = Parameter::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.name.full, "myParam");
            assert_eq!(ast.type_hint.full, "MyPackage.MyClass");
            assert!(ast.value.is_none());
        }

        #[test]
        fn int_with_default_value() {
            let mut result = CoriumParser::parse(Rule::Parameter, "myParam int = 10").unwrap();
            let ast = Parameter::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.name.full, "myParam");
            assert_eq!(ast.type_hint.full, "int");
            assert!(ast.value.is_some());
            assert!(matches!(
                ast.value.unwrap(),
                Expression::Literal(Literal::Int(10))
            ));
        }

        #[test]
        fn float_with_default_value() {
            let mut result = CoriumParser::parse(Rule::Parameter, "myParam float = 0.999").unwrap();
            let ast = Parameter::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.name.full, "myParam");
            assert_eq!(ast.type_hint.full, "float");
            assert!(ast.value.is_some());
            let _f = Literal::Float(0.999);
            assert!(matches!(ast.value.unwrap(), Expression::Literal(_f)));
        }

        #[test]
        fn bool_with_default_value() {
            let mut result = CoriumParser::parse(Rule::Parameter, "myParam bool = true").unwrap();
            let ast = Parameter::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.name.full, "myParam");
            assert_eq!(ast.type_hint.full, "bool");
            assert!(ast.value.is_some());
            assert!(matches!(
                ast.value.unwrap(),
                Expression::Literal(Literal::Bool(true))
            ));
        }

        #[test]
        fn char_with_default_value() {
            let mut result = CoriumParser::parse(Rule::Parameter, "myParam char = 'x'").unwrap();
            let ast = Parameter::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.name.full, "myParam");
            assert_eq!(ast.type_hint.full, "char");
            assert!(ast.value.is_some());
            assert!(matches!(
                ast.value.unwrap(),
                Expression::Literal(Literal::Char('x'))
            ));
        }

        #[test]
        fn string_with_default_value() {
            let mut result =
                CoriumParser::parse(Rule::Parameter, "myParam string = \"I luv u :3\"").unwrap();
            let ast = Parameter::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.name.full, "myParam");
            assert_eq!(ast.type_hint.full, "string");
            assert!(ast.value.is_some());
            assert!(matches!(
                ast.value.unwrap(),
                Expression::Literal(Literal::String("I luv u :3"))
            ));
        }
    }

    mod parameter_list {
        use super::*;
        use crate::ast::populator::NestedAstPopulator;
        use crate::ast::tree::expression::Expression;
        use crate::ast::tree::literal::Literal;
        use crate::ast::tree::parameter_list::ParameterList;
        use crate::ast::tree::Rule;

        #[test]
        fn one() {
            let mut result = CoriumParser::parse(Rule::ParameterList, "x int").unwrap();
            let ast = ParameterList::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.0.len(), 1);

            assert_eq!(ast.0[0].name.full, "x");
            assert_eq!(ast.0[0].type_hint.full, "int");
            assert!(ast.0[0].value.is_none());
        }

        #[test]
        fn two() {
            let mut result = CoriumParser::parse(Rule::ParameterList, "x int, y float").unwrap();
            let ast = ParameterList::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.0.len(), 2);

            assert_eq!(ast.0[0].name.full, "x");
            assert_eq!(ast.0[0].type_hint.full, "int");
            assert!(ast.0[0].value.is_none());

            assert_eq!(ast.0[1].name.full, "y");
            assert_eq!(ast.0[1].type_hint.full, "float");
            assert!(ast.0[1].value.is_none());
        }

        #[test]
        fn three() {
            let mut result =
                CoriumParser::parse(Rule::ParameterList, "x int, y float, z string").unwrap();
            let ast = ParameterList::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.0.len(), 3);

            assert_eq!(ast.0[0].name.full, "x");
            assert_eq!(ast.0[0].type_hint.full, "int");
            assert!(ast.0[0].value.is_none());

            assert_eq!(ast.0[1].name.full, "y");
            assert_eq!(ast.0[1].type_hint.full, "float");
            assert!(ast.0[1].value.is_none());

            assert_eq!(ast.0[2].name.full, "z");
            assert_eq!(ast.0[2].type_hint.full, "string");
            assert!(ast.0[2].value.is_none());
        }

        #[test]
        fn one_with_default_value() {
            let mut result = CoriumParser::parse(Rule::ParameterList, "x int = 10").unwrap();
            let ast = ParameterList::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.0.len(), 1);

            assert_eq!(ast.0[0].name.full, "x");
            assert_eq!(ast.0[0].type_hint.full, "int");
            assert!(ast.0[0].value.is_some());
            assert!(matches!(
                ast.0[0].value.as_ref().unwrap(),
                Expression::Literal(Literal::Int(10))
            ));
        }

        #[test]
        fn two_with_default_value() {
            let mut result =
                CoriumParser::parse(Rule::ParameterList, "x int = 10, y float = 2.4").unwrap();
            let ast = ParameterList::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.0.len(), 2);

            assert_eq!(ast.0[0].name.full, "x");
            assert_eq!(ast.0[0].type_hint.full, "int");
            assert!(ast.0[0].value.is_some());
            assert!(matches!(
                ast.0[0].value.as_ref().unwrap(),
                Expression::Literal(Literal::Int(10))
            ));

            assert_eq!(ast.0[1].name.full, "y");
            assert_eq!(ast.0[1].type_hint.full, "float");
            assert!(ast.0[1].value.is_some());
            let _f = Literal::Float(2.4);
            assert!(matches!(
                ast.0[1].value.as_ref().unwrap(),
                Expression::Literal(_f)
            ));
        }

        #[test]
        fn two_one_with_default_value() {
            let mut result =
                CoriumParser::parse(Rule::ParameterList, "a char, x int = 10").unwrap();
            let ast = ParameterList::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.0.len(), 2);

            assert_eq!(ast.0[0].name.full, "a");
            assert_eq!(ast.0[0].type_hint.full, "char");
            assert!(ast.0[0].value.is_none());

            assert_eq!(ast.0[1].name.full, "x");
            assert_eq!(ast.0[1].type_hint.full, "int");
            assert!(ast.0[1].value.is_some());
            assert!(matches!(
                ast.0[1].value.as_ref().unwrap(),
                Expression::Literal(Literal::Int(10))
            ));
        }
    }

    mod return_statement {
        use super::*;
        use crate::ast::populator::NestedAstPopulator;
        use crate::ast::tree::expression::Expression;
        use crate::ast::tree::literal::Literal;
        use crate::ast::tree::return_statement::ReturnStatement;
        use crate::ast::tree::Rule;

        #[test]
        fn return_none() {
            let mut result = CoriumParser::parse(Rule::ReturnStatement, "return\n").unwrap();
            let ast = ReturnStatement::populate(result.next().unwrap().into_inner());
            assert!(ast.0.is_none());
        }

        #[test]
        fn return_int() {
            let mut result = CoriumParser::parse(Rule::ReturnStatement, "return 10\n").unwrap();
            let ast = ReturnStatement::populate(result.next().unwrap().into_inner());
            assert!(ast.0.is_some());
            assert!(matches!(
                ast.0.unwrap(),
                Expression::Literal(Literal::Int(10))
            ));
        }

        #[test]
        fn return_ident() {
            let mut result = CoriumParser::parse(Rule::ReturnStatement, "return myVar\n").unwrap();
            let ast = ReturnStatement::populate(result.next().unwrap().into_inner());
            assert!(ast.0.is_some());
            let _ident = Expression::Identifier(Identifier::new("myVar"));
            assert!(matches!(ast.0.unwrap(), _ident));
        }

        #[test]
        fn return_float() {
            let mut result = CoriumParser::parse(Rule::ReturnStatement, "return 0.51\n").unwrap();
            let ast = ReturnStatement::populate(result.next().unwrap().into_inner());
            assert!(ast.0.is_some());
            let _f = Literal::Float(0.51);
            assert!(matches!(ast.0.unwrap(), Expression::Literal(_f)));
        }
    }

    mod mutable_variable {
        use super::*;
        use crate::ast::populator::NestedAstPopulator;
        use crate::ast::tree::expression::Expression;
        use crate::ast::tree::literal::Literal;
        use crate::ast::tree::mutable_variable::MutableVariable;
        use crate::ast::tree::Rule;

        #[test]
        fn int() {
            let mut result = CoriumParser::parse(Rule::MutableVariable, "let x = 10\n").unwrap();
            let ast = MutableVariable::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.name.full, "x");
            assert!(matches!(ast.value, Expression::Literal(Literal::Int(10))));
            assert!(ast.type_hint.is_none());
        }

        #[test]
        fn float() {
            let mut result = CoriumParser::parse(Rule::MutableVariable, "let x = 10.0\n").unwrap();
            let ast = MutableVariable::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.name.full, "x");
            let _f = Literal::Float(10.0);
            assert!(matches!(ast.value, Expression::Literal(_f)));
            assert!(ast.type_hint.is_none());
        }

        #[test]
        fn char() {
            let mut result = CoriumParser::parse(Rule::MutableVariable, "let x = 'x'\n").unwrap();
            let ast = MutableVariable::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.name.full, "x");
            assert!(matches!(ast.value, Expression::Literal(Literal::Char('x'))));
            assert!(ast.type_hint.is_none());
        }

        #[test]
        fn bool() {
            let mut result = CoriumParser::parse(Rule::MutableVariable, "let x = true\n").unwrap();
            let ast = MutableVariable::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.name.full, "x");
            assert!(matches!(
                ast.value,
                Expression::Literal(Literal::Bool(true))
            ));
            assert!(ast.type_hint.is_none());
        }

        #[test]
        fn string() {
            let mut result =
                CoriumParser::parse(Rule::MutableVariable, "let x = \"Name\"\n").unwrap();
            let ast = MutableVariable::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.name.full, "x");
            assert!(matches!(
                ast.value,
                Expression::Literal(Literal::String("Name"))
            ));
            assert!(ast.type_hint.is_none());
        }

        #[test]
        fn type_int() {
            let mut result =
                CoriumParser::parse(Rule::MutableVariable, "let x int = 10\n").unwrap();
            let ast = MutableVariable::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.name.full, "x");
            assert!(matches!(ast.value, Expression::Literal(Literal::Int(10))));
            assert!(ast.type_hint.is_some());
            assert_eq!(ast.type_hint.unwrap().full, "int");
        }

        #[test]
        fn type_float() {
            let mut result =
                CoriumParser::parse(Rule::MutableVariable, "let x float = 10.0\n").unwrap();
            let ast = MutableVariable::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.name.full, "x");
            let _f = Literal::Float(10.0);
            assert!(matches!(ast.value, Expression::Literal(_f)));
            assert!(ast.type_hint.is_some());
            assert_eq!(ast.type_hint.unwrap().full, "float");
        }

        #[test]
        fn type_char() {
            let mut result =
                CoriumParser::parse(Rule::MutableVariable, "let x char = 'x'\n").unwrap();
            let ast = MutableVariable::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.name.full, "x");
            assert!(matches!(ast.value, Expression::Literal(Literal::Char('x'))));
            assert!(ast.type_hint.is_some());
            assert_eq!(ast.type_hint.unwrap().full, "char");
        }

        #[test]
        fn type_bool() {
            let mut result =
                CoriumParser::parse(Rule::MutableVariable, "let x bool = true\n").unwrap();
            let ast = MutableVariable::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.name.full, "x");
            assert!(matches!(
                ast.value,
                Expression::Literal(Literal::Bool(true))
            ));
            assert!(ast.type_hint.is_some());
            assert_eq!(ast.type_hint.unwrap().full, "bool");
        }

        #[test]
        fn type_string() {
            let mut result =
                CoriumParser::parse(Rule::MutableVariable, "let x string = \"Name\"\n").unwrap();
            let ast = MutableVariable::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.name.full, "x");
            assert!(matches!(
                ast.value,
                Expression::Literal(Literal::String("Name"))
            ));
            assert!(ast.type_hint.is_some());
            assert_eq!(ast.type_hint.unwrap().full, "string");
        }
    }

    mod immutable_variable {
        use super::*;
        use crate::ast::populator::NestedAstPopulator;
        use crate::ast::tree::expression::Expression;
        use crate::ast::tree::immutable_variable::ImmutableVariable;
        use crate::ast::tree::literal::Literal;
        use crate::ast::tree::Rule;

        #[test]
        fn int() {
            let mut result =
                CoriumParser::parse(Rule::ImmutableVariable, "const x = 10\n").unwrap();
            let ast = ImmutableVariable::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.name.full, "x");
            assert!(matches!(ast.value, Expression::Literal(Literal::Int(10))));
            assert!(ast.type_hint.is_none());
        }

        #[test]
        fn float() {
            let mut result =
                CoriumParser::parse(Rule::ImmutableVariable, "const x = 10.0\n").unwrap();
            let ast = ImmutableVariable::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.name.full, "x");
            let _f = Literal::Float(10.0);
            assert!(matches!(ast.value, Expression::Literal(_f)));
            assert!(ast.type_hint.is_none());
        }

        #[test]
        fn char() {
            let mut result =
                CoriumParser::parse(Rule::ImmutableVariable, "const x = 'x'\n").unwrap();
            let ast = ImmutableVariable::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.name.full, "x");
            assert!(matches!(ast.value, Expression::Literal(Literal::Char('x'))));
            assert!(ast.type_hint.is_none());
        }

        #[test]
        fn bool() {
            let mut result =
                CoriumParser::parse(Rule::ImmutableVariable, "const x = true\n").unwrap();
            let ast = ImmutableVariable::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.name.full, "x");
            assert!(matches!(
                ast.value,
                Expression::Literal(Literal::Bool(true))
            ));
            assert!(ast.type_hint.is_none());
        }

        #[test]
        fn string() {
            let mut result =
                CoriumParser::parse(Rule::ImmutableVariable, "const x = \"Name\"\n").unwrap();
            let ast = ImmutableVariable::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.name.full, "x");
            assert!(matches!(
                ast.value,
                Expression::Literal(Literal::String("Name"))
            ));
            assert!(ast.type_hint.is_none());
        }

        #[test]
        fn type_int() {
            let mut result =
                CoriumParser::parse(Rule::ImmutableVariable, "const x int = 10\n").unwrap();
            let ast = ImmutableVariable::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.name.full, "x");
            assert!(matches!(ast.value, Expression::Literal(Literal::Int(10))));
            assert!(ast.type_hint.is_some());
            assert_eq!(ast.type_hint.unwrap().full, "int");
        }

        #[test]
        fn type_float() {
            let mut result =
                CoriumParser::parse(Rule::ImmutableVariable, "const x float = 10.0\n").unwrap();
            let ast = ImmutableVariable::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.name.full, "x");
            let _f = Literal::Float(10.0);
            assert!(matches!(ast.value, Expression::Literal(_f)));
            assert!(ast.type_hint.is_some());
            assert_eq!(ast.type_hint.unwrap().full, "float");
        }

        #[test]
        fn type_char() {
            let mut result =
                CoriumParser::parse(Rule::ImmutableVariable, "const x char = 'x'\n").unwrap();
            let ast = ImmutableVariable::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.name.full, "x");
            assert!(matches!(ast.value, Expression::Literal(Literal::Char('x'))));
            assert!(ast.type_hint.is_some());
            assert_eq!(ast.type_hint.unwrap().full, "char");
        }

        #[test]
        fn type_bool() {
            let mut result =
                CoriumParser::parse(Rule::ImmutableVariable, "const x bool = true\n").unwrap();
            let ast = ImmutableVariable::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.name.full, "x");
            assert!(matches!(
                ast.value,
                Expression::Literal(Literal::Bool(true))
            ));
            assert!(ast.type_hint.is_some());
            assert_eq!(ast.type_hint.unwrap().full, "bool");
        }

        #[test]
        fn type_string() {
            let mut result =
                CoriumParser::parse(Rule::ImmutableVariable, "const x string = \"Name\"\n")
                    .unwrap();
            let ast = ImmutableVariable::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.name.full, "x");
            assert!(matches!(
                ast.value,
                Expression::Literal(Literal::String("Name"))
            ));
            assert!(ast.type_hint.is_some());
            assert_eq!(ast.type_hint.unwrap().full, "string");
        }
    }

    mod module {
        use super::*;
        use crate::ast::populator::NestedAstPopulator;
        use crate::ast::tree::module::Module;
        use crate::ast::tree::Rule;

        #[test]
        fn simple() {
            let mut result = CoriumParser::parse(Rule::Module, "module MyPackage\n").unwrap();
            let ast = Module::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.qualified_name(), "MyPackage");
            assert_eq!(ast.split_name().len(), 1);
            assert_eq!(ast.split_name()[0], "MyPackage");
        }

        #[test]
        fn nested() {
            let mut result = CoriumParser::parse(Rule::Module, "module MyPackage.Class\n").unwrap();
            let ast = Module::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.qualified_name(), "MyPackage.Class");
            assert_eq!(ast.split_name().len(), 2);
            assert_eq!(ast.split_name()[0], "MyPackage");
            assert_eq!(ast.split_name()[1], "Class");
        }

        #[test]
        fn nested2() {
            let mut result =
                CoriumParser::parse(Rule::Module, "module MyPackage.Class.StaticMember\n").unwrap();
            let ast = Module::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.qualified_name(), "MyPackage.Class.StaticMember");
            assert_eq!(ast.split_name().len(), 3);
            assert_eq!(ast.split_name()[0], "MyPackage");
            assert_eq!(ast.split_name()[1], "Class");
            assert_eq!(ast.split_name()[2], "StaticMember");
        }

        #[test]
        fn nested3() {
            let mut result =
                CoriumParser::parse(Rule::Module, "module MyPackage.Class.StaticMember.Field\n")
                    .unwrap();
            let ast = Module::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.qualified_name(), "MyPackage.Class.StaticMember.Field");
            assert_eq!(ast.split_name().len(), 4);
            assert_eq!(ast.split_name()[0], "MyPackage");
            assert_eq!(ast.split_name()[1], "Class");
            assert_eq!(ast.split_name()[2], "StaticMember");
            assert_eq!(ast.split_name()[3], "Field");
        }
    }

    mod function_statement {
        use super::*;
        use crate::ast::populator::NestedAstPopulator;
        use crate::ast::tree::expression::Expression;
        use crate::ast::tree::immutable_variable::ImmutableVariable;
        use crate::ast::tree::literal::Literal;
        use crate::ast::tree::local_statement::LocalStatement;
        use crate::ast::tree::mutable_variable::MutableVariable;
        use crate::ast::tree::return_statement::ReturnStatement;
        use crate::ast::tree::Rule;

        #[test]
        fn mutable_variable() {
            let mut result = CoriumParser::parse(Rule::LocalStatement, "let x = 10\n").unwrap();
            let ast = LocalStatement::populate(result.next().unwrap().into_inner());
            let _ident = Identifier::new("x");
            assert!(matches!(
                ast,
                LocalStatement::MutableVariable(MutableVariable {
                    name: _ident,
                    type_hint: None,
                    value: Expression::Literal(Literal::Int(10))
                })
            ));
        }

        #[test]
        fn immutable_variable() {
            let mut result = CoriumParser::parse(Rule::LocalStatement, "const x = 10\n").unwrap();
            let ast = LocalStatement::populate(result.next().unwrap().into_inner());
            let _ident = Identifier::new("x");
            assert!(matches!(
                ast,
                LocalStatement::ImmutableVariable(ImmutableVariable {
                    name: _ident,
                    type_hint: None,
                    value: Expression::Literal(Literal::Int(10))
                })
            ));
        }

        #[test]
        fn return_statement() {
            let mut result = CoriumParser::parse(Rule::LocalStatement, "return\n").unwrap();
            let ast = LocalStatement::populate(result.next().unwrap().into_inner());
            assert!(matches!(
                ast,
                LocalStatement::ReturnStatement(ReturnStatement(None))
            ));
        }

        #[test]
        fn return_statement2() {
            let mut result = CoriumParser::parse(Rule::LocalStatement, "return true\n").unwrap();
            let ast = LocalStatement::populate(result.next().unwrap().into_inner());
            assert!(matches!(
                ast,
                LocalStatement::ReturnStatement(ReturnStatement(Some(Expression::Literal(
                    Literal::Bool(true)
                ))))
            ));
        }
    }

    mod block {
        use super::*;
        use crate::ast::populator::NestedAstPopulator;
        use crate::ast::tree::block::Block;
        use crate::ast::tree::expression::Expression;
        use crate::ast::tree::immutable_variable::ImmutableVariable;
        use crate::ast::tree::literal::Literal;
        use crate::ast::tree::local_statement::LocalStatement;
        use crate::ast::tree::mutable_variable::MutableVariable;
        use crate::ast::tree::return_statement::ReturnStatement;
        use crate::ast::tree::Rule;

        #[test]
        fn variables() {
            let source = concat!(
                "let x = 10\n",
                "let y bool = true\n",
                "let name = \"Hey\"\n",
                "const z char = 'y'\n",
                "let zw float = 2.33225\n"
            );
            let mut result = CoriumParser::parse(Rule::Block, source).unwrap();
            let ast = Block::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.0.len(), 5);
            let _ident = Identifier::new("x");
            assert!(matches!(
                &ast.0[0],
                LocalStatement::MutableVariable(MutableVariable {
                    name: _ident,
                    value: Expression::Literal(Literal::Int(10)),
                    type_hint: None
                })
            ));

            let _ident = Identifier::new("y");
            let _name = Identifier::new("bool");
            assert!(matches!(
                &ast.0[1],
                LocalStatement::MutableVariable(MutableVariable {
                    name: _ident,
                    value: Expression::Literal(Literal::Bool(true)),
                    type_hint: Some(_name)
                })
            ));

            let _ident = Identifier::new("name");
            assert!(matches!(
                &ast.0[2],
                LocalStatement::MutableVariable(MutableVariable {
                    name: _ident,
                    value: Expression::Literal(Literal::String("Hey")),
                    type_hint: None
                })
            ));

            let _ident = Identifier::new("z");
            let _name = Identifier::new("char");
            assert!(matches!(
                &ast.0[3],
                LocalStatement::ImmutableVariable(ImmutableVariable {
                    name: _ident,
                    value: Expression::Literal(Literal::Char('y')),
                    type_hint: Some(_name)
                })
            ));

            let _ident = Identifier::new("zw");
            let _name = Identifier::new("float");
            let _f = Literal::Float(2.33225);
            assert!(matches!(
                &ast.0[4],
                LocalStatement::MutableVariable(MutableVariable {
                    name: _ident,
                    value: Expression::Literal(_f),
                    type_hint: Some(_name)
                })
            ));
        }

        #[test]
        fn returns() {
            let source = concat!(
                "return\n",
                "return true\n",
                "return \"Hey\"\n",
                "return 2.33225\n"
            );
            let mut result = CoriumParser::parse(Rule::Block, source).unwrap();
            let ast = Block::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.0.len(), 4);
            assert!(matches!(
                &ast.0[0],
                LocalStatement::ReturnStatement(ReturnStatement(None))
            ));
            assert!(matches!(
                &ast.0[1],
                LocalStatement::ReturnStatement(ReturnStatement(Some(Expression::Literal(
                    Literal::Bool(true)
                ))))
            ));
            assert!(matches!(
                &ast.0[2],
                LocalStatement::ReturnStatement(ReturnStatement(Some(Expression::Literal(
                    Literal::String("Hey")
                ))))
            ));
            let _f = Literal::Float(2.33225);
            assert!(matches!(
                &ast.0[3],
                LocalStatement::ReturnStatement(ReturnStatement(Some(Expression::Literal(_f))))
            ));
        }

        #[test]
        fn mixed() {
            let source = concat!(
                "let x = 10\n",
                "return true\n",
                "return \"Hey\"\n",
                "let z bool = true\n",
                "let z float = 2.33225\n"
            );
            let mut result = CoriumParser::parse(Rule::Block, source).unwrap();
            let ast = Block::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.0.len(), 5);
            let _ident = Identifier::new("x");
            assert!(matches!(
                &ast.0[0],
                LocalStatement::MutableVariable(MutableVariable {
                    name: _ident,
                    value: Expression::Literal(Literal::Int(10)),
                    type_hint: None
                })
            ));
            assert!(matches!(
                &ast.0[1],
                LocalStatement::ReturnStatement(ReturnStatement(Some(Expression::Literal(
                    Literal::Bool(true)
                ))))
            ));
            assert!(matches!(
                &ast.0[2],
                LocalStatement::ReturnStatement(ReturnStatement(Some(Expression::Literal(
                    Literal::String("Hey")
                ))))
            ));
            let _name = Identifier::new("bool");
            let _ident = Identifier::new("z");
            assert!(matches!(
                &ast.0[3],
                LocalStatement::MutableVariable(MutableVariable {
                    name: _ident,
                    value: Expression::Literal(Literal::Bool(true)),
                    type_hint: Some(_name)
                })
            ));
            let _name = Identifier::new("float");
            let _f = Literal::Float(2.33225);
            let _ident = Identifier::new("z");
            assert!(matches!(
                &ast.0[4],
                LocalStatement::MutableVariable(MutableVariable {
                    name: _ident,
                    value: Expression::Literal(_f),
                    type_hint: Some(_name)
                })
            ));
        }
    }

    mod function_signature {
        use super::*;
        use crate::ast::populator::NestedAstPopulator;
        use crate::ast::tree::expression::Expression;
        use crate::ast::tree::literal::Literal;
        use crate::ast::tree::Rule;

        #[test]
        fn simple() {
            let mut result = CoriumParser::parse(Rule::FunctionSignature, "function f ()").unwrap();
            let ast = FunctionSignature::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.name.full, "f");
            assert!(ast.parameters.is_none());
            assert!(ast.return_type.is_none());
        }

        #[test]
        fn return_type() {
            let mut result =
                CoriumParser::parse(Rule::FunctionSignature, "function f () int").unwrap();
            let ast = FunctionSignature::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.name.full, "f");
            assert!(ast.parameters.is_none());
            assert!(ast.return_type.is_some());
            let _name = Identifier::new("int");
            assert!(matches!(ast.return_type.unwrap(), _name));
        }

        #[test]
        fn param() {
            let mut result =
                CoriumParser::parse(Rule::FunctionSignature, "function f (x float)").unwrap();
            let ast = FunctionSignature::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.name.full, "f");
            assert!(ast.parameters.is_some());
            assert_eq!(ast.parameters.as_ref().unwrap().0.len(), 1);
            assert!(ast.return_type.is_none());
            let _name = Identifier::new("float");
            let _ident = Identifier::new("x");
            assert!(matches!(
                &ast.parameters.as_ref().unwrap().0[0],
                Parameter {
                    name: _ident,
                    type_hint: _name,
                    value: None
                }
            ));
        }

        #[test]
        fn params() {
            let mut result = CoriumParser::parse(
                Rule::FunctionSignature,
                "function proc (x float, name string, ok bool = true)",
            )
            .unwrap();
            let ast = FunctionSignature::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.name.full, "proc");
            assert!(ast.parameters.is_some());
            assert_eq!(ast.parameters.as_ref().unwrap().0.len(), 3);
            assert!(ast.return_type.is_none());
            let _name = Identifier::new("float");
            let _ident = Identifier::new("x");
            assert!(matches!(
                &ast.parameters.as_ref().unwrap().0[0],
                Parameter {
                    name: _ident,
                    type_hint: _name,
                    value: None
                }
            ));
            let _name = Identifier::new("string");
            let _ident = Identifier::new("name");
            assert!(matches!(
                &ast.parameters.as_ref().unwrap().0[1],
                Parameter {
                    name: _ident,
                    type_hint: _name,
                    value: None
                }
            ));
            let _name = Identifier::new("bool");
            let _ident = Identifier::new("ok");
            assert!(matches!(
                &ast.parameters.as_ref().unwrap().0[2],
                Parameter {
                    name: _ident,
                    type_hint: _name,
                    value: Some(Expression::Literal(Literal::Bool(true)))
                }
            ));
        }

        #[test]
        fn param_ret() {
            let mut result =
                CoriumParser::parse(Rule::FunctionSignature, "function f (x float) float").unwrap();
            let ast = FunctionSignature::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.name.full, "f");
            assert!(ast.parameters.is_some());
            assert_eq!(ast.parameters.as_ref().unwrap().0.len(), 1);
            assert!(ast.return_type.is_some());
            let _name = Identifier::new("float");
            assert!(matches!(ast.return_type.unwrap(), _name));
            let _name = Identifier::new("float");
            let _ident = Identifier::new("x");
            assert!(matches!(
                &ast.parameters.as_ref().unwrap().0[0],
                Parameter {
                    name: _ident,
                    type_hint: _name,
                    value: None
                }
            ));
        }
    }

    mod native_function {
        use super::*;
        use crate::ast::populator::NestedAstPopulator;
        use crate::ast::tree::expression::Expression;
        use crate::ast::tree::literal::Literal;
        use crate::ast::tree::native_function::NativeFunction;
        use crate::ast::tree::Rule;

        #[test]
        fn simple() {
            let mut result =
                CoriumParser::parse(Rule::NativeFunction, "native function f ()\n").unwrap();
            let ast = NativeFunction::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.signature.name.full, "f");
            assert!(ast.signature.parameters.is_none());
            assert!(ast.signature.return_type.is_none());
        }

        #[test]
        fn return_type() {
            let mut result =
                CoriumParser::parse(Rule::NativeFunction, "native function f () int\n").unwrap();
            let ast = NativeFunction::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.signature.name.full, "f");
            assert!(ast.signature.parameters.is_none());
            assert!(ast.signature.return_type.is_some());
            let _name = Identifier::new("int");
            assert!(matches!(ast.signature.return_type.unwrap(), _name));
        }

        #[test]
        fn param() {
            let mut result =
                CoriumParser::parse(Rule::NativeFunction, "native function f (x float)\n").unwrap();
            let ast = NativeFunction::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.signature.name.full, "f");
            assert!(ast.signature.parameters.is_some());
            assert_eq!(ast.signature.parameters.as_ref().unwrap().0.len(), 1);
            assert!(ast.signature.return_type.is_none());
            let _name = Identifier::new("float");
            let _ident = Identifier::new("x");
            assert!(matches!(
                &ast.signature.parameters.as_ref().unwrap().0[0],
                Parameter {
                    name: _ident,
                    type_hint: _name,
                    value: None
                }
            ));
        }

        #[test]
        fn params() {
            let mut result = CoriumParser::parse(
                Rule::NativeFunction,
                "native function proc (x float, name string, ok bool = true)\n",
            )
            .unwrap();
            let ast = NativeFunction::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.signature.name.full, "proc");
            assert!(ast.signature.parameters.is_some());
            assert_eq!(ast.signature.parameters.as_ref().unwrap().0.len(), 3);
            assert!(ast.signature.return_type.is_none());
            let _name = Identifier::new("float");
            let _ident = Identifier::new("x");
            assert!(matches!(
                &ast.signature.parameters.as_ref().unwrap().0[0],
                Parameter {
                    name: _ident,
                    type_hint: _name,
                    value: None
                }
            ));
            let _name = Identifier::new("string");
            let _ident = Identifier::new("name");
            assert!(matches!(
                &ast.signature.parameters.as_ref().unwrap().0[1],
                Parameter {
                    name: _ident,
                    type_hint: _name,
                    value: None
                }
            ));
            let _name = Identifier::new("bool");
            let _ident = Identifier::new("ok");
            assert!(matches!(
                &ast.signature.parameters.as_ref().unwrap().0[2],
                Parameter {
                    name: _ident,
                    type_hint: _name,
                    value: Some(Expression::Literal(Literal::Bool(true)))
                }
            ));
        }

        #[test]
        fn param_ret() {
            let mut result =
                CoriumParser::parse(Rule::NativeFunction, "native function f (x float) float\n")
                    .unwrap();
            let ast = NativeFunction::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.signature.name.full, "f");
            assert!(ast.signature.parameters.is_some());
            assert_eq!(ast.signature.parameters.as_ref().unwrap().0.len(), 1);
            assert!(ast.signature.return_type.is_some());
            let _name = Identifier::new("float");
            assert!(matches!(ast.signature.return_type.unwrap(), _name));
            let _name = Identifier::new("float");
            let _ident = Identifier::new("x");
            assert!(matches!(
                &ast.signature.parameters.as_ref().unwrap().0[0],
                Parameter {
                    name: _ident,
                    type_hint: _name,
                    value: None
                }
            ));
        }
    }

    mod function {
        use super::*;
        use crate::ast::populator::NestedAstPopulator;
        use crate::ast::tree::expression::Expression;
        use crate::ast::tree::function::Function;
        use crate::ast::tree::literal::Literal;
        use crate::ast::tree::local_statement::LocalStatement;
        use crate::ast::tree::mutable_variable::MutableVariable;
        use crate::ast::tree::return_statement::ReturnStatement;
        use crate::ast::tree::Rule;

        #[test]
        fn simple() {
            let mut result = CoriumParser::parse(Rule::Function, "function f () {\n}\n").unwrap();
            let ast = Function::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.signature.name, Identifier::new("f"));
            assert!(ast.signature.return_type.is_none());
            assert!(ast.signature.parameters.is_none());
            assert!(ast.block.0.is_empty());
        }

        #[test]
        fn return_type() {
            let mut result =
                CoriumParser::parse(Rule::Function, "function f () int {\n}\n").unwrap();
            let ast = Function::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.signature.name, Identifier::new("f"));
            assert!(ast.signature.return_type.is_some());
            let _name = Identifier::new("int");
            assert!(matches!(ast.signature.return_type.as_ref().unwrap(), _name));
            assert!(ast.signature.parameters.is_none());
            assert!(ast.block.0.is_empty());
        }

        #[test]
        fn param() {
            let mut result =
                CoriumParser::parse(Rule::Function, "function f (x float) {\n}\n").unwrap();
            let ast = Function::populate(result.next().unwrap().into_inner());
            assert!(ast.block.0.is_empty());
            assert_eq!(ast.signature.name.full, "f");
            assert!(ast.signature.parameters.is_some());
            assert_eq!(ast.signature.parameters.as_ref().unwrap().0.len(), 1);
            assert!(ast.signature.return_type.is_none());
            let _name = Identifier::new("float");
            let _ident = Identifier::new("x");
            assert!(matches!(
                &ast.signature.parameters.as_ref().unwrap().0[0],
                Parameter {
                    name: _ident,
                    type_hint: _name,
                    value: None
                }
            ));
        }

        #[test]
        fn params() {
            let mut result = CoriumParser::parse(
                Rule::Function,
                "function proc (x float, name string, ok bool = true) {\n}\n",
            )
            .unwrap();
            let ast = Function::populate(result.next().unwrap().into_inner());
            assert!(ast.block.0.is_empty());
            assert_eq!(ast.signature.name.full, "proc");
            assert!(ast.signature.parameters.is_some());
            assert_eq!(ast.signature.parameters.as_ref().unwrap().0.len(), 3);
            assert!(ast.signature.return_type.is_none());
            let _name = Identifier::new("float");
            let _ident = Identifier::new("x");
            assert!(matches!(
                &ast.signature.parameters.as_ref().unwrap().0[0],
                Parameter {
                    name: _ident,
                    type_hint: _name,
                    value: None
                }
            ));
            let _name = Identifier::new("string");
            let _ident = Identifier::new("name");
            assert!(matches!(
                &ast.signature.parameters.as_ref().unwrap().0[1],
                Parameter {
                    name: _ident,
                    type_hint: _name,
                    value: None
                }
            ));
            let _name = Identifier::new("bool");
            let _ident = Identifier::new("ok");
            assert!(matches!(
                &ast.signature.parameters.as_ref().unwrap().0[2],
                Parameter {
                    name: _ident,
                    type_hint: _name,
                    value: Some(Expression::Literal(Literal::Bool(true)))
                }
            ));
        }

        #[test]
        fn param_ret() {
            let mut result =
                CoriumParser::parse(Rule::Function, "function f (x float) float {\n}\n").unwrap();
            let ast = Function::populate(result.next().unwrap().into_inner());
            assert!(ast.block.0.is_empty());
            assert_eq!(ast.signature.name.full, "f");
            assert!(ast.signature.parameters.is_some());
            assert_eq!(ast.signature.parameters.as_ref().unwrap().0.len(), 1);
            assert!(ast.signature.return_type.is_some());
            let _name = Identifier::new("float");
            assert!(matches!(ast.signature.return_type.unwrap(), _name));
            let _name = Identifier::new("float");
            let _ident = Identifier::new("x");
            assert!(matches!(
                &ast.signature.parameters.as_ref().unwrap().0[0],
                Parameter {
                    name: _ident,
                    type_hint: _name,
                    value: None
                }
            ));
        }

        #[test]
        fn return_statement() {
            let mut result =
                CoriumParser::parse(Rule::Function, "function f () {\nreturn 10\n}\n").unwrap();
            let ast = Function::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.signature.name.full, "f");
            assert!(ast.signature.parameters.is_none());
            assert!(ast.signature.return_type.is_none());
            assert_eq!(ast.block.0.len(), 1);
            assert!(matches!(
                &ast.block.0[0],
                LocalStatement::ReturnStatement(ReturnStatement(Some(Expression::Literal(
                    Literal::Int(10)
                ))))
            ))
        }

        #[test]
        fn complex() {
            let src = concat!(
                "function compute (x int = 0) int {\n",
                "    let result = \"LOL\"\n",
                "    return 23\n",
                "}\n"
            );
            let mut result = CoriumParser::parse(Rule::Function, src).unwrap();
            let ast = Function::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.signature.name.full, "compute");
            assert!(ast.signature.parameters.is_some());
            assert!(ast.signature.return_type.is_some());
            assert_eq!(ast.block.0.len(), 2);
            let _name = Identifier::new("int");
            let _ident = Identifier::new("x");
            assert!(matches!(
                &ast.signature.parameters.as_ref().unwrap().0[0],
                Parameter {
                    name: _ident,
                    type_hint: _name,
                    value: Some(Expression::Literal(Literal::Int(0)))
                }
            ));
            assert_eq!(ast.signature.return_type.unwrap().full, "int");
            let _ident = Identifier::new("result");
            assert!(matches!(
                &ast.block.0[0],
                LocalStatement::MutableVariable(MutableVariable {
                    name: _ident,
                    type_hint: None,
                    value: Expression::Literal(Literal::String("LOL"))
                })
            ));
            assert!(matches!(
                &ast.block.0[1],
                LocalStatement::ReturnStatement(ReturnStatement(Some(Expression::Literal(
                    Literal::Int(23)
                ))))
            ));
        }
    }

    mod global_statement {
        use crate::ast::populator::NestedAstPopulator;
        use crate::ast::tree::binary_operator::BinaryOperator;
        use crate::ast::tree::block::Block;
        use crate::ast::tree::expression::Expression;
        use crate::ast::tree::function::Function;
        use crate::ast::tree::global_statement::GlobalStatement;
        use crate::ast::tree::immutable_variable::ImmutableVariable;
        use crate::ast::tree::literal::Literal;
        use crate::ast::tree::local_statement::LocalStatement;
        use crate::ast::tree::mutable_variable::MutableVariable;
        use crate::ast::tree::native_function::NativeFunction;
        use crate::ast::tree::return_statement::ReturnStatement;

        use super::*;
        use crate::ast::tree::Rule;

        fn fun1() -> GlobalStatement<'static> {
            GlobalStatement::Function(Function {
                signature: FunctionSignature {
                    name: Identifier::new("square"),
                    parameters: Some(ParameterList(vec![
                        Parameter {
                            name: Identifier::new("x"),
                            type_hint: Identifier::new("float"),
                            value: None,
                        },
                        Parameter {
                            name: Identifier::new("y"),
                            type_hint: Identifier::new("float"),
                            value: Some(Expression::Literal(Literal::Float(1.0))),
                        },
                    ])),
                    return_type: Some(Identifier::new("float")),
                },
                block: Block(vec![LocalStatement::ReturnStatement(ReturnStatement(
                    Some(Expression::Binary {
                        lhs: Box::new(Expression::Identifier(Identifier::new("x"))),
                        op: BinaryOperator::Multiplication,
                        rhs: Box::new(Expression::Identifier(Identifier::new("y"))),
                    }),
                ))]),
            })
        }

        #[test]
        fn function_calculation() {
            let src = concat!(
                "function square (x float, y float = 1.0) float {\n",
                "return x * y\n",
                "}\n"
            );
            let mut result = CoriumParser::parse(Rule::GlobalStatement, src).unwrap();
            let ast = GlobalStatement::populate(result.next().unwrap().into_inner());
            let _fun = fun1();
            assert!(matches!(ast, _fun));
        }

        #[test]
        fn function() {
            let src = "function f () {\nlet x = 10\n}\n";
            let mut result = CoriumParser::parse(Rule::GlobalStatement, src).unwrap();
            let ast = GlobalStatement::populate(result.next().unwrap().into_inner());
            let _ident = Identifier::new("x");
            let _block = vec![LocalStatement::MutableVariable(MutableVariable {
                name: _ident,
                type_hint: None,
                value: Expression::Literal(Literal::Int(10)),
            })];
            let _ident = Identifier::new("f");
            assert!(matches!(
                ast,
                GlobalStatement::Function(Function {
                    signature: FunctionSignature {
                        name: _ident,
                        return_type: None,
                        parameters: None
                    },
                    block: Block(_block)
                })
            ));
        }

        #[test]
        fn native_function() {
            let src = "native function f ()\n";
            let mut result = CoriumParser::parse(Rule::GlobalStatement, src).unwrap();
            let ast = GlobalStatement::populate(result.next().unwrap().into_inner());
            let _ident = Identifier::new("f");
            assert!(matches!(
                ast,
                GlobalStatement::NativeFunction(NativeFunction {
                    signature: FunctionSignature {
                        name: _ident,
                        return_type: None,
                        parameters: None
                    }
                })
            ));
        }

        #[test]
        fn mutable_variable() {
            let src = "let x = 10\n";
            let mut result = CoriumParser::parse(Rule::GlobalStatement, src).unwrap();
            let ast = GlobalStatement::populate(result.next().unwrap().into_inner());
            let _ident = Identifier::new("x");
            assert!(matches!(
                ast,
                GlobalStatement::MutableVariable(MutableVariable {
                    name: _ident,
                    type_hint: None,
                    value: Expression::Literal(Literal::Int(10))
                })
            ));
        }

        #[test]
        fn immutable_variable() {
            let src = "const x = 10\n";
            let mut result = CoriumParser::parse(Rule::GlobalStatement, src).unwrap();
            let ast = GlobalStatement::populate(result.next().unwrap().into_inner());
            let _ident = Identifier::new("x");
            assert!(matches!(
                ast,
                GlobalStatement::ImmutableVariable(ImmutableVariable {
                    name: _ident,
                    type_hint: None,
                    value: Expression::Literal(Literal::Int(10))
                })
            ));
        }

        #[test]
        fn native_no_newline1() {
            let src = "native function f ()";
            let result = CoriumParser::parse(Rule::GlobalStatement, src);
            assert!(result.is_err());
        }

        #[test]
        fn function_no_newline1() {
            let src = "function f () {let x = 10\n}\n";
            let result = CoriumParser::parse(Rule::GlobalStatement, src);
            assert!(result.is_err());
        }

        #[test]
        fn function_no_newline2() {
            let src = "function f () {\nlet x = 10}\n";
            let result = CoriumParser::parse(Rule::GlobalStatement, src);
            assert!(result.is_err());
        }

        #[test]
        fn function_no_newline3() {
            let src = "function f () {\nlet x = 10\n}";
            let result = CoriumParser::parse(Rule::GlobalStatement, src);
            assert!(result.is_err());
        }
    }

    mod compilation_unit {
        use super::*;
        use crate::ast::populator::NestedAstPopulator;
        use crate::ast::tree::block::Block;
        use crate::ast::tree::compilation_unit::CompilationUnit;
        use crate::ast::tree::expression::Expression;
        use crate::ast::tree::function::Function;
        use crate::ast::tree::global_statement::GlobalStatement;
        use crate::ast::tree::literal::Literal;
        use crate::ast::tree::local_statement::LocalStatement;
        use crate::ast::tree::mutable_variable::MutableVariable;
        use crate::ast::tree::native_function::NativeFunction;
        use crate::ast::tree::Rule;

        #[test]
        fn module() {
            let mut result = CoriumParser::parse(Rule::CompilationUnit, "module x\n").unwrap();
            let ast = CompilationUnit::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.module.qualified_name(), "x");
        }

        #[test]
        fn module_functions() {
            let src = concat!(
                "module test\n",
                "native function f ()\n",
                "function y () {\n",
                "let x int = 10\n",
                "}\n",
                "native function get () char\n"
            );
            let mut result = CoriumParser::parse(Rule::CompilationUnit, src).unwrap();
            let ast = CompilationUnit::populate(result.next().unwrap().into_inner());
            assert_eq!(ast.module.qualified_name(), "test");
            assert_eq!(ast.statements.len(), 3);
            let _ident = Identifier::new("f");
            assert!(matches!(
                &ast.statements[0],
                GlobalStatement::NativeFunction(NativeFunction {
                    signature: FunctionSignature {
                        name: _ident,
                        parameters: None,
                        return_type: None
                    }
                })
            ));
            let _block = Block(vec![LocalStatement::MutableVariable(MutableVariable {
                name: Identifier::new("x"),
                type_hint: Some(Identifier::new("int")),
                value: Expression::Literal(Literal::Int(10)),
            })]);
            let _ident = Identifier::new("y");
            assert!(matches!(
                &ast.statements[1],
                GlobalStatement::Function(Function {
                    signature: FunctionSignature {
                        name: _ident,
                        parameters: None,
                        return_type: None
                    },
                    block: _block
                })
            ));
            let _name = Identifier::new("char");
            let _ident = Identifier::new("get");
            assert!(matches!(
                &ast.statements[2],
                GlobalStatement::NativeFunction(NativeFunction {
                    signature: FunctionSignature {
                        name: _ident,
                        parameters: None,
                        return_type: Some(_name)
                    }
                })
            ));
        }
    }
}
