示例#1
0
        public void ShouldParseOneExpression([ValueSource(nameof(Expressions))] ExpressionTestCase expression)
        {
            // Given
            var parser = new QuerySyntaxTreeParser();

            // When
            var result = parser.Parse(expression.Expression)?.ToArray();

            // Then
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Length);
            expression.Assertion(result[0]);
        }
示例#2
0
        public void ShouldParseTwoExpression([ValueSource(nameof(Expressions))] ExpressionTestCase expression1,
                                             [ValueSource(nameof(Expressions))] ExpressionTestCase expression2)
        {
            // Given
            var parser = new QuerySyntaxTreeParser();

            // When
            var result = parser.Parse($"{expression1.Expression}, {expression2.Expression}")?.ToArray();

            // Then
            Assert.IsNotNull(result);
            Assert.AreEqual(2, result.Length);
            expression1.Assertion(result[0]);
            expression2.Assertion(result[1]);
        }
示例#3
0
        public void InterpreterTestCase(ExpressionTestCase testCase)
        {
            _runner = new InterpreterRunner();
            var engineName = _runner.GetName();

            string       actualStr;
            FormulaValue result          = null;
            bool         exceptionThrown = false;

            try
            {
                result    = _runner.RunAsync(testCase.Input).Result;
                actualStr = TestToString(result);
            }
            catch (Exception e)
            {
                actualStr       = e.Message.Replace("\r\n", "|");
                exceptionThrown = true;
            }

            if ((exceptionThrown && testCase.GetExpected(nameof(InterpreterRunner)) == "Compile Error") || (result != null && testCase.GetExpected(nameof(InterpreterRunner)) == "#Error" && _runner.IsError(result)))
            {
                // Pass as test is expected to return an error
                return;
            }

            if (testCase.GetExpected(nameof(InterpreterRunner)) == "#Skip")
            {
                var goodResult = testCase.GetExpected("-");
                Assert.False(goodResult == actualStr || goodResult == "#Error" && _runner.IsError(result), "Test marked to skip returned correct result");

                // Since test is marked to skip and it didn't return a result that matched the baseline
                // expected result then we can marked it skipped here
                Skip.If(true, $"Test {testCase.SourceFile}:{testCase.SourceLine} was skipped by request");
            }

            Assert.Equal(testCase.GetExpected(nameof(InterpreterRunner)), actualStr);
        }