예제 #1
0
    def test_both_dead(self):
        "Test removing a both node when one side is dead"
        t = ast.Constant(True)
        f = ast.Constant(False)

        # Should reduce to left
        n = ast.Both(t, f)
        c, r = optimizer.optimization_pass(n)
        assert c == 1
        assert r is t

        # Should reduce to right
        n = ast.Both(f, t)
        c, r = optimizer.optimization_pass(n)
        assert c == 1
        assert r is t
예제 #2
0
    def test_negate(self):
        "Test negation static analysis"
        t = ast.Constant(True)
        f = ast.Constant(False)
        n = ast.NegateOperator(t)

        # Should reduce to False
        c, r = optimizer.optimization_pass(n)
        assert c == 1
        assert isinstance(r, ast.Constant)
        assert r.value == False

        # Should reduce to True
        n = ast.NegateOperator(f)
        c, r = optimizer.optimization_pass(n)
        assert c == 1
        assert isinstance(r, ast.Constant)
        assert r.value == True
예제 #3
0
    def test_or_replace(self):
        "Test OR -> True"
        t = ast.Constant(True)
        f = ast.Constant(False)
        n = ast.LogicalOperator('or', t, f)

        # Should reduce to True
        c, r = optimizer.optimization_pass(n)
        assert c == 1
        assert isinstance(r, ast.Constant)
        assert r.value == True

        # Should reduce to True
        n = ast.LogicalOperator('or', f, t)
        c, r = optimizer.optimization_pass(n)
        assert c == 1
        assert isinstance(r, ast.Constant)
        assert r.value == True
예제 #4
0
    def test_and_replace(self):
        "Test AND -> False"
        t = ast.Constant(True)
        f = ast.Constant(False)
        n = ast.LogicalOperator('and', t, f)

        # Should reduce to False
        c, r = optimizer.optimization_pass(n)
        assert c == 1
        assert isinstance(r, ast.Constant)
        assert r.value == False

        # Should reduce to False
        n = ast.LogicalOperator('and', f, t)
        c, r = optimizer.optimization_pass(n)
        assert c == 1
        assert isinstance(r, ast.Constant)
        assert r.value == False
예제 #5
0
 def test_undef_contains(self):
     "Tests removing an Empty contains X"
     u = ast.Undefined()
     v = ast.Literal('foo')
     cn = ast.ContainsOperator(u, v)
     c, r = optimizer.optimization_pass(cn)
     assert c == 1
     assert isinstance(r, ast.Constant)
     assert r.value == False
예제 #6
0
    def test_push_result(self):
        "Test false push result"
        f = ast.Constant(False)
        n = ast.PushResult(None, f)

        # Should reduce to False
        c, r = optimizer.optimization_pass(n)
        assert c == 1
        assert isinstance(r, ast.Constant)
        assert r.value == False
예제 #7
0
    def test_both_all_false(self):
        "Test removing a both node when both sides are false"
        f = ast.Constant(False)
        n = ast.Both(f, f)

        # Should reduce to False
        c, r = optimizer.optimization_pass(n)
        assert c == 1
        assert isinstance(r, ast.Constant)
        assert r.value == False
예제 #8
0
    def test_and_dead(self):
        "Tests removing AND with dead branch"
        t = ast.Constant(True)
        l = ast.Literal('foo')
        v = ast.Number(42)
        cmp = ast.CompareOperator('=', l, v)
        n = ast.LogicalOperator('and', t, cmp)

        # Should reduce to to the compare
        c, r = optimizer.optimization_pass(n)
        assert c == 1
        assert r is cmp
예제 #9
0
    def test_or_dead(self):
        "Tests removing OR with dead branch"
        f = ast.Constant(False)
        l = ast.Literal('foo')
        v = ast.Number(42)
        cmp = ast.CompareOperator('=', l, v)
        n = ast.LogicalOperator('or', f, cmp)

        # Should reduce to to the compare
        c, r = optimizer.optimization_pass(n)
        assert c == 1
        assert r is cmp
예제 #10
0
    def test_or_dead(self):
        "Tests removing OR with dead branch"
        f = ast.Constant(False)
        l = ast.Literal('foo')
        v = ast.Number(42)
        cmp = ast.CompareOperator('=', l, v)
        n = ast.LogicalOperator('or', f, cmp)

        # Should reduce to to the compare
        c, r = optimizer.optimization_pass(n)
        assert c == 1
        assert r is cmp
예제 #11
0
    def test_branch_true_dead(self):
        "Test branch with the false branch being dead"
        t = ast.Constant(True)
        f = ast.Constant(False)
        l = ast.Literal('foo')
        v = ast.Number(42)
        cmp = ast.CompareOperator('=', l, v)
        n = ast.Branch(f, t, cmp)

        # Should reduce to to the compare
        c, r = optimizer.optimization_pass(n)
        assert c == 1
        assert r is cmp
예제 #12
0
    def test_branch_true_dead(self):
        "Test branch with the false branch being dead"
        t = ast.Constant(True)
        f = ast.Constant(False)
        l = ast.Literal('foo')
        v = ast.Number(42)
        cmp = ast.CompareOperator('=', l, v)
        n = ast.Branch(f, t, cmp)

        # Should reduce to to the compare
        c, r = optimizer.optimization_pass(n)
        assert c == 1
        assert r is cmp
예제 #13
0
 def test_empty_set(self):
     "Test removing an empty literal set"
     s = ast.LiteralSet([])
     c, r = optimizer.optimization_pass(s)
     assert c == 1
     assert isinstance(r, ast.Empty)
예제 #14
0
 def test_empty_set(self):
     "Test removing an empty literal set"
     s = ast.LiteralSet([])
     c, r = optimizer.optimization_pass(s)
     assert c == 1
     assert isinstance(r, ast.Empty)