Example #1
0
 def test_placeable_bad_term(self):
     val, errs = self.bundle.format_pattern(
         self.bundle.get_message('bad-term-ref').value, {})
     self.assertEqual(val, 'Text {-not-a-term}')
     self.assertEqual(len(errs), 1)
     self.assertEqual(errs,
                      [FluentReferenceError("Unknown term: -not-a-term")])
 def test_ref_term_attribute_missing(self):
     val, errs = self.ctx.format('ref-term-attr-missing')
     self.assertEqual(val, "Other")
     self.assertEqual(len(errs), 1)
     self.assertEqual(
         errs,
         [FluentReferenceError('Unknown attribute: -my-term.missing')])
 def test_placeable_bad_message_attr(self):
     val, errs = self.ctx.format('bad-message-attr-ref', {})
     self.assertEqual(val, 'Text Message')
     self.assertEqual(len(errs), 1)
     self.assertEqual(
         errs,
         [FluentReferenceError("Unknown attribute: message.not-an-attr")])
 def test_missing_attr(self):
     # We don't fall back from attributes, get default.
     val, errs = self.bundle.format_pattern(
         self.bundle.get_message('missing-attr-ref').value, {})
     self.assertEqual(val, 'DEF option')
     self.assertEqual(
         errs, [FluentReferenceError('Unknown attribute: -other.missing')])
Example #5
0
 def test_placeable_bad_message_attr(self):
     val, errs = self.bundle.format_pattern(
         self.bundle.get_message('bad-message-attr-ref').value, {})
     self.assertEqual(val, 'Text {message.not-an-attr}')
     self.assertEqual(len(errs), 1)
     self.assertEqual(
         errs,
         [FluentReferenceError("Unknown attribute: message.not-an-attr")])
Example #6
0
 def test_ref_term_attribute_missing(self):
     val, errs = self.bundle.format_pattern(
         self.bundle.get_message('ref-term-attr-missing').value)
     self.assertEqual(val, "Other")
     self.assertEqual(len(errs), 1)
     self.assertEqual(
         errs,
         [FluentReferenceError('Unknown attribute: -my-term.missing')])
 def test_with_a_missing_selector(self):
     self.ctx.add_messages(
         dedent_ftl("""
         foo = { $none ->
             [a] A
            *[b] B
          }
     """))
     val, errs = self.ctx.format('foo', {})
     self.assertEqual(val, "B")
     self.assertEqual(errs,
                      [FluentReferenceError("Unknown external: none")])
Example #8
0
 def test_with_a_missing_selector(self):
     self.bundle.add_resource(
         FluentResource(
             dedent_ftl("""
         foo = { $none ->
             [a] A
            *[b] B
          }
     """)))
     val, errs = self.bundle.format_pattern(
         self.bundle.get_message('foo').value, {})
     self.assertEqual(val, "B")
     self.assertEqual(errs,
                      [FluentReferenceError("Unknown external: none")])
Example #9
0
 def test_from_arg_missing(self):
     val, errs = self.ctx.format('from-arg', {})
     self.assertEqual(val, "arg")
     self.assertEqual(len(errs), 1)
     self.assertEqual(errs, [FluentReferenceError('Unknown external: arg')])
 def test_placeable_bad_term(self):
     val, errs = self.ctx.format('bad-term-ref', {})
     self.assertEqual(val, 'Text -not-a-term')
     self.assertEqual(len(errs), 1)
     self.assertEqual(errs,
                      [FluentReferenceError("Unknown term: -not-a-term")])
Example #11
0
 def test_choose_missing_variant(self):
     val, errs = self.ctx.format('qux', {})
     self.assertEqual(val, 'B')
     self.assertEqual(len(errs), 1)
     self.assertEqual(errs, [FluentReferenceError("Unknown variant: c")])
 def test_placeable_bad_message(self):
     val, errs = self.ctx.format('bad-message-ref', {})
     self.assertEqual(val, 'Text not-a-message')
     self.assertEqual(len(errs), 1)
     self.assertEqual(
         errs, [FluentReferenceError("Unknown message: not-a-message")])
 def test_msg_with_string_value_and_no_attributes(self):
     val, errs = self.bundle.format_pattern(
         self.bundle.get_message('ref-foo').value, {})
     self.assertEqual(val, '{foo.missing}')
     self.assertEqual(
         errs, [FluentReferenceError('Unknown attribute: foo.missing')])
Example #14
0
 def test_from_arg_missing(self):
     val, errs = self.bundle.format_pattern(
         self.bundle.get_message('from-arg').value, {})
     self.assertEqual(val, "arg")
     self.assertEqual(len(errs), 1)
     self.assertEqual(errs, [FluentReferenceError('Unknown external: arg')])
 def test_falls_back_for_msg_with_pattern_value_and_other_attributes(self):
     val, errs = self.ctx.format('ref-qux', {})
     self.assertEqual(val, 'Foo Qux')
     self.assertEqual(errs,
                      [FluentReferenceError(
                          'Unknown attribute: qux.missing')])
 def test_bad_term(self):
     val, errs = self.bundle.format_pattern(
         self.bundle.get_message('bad-term').value, {})
     self.assertEqual(val, '{-missing}')
     self.assertEqual(errs,
                      [FluentReferenceError('Unknown term: -missing')])
Example #17
0
 def test_falls_back_to_name_of_function(self):
     val, errs = self.bundle.format_pattern(
         self.bundle.get_message('missing').value, {})
     self.assertEqual(val, "MISSING()")
     self.assertEqual(errs,
                      [FluentReferenceError("Unknown function: MISSING")])
 def test_with_a_missing_selector(self):
     val, errs = self.ctx.format('baz', {})
     self.assertEqual(val, "A")
     self.assertEqual(errs, [FluentReferenceError("Unknown external: num")])
 def test_msg_with_pattern_value_and_other_attributes(self):
     val, errs = self.bundle.format_pattern(
         self.bundle.get_message('ref-qux').value, {})
     self.assertEqual(val, '{qux.missing}')
     self.assertEqual(
         errs, [FluentReferenceError('Unknown attribute: qux.missing')])
 def test_missing_message_and_attribute(self):
     val, errs = self.bundle.format_pattern(
         self.bundle.get_message('ref-double-missing').value, {})
     self.assertEqual(val, '{missing.attr}')
     self.assertEqual(
         errs, [FluentReferenceError('Unknown attribute: missing.attr')])
 def test_falls_back_for_msg_with_string_value_and_other_attributes(self):
     val, errs = self.ctx.format('ref-bar', {})
     self.assertEqual(val, 'Bar')
     self.assertEqual(errs,
                      [FluentReferenceError(
                          'Unknown attribute: bar.missing')])
 def test_missing_attr(self):
     # We should fall back to the parent, and still pass the args.
     val, errs = self.ctx.format('missing-attr-ref', {})
     self.assertEqual(val, 'ABC option')
     self.assertEqual(
         errs, [FluentReferenceError('Unknown attribute: -other.missing')])
 def test_missing_message_and_attribute(self):
     val, errs = self.ctx.format('ref-double-missing', {})
     self.assertEqual(val, 'missing.attr')
     self.assertEqual(errs, [FluentReferenceError('Unknown attribute: missing.attr')])
 def test_bad_term(self):
     val, errs = self.ctx.format('bad-term', {})
     self.assertEqual(val, '-missing')
     self.assertEqual(errs,
                      [FluentReferenceError('Unknown term: -missing')])
Example #25
0
 def test_falls_back_to_name_of_function(self):
     val, errs = self.ctx.format("missing", {})
     self.assertEqual(val, "MISSING()")
     self.assertEqual(errs,
                      [FluentReferenceError("Unknown function: MISSING")])
Example #26
0
 def test_with_a_missing_selector(self):
     val, errs = self.bundle.format_pattern(
         self.bundle.get_message('qux').value, {})
     self.assertEqual(val, "B")
     self.assertEqual(errs, [FluentReferenceError("Unknown external: num")])