use_reduce: Next try on full reduction
authorSebastian Luther <SebastianLuther@gmx.de>
Fri, 15 Oct 2010 13:01:57 +0000 (15:01 +0200)
committerZac Medico <zmedico@gentoo.org>
Fri, 15 Oct 2010 13:22:20 +0000 (06:22 -0700)
pym/portage/dep/__init__.py
pym/portage/tests/dep/test_use_reduce.py

index 3db2ae02d17cbcf309c02c132476607c3ca77da0..60e94f0bdc5445c6f20b122f4ad0163e73dc8be3 100644 (file)
@@ -445,7 +445,7 @@ def use_reduce(depstr, uselist=[], masklist=[], matchall=False, excludeall=[], i
                                                                stack[level].extend(l[1])
                                                elif len(l) == 1 and isinstance(l[0], list):
                                                        # l = [[...]]
-                                                       last = last_any_of_operator_level(level)
+                                                       last = last_any_of_operator_level(level-1)
                                                        if last == -1:
                                                                if opconvert and isinstance(l[0], list) \
                                                                        and l[0] and l[0][0] == '||':
@@ -453,7 +453,10 @@ def use_reduce(depstr, uselist=[], masklist=[], matchall=False, excludeall=[], i
                                                                else:
                                                                        stack[level].extend(l[0])
                                                        else:
-                                                               stack[level].append(l[0])
+                                                               if opconvert and l[0] and l[0][0] == "||":
+                                                                       stack[level].extend(l[0][1:])
+                                                               else:
+                                                                       stack[level].append(l[0])
                                                else:
                                                        stack[level].extend(l)
                                        else:
@@ -480,7 +483,7 @@ def use_reduce(depstr, uselist=[], masklist=[], matchall=False, excludeall=[], i
                                                stack[level].pop()
                                                stack[level].extend(l)
                                        else:
-                                               if opconvert and starts_with_any_of_dep(level):
+                                               if opconvert and ends_in_any_of_dep(level):
                                                        #In opconvert mode, we have to move the operator from the level
                                                        #above into the current list.
                                                        stack[level].pop()
index f7e9b101233716ab332e0b0e482300d616bf7d38..7c7286ad801ca0787b456ab64b86a64d2c3aa4db 100644 (file)
@@ -321,7 +321,7 @@ class UseReduce(TestCase):
                                "A foo? ( || ( B || ( bar? ( || ( C D E ) ) !bar? ( F ) ) ) ) G",
                                uselist = ["foo", "bar"],
                                opconvert = True,
-                               expected_result = ['A', ['||', 'B', ['||', 'C', 'D', 'E']], 'G']),
+                               expected_result = ['A', ['||', 'B', 'C', 'D', 'E'], 'G']),
                        UseReduceTestCase(
                                "A foo? ( || ( B || ( bar? ( || ( C D E ) ) !bar? ( F ) ) ) ) G",
                                uselist = ["foo", "bar"],
@@ -376,7 +376,7 @@ class UseReduce(TestCase):
                                "|| ( ( A B ) foo? ( || ( C D ) ) )",
                                uselist = ["foo"],
                                opconvert = True,
-                               expected_result = [['||', ['A', 'B'], ['||', 'C', 'D']]]),
+                               expected_result = [['||', ['A', 'B'], 'C', 'D']]),
 
                        UseReduceTestCase(
                                "|| ( ( A B ) foo? ( || ( C D ) ) )",
@@ -392,6 +392,11 @@ class UseReduce(TestCase):
                                "|| ( ( A B ) || ( C D || ( E ( F G ) || ( H ) ) ) )",
                                expected_result = ['||', [['A', 'B'], 'C', 'D', 'E', ['F', 'G'], 'H']]),
 
+                       UseReduceTestCase(
+                               "|| ( ( A B ) || ( C D || ( E ( F G ) || ( H ) ) ) )",
+                               opconvert = True,
+                               expected_result = [['||', ['A', 'B'], 'C', 'D', 'E', ['F', 'G'], 'H']]),
+
                        UseReduceTestCase(
                                "|| ( foo? ( A B ) )",
                                uselist = ["foo"],
@@ -419,7 +424,13 @@ class UseReduce(TestCase):
                        UseReduceTestCase(
                                "|| ( ( A B ) || ( foo? ( bar? ( ( C D || ( baz? ( E ) ( F G ) || ( H ) ) ) ) ) ) )",
                                uselist = ["foo", "bar", "baz"],
-                               expected_result = ['||', [['A', 'B'], 'C', 'D', '||', ['E', ['F', 'G'], 'H']]]),
+                               expected_result = ['||', [['A', 'B'], ['C', 'D', '||', ['E', ['F', 'G'], 'H']]]]),
+
+                       UseReduceTestCase(
+                               "|| ( ( A B ) || ( foo? ( bar? ( ( C D || ( baz? ( E ) ( F G ) || ( H ) ) ) ) ) ) )",
+                               uselist = ["foo", "bar", "baz"],
+                               opconvert = True,
+                               expected_result = [['||', ['A', 'B'], ['C', 'D', ['||', 'E', ['F', 'G'], 'H']]]]),
 
                        UseReduceTestCase(
                                "|| ( foo? ( A B ) )",