Skip to content

Commit 9914930

Browse files
committed
format - some additional tests for messages/terms in terms
Thanks @stasm
1 parent 59292d6 commit 9914930

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

fluent.runtime/tests/format/test_parameterized_terms.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def setUp(self):
1616
-thing = { $article ->
1717
*[definite] the thing
1818
[indefinite] a thing
19+
[none] thing
1920
}
2021
thing-no-arg = { -thing }
2122
thing-no-arg-alt = { -thing() }
@@ -56,6 +57,11 @@ def test_no_implicit_access_to_external_args(self):
5657
self.assertEqual(val, 'the thing')
5758
self.assertEqual(errs, [])
5859

60+
def test_no_implicit_access_to_external_args_but_term_args_still_passed(self):
61+
val, errs = self.ctx.format('thing-with-arg', {'article': 'none'})
62+
self.assertEqual(val, 'a thing')
63+
self.assertEqual(errs, [])
64+
5965
def test_bad_term(self):
6066
val, errs = self.ctx.format('bad-term', {})
6167
self.assertEqual(val, '-missing')
@@ -138,7 +144,53 @@ def test_inner_arg(self):
138144
self.assertEqual(val, 'The thing.')
139145
self.assertEqual(errs, [])
140146

147+
def test_inner_arg_with_external_args(self):
148+
val, errs = self.ctx.format('inner-arg', {'article': 'indefinite'})
149+
self.assertEqual(val, 'The thing.')
150+
self.assertEqual(errs, [])
151+
141152
def test_neither_arg(self):
142153
val, errs = self.ctx.format('neither-arg', {})
143154
self.assertEqual(val, 'the thing.')
144155
self.assertEqual(errs, [])
156+
157+
158+
class TestTermsCalledFromTerms(unittest.TestCase):
159+
160+
def setUp(self):
161+
self.ctx = FluentBundle(['en-US'], use_isolating=False)
162+
self.ctx.add_messages(dedent_ftl("""
163+
-foo = {$a} {$b}
164+
-bar = {-foo(b: 2)}
165+
-baz = {-foo}
166+
ref-bar = {-bar(a: 1)}
167+
ref-baz = {-baz(a: 1)}
168+
"""))
169+
170+
def test_term_args_isolated_with_call_syntax(self):
171+
val, errs = self.ctx.format('ref-bar', {})
172+
self.assertEqual(val, 'a 2')
173+
self.assertEqual(errs, [])
174+
175+
def test_term_args_isolated_without_call_syntax(self):
176+
val, errs = self.ctx.format('ref-baz', {})
177+
self.assertEqual(val, 'a b')
178+
self.assertEqual(errs, [])
179+
180+
181+
class TestMessagesCalledFromTerms(unittest.TestCase):
182+
183+
def setUp(self):
184+
self.ctx = FluentBundle(['en-US'], use_isolating=False)
185+
self.ctx.add_messages(dedent_ftl("""
186+
msg = Msg is {$arg}
187+
-foo = {msg}
188+
ref-foo = {-foo(arg: 1)}
189+
"""))
190+
191+
def test_messages_inherit_term_args(self):
192+
# This behaviour may change in future, message calls might be
193+
# disallowed from inside terms
194+
val, errs = self.ctx.format('ref-foo', {'arg': 2})
195+
self.assertEqual(val, 'Msg is 1')
196+
self.assertEqual(errs, [])

0 commit comments

Comments
 (0)