Example #1
0
        public void Test_FlattenBinaryOpSeq()
        {
            ExpectList(LNode.FlattenBinaryOpSeq(a, S.Add, null), new[] { a });
            ExpectList(LNode.FlattenBinaryOpSeq(a, S.Add, false), new[] { a });
            ExpectList(LNode.FlattenBinaryOpSeq(a, S.Add, true), new[] { a });
            var expr = F.Call(S.Add, a, b);

            ExpectList(LNode.FlattenBinaryOpSeq(expr, S.Add, null), new[] { a, b });
            ExpectList(LNode.FlattenBinaryOpSeq(expr, S.Add, false), new[] { a, b });
            ExpectList(LNode.FlattenBinaryOpSeq(expr, S.Add, true), new[] { a, b });
            var fooCall = F.Call(Foo, c, zero);             // Ensure this is not mistaken for an operator

            expr = F.Call(S.Assign, a, F.Call(S.Assign, b, fooCall));
            ExpectList(LNode.FlattenBinaryOpSeq(expr, S.Assign, null), new[] { a, b, fooCall });
            ExpectList(LNode.FlattenBinaryOpSeq(expr, S.Assign, false), new[] { a, F.Call(S.Assign, b, fooCall) });
            ExpectList(LNode.FlattenBinaryOpSeq(expr, S.Assign, true), new[] { a, b, fooCall });
            expr = F.Call(S.Mul, F.Call(S.Mul, a, b), F.Call(S.Mul, c, two));
            ExpectList(LNode.FlattenBinaryOpSeq(expr, S.Mul, null), new[] { a, b, c, two });
            ExpectList(LNode.FlattenBinaryOpSeq(expr, S.Mul, false), new[] { a, b, F.Call(S.Mul, c, two) });
            ExpectList(LNode.FlattenBinaryOpSeq(expr, S.Mul, true), new[] { F.Call(S.Mul, a, b), c, two });
        }