Beispiel #1
0
        public void CheckParseError()
        {
            var engine = new RecalcEngine();
            var result = engine.Check("3*1+");

            Assert.False(result.IsSuccess);
            Assert.Single(result.Errors);
            Assert.StartsWith("Error 4-4: Expected an operand", result.Errors[0].ToString());
        }
Beispiel #2
0
        public void CheckBindError()
        {
            var engine = new RecalcEngine();
            var result = engine.Check("3+foo+2"); // foo is undefined

            Assert.False(result.IsSuccess);
            Assert.Single(result.Errors);
            Assert.StartsWith("Error 2-5: Name isn't valid. This identifier isn't recognized", result.Errors[0].ToString());
        }
Beispiel #3
0
        public void CheckBindEnum()
        {
            var engine = new RecalcEngine();
            var result = engine.Check("TimeUnit.Hours");

            Assert.True(result.IsSuccess);

            // The resultant type will be the underlying type of the enum provided to
            // check.  In the case of TimeUnit, this is StringType
            Assert.True(result.ReturnType is StringType);
            Assert.Empty(result.TopLevelIdentifiers);
        }
Beispiel #4
0
        public void CheckSuccess()
        {
            var engine = new RecalcEngine();
            var result = engine.Check("3*2+x",
                                      new RecordType().Add(
                                          new NamedFormulaType("x", FormulaType.Number)));

            Assert.True(result.IsSuccess);
            Assert.True(result.ReturnType is NumberType);
            Assert.Single(result.TopLevelIdentifiers);
            Assert.Equal("x", result.TopLevelIdentifiers.First());
        }
        [InlineData("With({B:15}, B> A)", "A")]                         // B is shadowed
        public void T1(string expr, string dependsOn)
        {
            // var expected = new HashSet<string>(dependsOn.Split(','));

            var engine = new RecalcEngine();

            var accountType = new TableType()
                              .Add(new NamedFormulaType("Age", FormulaType.Number));

            var type = new RecordType()
                       .Add(new NamedFormulaType("A", FormulaType.Number))
                       .Add(new NamedFormulaType("B", FormulaType.Number))
                       .Add(new NamedFormulaType("Accounts", accountType));
            var result = engine.Check(expr, type);

            Assert.True(result.IsSuccess);

            // sets should be equal
            var sorted    = result.TopLevelIdentifiers.OrderBy(x => x).ToArray();
            var actualStr = string.Join(',', sorted);

            Assert.Equal(dependsOn, actualStr);
        }