Example #1
0
        public void FunctionCallExpression4()
        {
            var e = new FunctionCallExpression("f", new [] { (Expression) new Literal("x"), new StringLiteral("y") });

            Assert.IsFalse(e.IsTrivial);
            Assert.AreEqual("f(x, \"y\")", e.ToString());
        }
Example #2
0
        public void FunctionCallExpression2()
        {
            var e = new FunctionCallExpression("", new Expression[0]);

            Assert.IsFalse(e.IsTrivial);
            Assert.AreEqual("()", e.ToString());
        }
        private RuleOutcome GetOutcomeRule(FunctionCallExpression fc)
        {
            var binaryExpression = fc.ArgumentList.Expressions[0].Element as BinaryExpression;
            var left             = binaryExpression.Left.ToString();
            var right            = binaryExpression.Right.ToString();
            var op = binaryExpression.Operator.ToString();

            return(new RuleOutcome(
                       this.Name,
                       score: 5,
                       referenceText: fc.ToString(),
                       message:
                       $"If any of the columns referenced in '{fc.ToString()}' contains nulls, significant values might not be included due to scalar arithmetic null propagation rules." + Environment.NewLine +
                       $"Consider rewriting it as 'sum({left}) {op} sum({right})'.",
                       severity: Severity.Warning,
                       category: Category.Correctness,
                       textStart: fc.TextStart
                       ));
        }
Example #4
0
        public void TestAddZero()
        {
            var left  = new FunctionCallExpression("byte", new[] { new IntegerConstantExpression(0) });
            var right = new IntegerConstantExpression(0);
            var expr  = new MathematicExpression(left, MathematicOperation.Add, right);
            var scope = new InterpreterScope();

            scope.Context = new TriggerBuilderContext();
            scope.AddFunction(new MemoryAccessorFunction("byte", FieldSize.Byte));

            ExpressionBase result;

            Assert.That(expr.ReplaceVariables(scope, out result), Is.True);
            Assert.That(result.ToString(), Is.EqualTo(left.ToString()));
        }
        private static Diagnostic GetDiagnostic(FunctionCallExpression fc)
        {
            var binaryExpression = fc.ArgumentList.Expressions[0].Element as BinaryExpression;
            var left             = binaryExpression.Left.ToString();
            var right            = binaryExpression.Right.ToString();
            var op = binaryExpression.Operator.Text;

            return(new Diagnostic(
                       "KustoNullAggregation",
                       category: DiagnosticCategory.Correctness,
                       severity: DiagnosticSeverity.Warning,
                       message:
                       $"If any of the columns referenced in '{fc.ToString()}' contains nulls, significant values might not be included due to scalar arithmetic null propagation rules."
                       + Environment.NewLine +
                       $"Consider rewriting it as '{fc.Name}({left}) {op} {fc.Name}({right})'.")
                   .WithLocation(fc));
        }
Example #6
0
        public void TestReplaceVariablesMemoryAccessor()
        {
            var value = new FunctionCallExpression("byte", new[] { new IntegerConstantExpression(1) });
            var expr  = new ArrayExpression();

            expr.Entries.Add(value);

            var scope = new InterpreterScope(AchievementScriptInterpreter.GetGlobalScope());

            ExpressionBase result;

            Assert.That(expr.ReplaceVariables(scope, out result), Is.True);

            Assert.That(result, Is.InstanceOf <ArrayExpression>());
            var arrayResult = (ArrayExpression)result;

            Assert.That(arrayResult.Entries.Count, Is.EqualTo(1));
            Assert.That(arrayResult.Entries[0].ToString(), Is.EqualTo(value.ToString()));
        }