From c82c131a59e12a514706b89ecf3d4fc8c6e49f69 Mon Sep 17 00:00:00 2001 From: Axel Hecht Date: Thu, 22 Mar 2018 12:14:08 +0100 Subject: [PATCH] bug 1447905, missing dependencies in REPLACE The replacements in a REPLACE transform are in a dict, which fold() didn't go in to. --- fluent/util.py | 2 ++ tests/migrate/test_util.py | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/fluent/util.py b/fluent/util.py index 4afeaec4..50a2ac9e 100644 --- a/fluent/util.py +++ b/fluent/util.py @@ -36,6 +36,8 @@ def fold_(vals, acc): acc = fold(fun, head, acc) if isinstance(head, list): acc = fold_(head, acc) + if isinstance(head, dict): + acc = fold_(head.values(), acc) return fold_(tail, fun(acc, head)) diff --git a/tests/migrate/test_util.py b/tests/migrate/test_util.py index 32ea42d1..40a81df3 100644 --- a/tests/migrate/test_util.py +++ b/tests/migrate/test_util.py @@ -5,7 +5,7 @@ import fluent.syntax.ast as FTL from fluent.util import fold -from fluent.migrate.transforms import CONCAT, COPY, Source +from fluent.migrate.transforms import CONCAT, COPY, REPLACE, Source def get_source(acc, cur): @@ -81,3 +81,20 @@ def test_copy_concat(self): fold(get_source, node, ()), (('path1', 'key1'), ('path2', 'key2')) ) + + def test_copy_in_replace(self): + node = FTL.Message( + FTL.Identifier('hello'), + value=REPLACE( + 'path1', + 'key1', + { + "foo": COPY('path2', 'key2') + } + ) + ) + + self.assertEqual( + fold(get_source, node, ()), + (('path2', 'key2'), ('path1', 'key1')) + )