Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed regression with variant expressions involving missing terms #104

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 3 additions & 3 deletions fluent.runtime/fluent/runtime/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,9 @@ class VariantExpression(FTL.VariantExpression, BaseResolver):
def __call__(self, env):
message = lookup_reference(self.ref, env)

# TODO What to do if message is not a VariantList?
# Need test at least.
assert isinstance(message, VariantList)
if not isinstance(message, VariantList):
# Must be FluentNoneResolver
return message(env)

variant_name = self.key.name
return message(env, variant_name)
Expand Down
9 changes: 9 additions & 0 deletions fluent.runtime/tests/format/test_variants.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def setUp(self):
bar = { -variant[a] }
baz = { -variant[b] }
qux = { -variant[c] }
goo = { -missing[a] }
"""))

def test_returns_the_default_variant(self):
Expand All @@ -45,3 +46,11 @@ def test_choose_missing_variant(self):
self.assertEqual(
errs,
[FluentReferenceError("Unknown variant: c")])

def test_choose_missing_term(self):
val, errs = self.ctx.format('goo', {})
self.assertEqual(val, '-missing')
self.assertEqual(len(errs), 1)
self.assertEqual(
errs,
[FluentReferenceError("Unknown term: -missing")])