예제 #1
0
        public override void Run()
        {
            var root     = TestUtils.Parse("a = (-1 + 1) * 2 / 1 ^ 2 and 1 or 2");
            var exp_list = ASTFinder.Find <ExpressionList>(root);

            ExpectTrue(exp_list.exp_list.Count == 1);

            // or
            var bin_exp = exp_list.exp_list[0] as BinaryExpression;

            ExpectTrue(bin_exp.op.Match(Keyword.OR));
            ExpectTrue(bin_exp.right is Terminator);

            // and
            bin_exp = bin_exp.left as BinaryExpression;
            ExpectTrue(bin_exp.op.Match(Keyword.AND));

            // ((-1 + 1) * 2) / (1 ^ 2)
            bin_exp = bin_exp.left as BinaryExpression;
            ExpectTrue(bin_exp.op.m_type == '/');

            // 1^2
            var right = bin_exp.right as BinaryExpression;

            ExpectTrue(right.op.m_type == '^');

            // (-1 + 1) * 2
            var left = bin_exp.left as BinaryExpression;

            ExpectTrue(left.op.m_type == '*');
        }
예제 #2
0
        public override void Run()
        {
            var root     = TestUtils.Parse("a = 1 + 2 + 3");
            var exp_list = ASTFinder.Find <ExpressionList>(root);

            ExpectTrue(exp_list.exp_list.Count == 1);
            var bin_exp = exp_list.exp_list[0] as BinaryExpression;

            ExpectTrue(bin_exp.op.m_type == '+');

            // 1+2
            bin_exp = bin_exp.left as BinaryExpression;
            ExpectTrue(bin_exp.op.m_type == '+');
            var num = bin_exp.right as Terminator;

            ExpectTrue(num.token.m_number == 2 && num.token.m_type == (int)TokenType.NUMBER);
        }
예제 #3
0
        public override void Run()
        {
            var root     = TestUtils.Parse("a = 2+5*6*7 and 3");
            var exp_list = ASTFinder.Find <ExpressionList>(root);

            ExpectTrue(exp_list.exp_list.Count == 1);
            var bin_exp = exp_list.exp_list[0] as BinaryExpression;

            ExpectTrue(bin_exp.op.Match(Keyword.AND));

            // 2+2*2*2
            bin_exp = bin_exp.left as BinaryExpression;
            ExpectTrue(bin_exp.op.m_type == '+');
            // (2*2)*2
            bin_exp = bin_exp.right as BinaryExpression;
            ExpectTrue(bin_exp.op.m_type == '*');
            var num = bin_exp.right as Terminator;

            ExpectTrue(num.token.m_number == 7 && num.token.m_type == (int)TokenType.NUMBER);
        }