<commit_before>﻿namespace OffByOne.Ql.Tests.ParserTests
{
    using System;
    using System.Linq;

    using OffByOne.LanguageCore.Ast.Literals;
    using OffByOne.Ql.Ast.Expressions;
    using OffByOne.Ql.Ast.Expressions.Binary;
    using OffByOne.Ql.Ast.Statements;
    using OffByOne.Ql.Ast.Statements.Branch;
    using OffByOne.Ql.Tests.ParserTests.Base;

    using Xunit;

    public class FormTest : ParserTest
    {
        [Fact]
        public void AstCreation_ShouldReturnFormNodeIfGivenSyntaxIsCorrect()
        {
            var astTree = this.GetAstNodesFromInput(@"
                form questionnaire { 
                    ""What is your birth date?"" 
                        birthDate: date

                    ""Do you want to continue?""
                        continue: boolean

                    if (birthDate < '31-12-1999' || continue) {
                        ""How much money do you spend on alcoholic beverages?""
                            alcoholicBeverages: money
                    } else {
                        ""Okay. Goodbye?""
                            exit: boolean(continue || false)
                    }
                }
            ");

            Assert.IsType<FormStatement>(astTree);

            var castAstTree = (FormStatement)astTree;

            Assert.Equal("questionnaire", castAstTree.Identifier);
            Assert.Equal(3, castAstTree.Statements.Count());

            var questions = castAstTree
                .Statements
                .OfType<QuestionStatement>()
                .ToList();

            Assert.True(questions.Any(x => x.Identifier == "birthDate" && x.Label == "What is your birth date?"));
            Assert.True(questions.Any(x => x.Identifier == "continue" && x.Label == "Do you want to continue?"));

            var ifStatement = castAstTree.Statements.OfType<IfStatement>().First();
            Assert.True(ifStatement.Condition is OrExpression);
            var condition = (OrExpression)ifStatement.Condition;

            Assert.IsType<LessThanExpression>(condition.LeftExpression);
            Assert.IsType<VariableExpression>(condition.RightExpression);

            var lessThanExp = (LessThanExpression)condition.LeftExpression;
            var variableExp = (VariableExpression)condition.RightExpression;

            Assert.IsType<VariableExpression>(lessThanExp.LeftExpression);
            Assert.IsType<Expression>(lessThanExp.RightExpression);
            Assert.Equal(variableExp.Identifier, "continue");

            var lhs = (VariableExpression)lessThanExp.LeftExpression;
            var rhs = (Expression)lessThanExp.RightExpression;
            Assert.IsType<DateLiteral>(rhs);

            Assert.Equal(lhs.Identifier, "birthDate");
            // Assert.Equal(((DateLiteral)rhs).Value, new DateTime(1999, 12, 31));

            var elseStatements = ifStatement.ElseStatements;
            Assert.Equal(1, elseStatements.Count());

            Assert.IsType<QuestionStatement>(elseStatements.First());<commit_msg>Found issue with failing test. Todo: fix it<commit_after>﻿namespace OffByOne.Ql.Tests.ParserTests
{
    using System;
    using System.Linq;

    using OffByOne.LanguageCore.Ast.Literals;
    using OffByOne.Ql.Ast.Expressions;
    using OffByOne.Ql.Ast.Expressions.Binary;
    using OffByOne.Ql.Ast.Statements;
    using OffByOne.Ql.Ast.Statements.Branch;
    using OffByOne.Ql.Tests.ParserTests.Base;

    using Xunit;

    public class FormTest : ParserTest
    {
        [Fact]
        public void AstCreation_ShouldReturnFormNodeIfGivenSyntaxIsCorrect()
        {
            var astTree = this.GetAstNodesFromInput(@"
                form questionnaire { 
                    ""What is your birth date?"" 
                        birthDate: date

                    ""Do you want to continue?""
                        continue: boolean

                    if (birthDate < '31-12-1999' || continue) {
                        ""How much money do you spend on alcoholic beverages?""
                            alcoholicBeverages: money
                    } else {
                        ""Okay. Goodbye?""
                            exit: boolean(continue || false)
                    }
                }
            ");

            Assert.IsType<FormStatement>(astTree);

            var castAstTree = (FormStatement)astTree;

            Assert.Equal("questionnaire", castAstTree.Identifier);
            Assert.Equal(3, castAstTree.Statements.Count());

            var questions = castAstTree
                .Statements
                .OfType<QuestionStatement>()
                .ToList();

            // TODO: Fix processing of StringLiterals
            Assert.True(questions.Any(x => x.Identifier == "birthDate" && x.Label == "What is your birth date?"));
            Assert.True(questions.Any(x => x.Identifier == "continue" && x.Label == "Do you want to continue?"));

            var ifStatement = castAstTree.Statements.OfType<IfStatement>().First();
            Assert.True(ifStatement.Condition is OrExpression);
            var condition = (OrExpression)ifStatement.Condition;

            Assert.IsType<LessThanExpression>(condition.LeftExpression);
            Assert.IsType<VariableExpression>(condition.RightExpression);

            var lessThanExp = (LessThanExpression)condition.LeftExpression;
            var variableExp = (VariableExpression)condition.RightExpression;

            Assert.IsType<VariableExpression>(lessThanExp.LeftExpression);
            Assert.IsType<Expression>(lessThanExp.RightExpression);
            Assert.Equal(variableExp.Identifier, "continue");

            var lhs = (VariableExpression)lessThanExp.LeftExpression;
            var rhs = (Expression)lessThanExp.RightExpression;
            Assert.IsType<DateLiteral>(rhs);

            Assert.Equal(lhs.Identifier, "birthDate");
            // Assert.Equal(((DateLiteral)rhs).Value, new DateTime(1999, 12, 31));

            var elseStatements = ifStatement.ElseStatements;
            Assert.Equal(1, elseStatements.Count());

            Assert.IsType<QuestionStatement>(elseStatements.First());
{'fraction_non_alphanumeric': 0.10065040650406504, 'fraction_numerical': 0.005853658536585366, 'mean_word_length': 2.0465577018325902, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4433001', 'n_tokens_mistral': 1643, 'n_tokens_neox': 1509, 'n_words': 293}