コード例 #1
0
        public void a_Eq_A()
        {
            string           expr       = "a=A";
            List <ExprToken> listTokens = TestCommon.AddTokens("a", "=", "A");

            // decoder, renvoie un arbre de node
            ExprTokensParser parser = new ExprTokensParser();

            // the default list: =, <, >, >=, <=, <>
            var dictOperators = TestCommon.BuildDefaultConfig();

            parser.SetConfiguration(dictOperators);

            // decode the list of tokens
            ParseResult            result   = parser.Parse(expr, listTokens);
            ExprSyntaxTreeAnalyzer analyzer = new ExprSyntaxTreeAnalyzer();

            analyzer.Analyze(result);

            // finished with no error
            Assert.AreEqual(0, result.ListError.Count, "The tokens should be decoded with success");

            // check the list of variables present in the expression
            Assert.AreEqual(1, result.ListExprVarUsed.Count, "The expression should have 1 variable");

            ExprObjectUsedBase obj1 = result.ListExprVarUsed.Find(o => o.Name.Equals("a"));

            Assert.IsNotNull(obj1, "The var a should exists");
            Assert.AreEqual(ExprObjectType.Variable, obj1.ExprObjectType, "The obj a should be a variable");
        }
コード例 #2
0
        public void a_Eq_12_checkVarSyntax_0var_err()
        {
            string           expr       = "0var";
            List <ExprToken> listTokens = TestCommon.AddTokens("0var");

            // decoder, renvoie un arbre de node
            ExprTokensParser parser = new ExprTokensParser();

            // the default list: =, <, >, >=, <=, <>
            var dictOperators = TestCommon.BuildDefaultConfig();

            parser.SetConfiguration(dictOperators);

            // decode the list of tokens
            ParseResult            result   = parser.Parse(expr, listTokens);
            ExprSyntaxTreeAnalyzer analyzer = new ExprSyntaxTreeAnalyzer();

            analyzer.Analyze(result);

            // finished with an error
            Assert.AreEqual(1, result.ListError.Count, "The tokens should be decoded with an error");

            // check the list of variables present in the expression
            Assert.AreEqual(0, result.ListExprVarUsed.Count, "The expression should have any variable");

            // todo: check error code
            Assert.AreEqual(ErrorCode.ValueNumberBadFormed, result.ListError[0].Code, "The error code should be: ValueNumberBadFormed");
        }