コード例 #1
0
        public void GetTokensFromBadFormulaTest()
        {
            var scope       = RecalcEngineScope.FromJson(new RecalcEngine(), "{\"A\":1,\"B\":[1,2,3]}");
            var checkResult = scope.Check("A + CountRows(B) + C + NoFunction(123)");

            var result = GetTokensUtils.GetTokens(checkResult._binding, GetTokensFlags.None);

            Assert.Equal(0, result.Count);

            result = GetTokensUtils.GetTokens(checkResult._binding, GetTokensFlags.UsedInExpression);
            Assert.Equal(3, result.Count);
            Assert.Equal(TokenResultType.Variable, result["A"]);
            Assert.Equal(TokenResultType.Variable, result["B"]);
            Assert.Equal(TokenResultType.Function, result["CountRows"]);
            Assert.False(result.ContainsKey("C"));
            Assert.False(result.ContainsKey("NoFunction"));

            result = GetTokensUtils.GetTokens(checkResult._binding, GetTokensFlags.AllFunctions);
            Assert.False(result.ContainsKey("A"));
            Assert.False(result.ContainsKey("B"));
            Assert.Equal(TokenResultType.Function, result["Abs"]);
            Assert.Equal(TokenResultType.Function, result["CountRows"]);
            Assert.Equal(TokenResultType.Function, result["Year"]);
            Assert.False(result.ContainsKey("C"));
            Assert.False(result.ContainsKey("NoFunction"));

            result = GetTokensUtils.GetTokens(checkResult._binding, GetTokensFlags.UsedInExpression | GetTokensFlags.AllFunctions);
            Assert.Equal(TokenResultType.Variable, result["A"]);
            Assert.Equal(TokenResultType.Variable, result["B"]);
            Assert.Equal(TokenResultType.Function, result["Abs"]);
            Assert.Equal(TokenResultType.Function, result["Year"]);
            Assert.Equal(TokenResultType.Function, result["CountRows"]);
            Assert.False(result.ContainsKey("C"));
            Assert.False(result.ContainsKey("NoFunction"));
        }
コード例 #2
0
ファイル: CheckResult.cs プロジェクト: jgrisham/Power-Fx
 internal IReadOnlyDictionary <string, TokenResultType> GetTokens(GetTokensFlags flags) => GetTokensUtils.GetTokens(_binding, flags);