Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions fluent/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
19 changes: 18 additions & 1 deletion tests/migrate/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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'))
)