Ejemplo n.º 1
0
    def setUp(self):
        self.bundle = FluentBundle.from_string('en-US',
                                               dedent_ftl("""
            -brand = Cool Thing
                .status = { $version ->
                    [v2]     available
                   *[v1]     deprecated
                }

            attr-with-arg = { -brand } is { -brand.status(version: "v2") ->
                 [available]   available, yay!
                *[deprecated]  deprecated, sorry
            }

            -other = { $arg ->
                        [a]  ABC
                       *[d]  DEF
                     }

            missing-attr-ref = { -other.missing(arg: "a") ->
                 [ABC]  ABC option
                *[DEF]  DEF option
            }
        """),
                                               use_isolating=False)
Ejemplo n.º 2
0
    def setUp(self):
        self.bundle = FluentBundle.from_string('en-US', dedent_ftl("""
            message = Message
                    .attr = Message Attribute
            -term = Term
                  .attr = Term Attribute
            -term2 = {
               *[variant1] Term Variant 1
                [variant2] Term Variant 2
             }

            uses-message = { message }
            uses-message-attr = { message.attr }
            uses-term = { -term }

            bad-message-ref = Text { not-a-message }
            bad-message-attr-ref = Text { message.not-an-attr }
            bad-term-ref = Text { -not-a-term }

            self-referencing-message = Text { self-referencing-message }
            cyclic-msg1 = Text1 { cyclic-msg2 }
            cyclic-msg2 = Text2 { cyclic-msg1 }
            self-cyclic-message = Parent { self-cyclic-message.attr }
                                .attr = Attribute { self-cyclic-message }

            self-attribute-ref-ok = Parent { self-attribute-ref-ok.attr }
                                  .attr = Attribute
            self-parent-ref-ok = Parent
                               .attr =  Attribute { self-parent-ref-ok }
            -cyclic-term = { -cyclic-term }
            cyclic-term-message = { -cyclic-term }
        """), use_isolating=False)
Ejemplo n.º 3
0
    def test_format_args(self):
        bundle = FluentBundle.from_string('en-US', 'foo = Foo')
        val, errs = bundle.format('foo')
        self.assertEqual(val, 'Foo')

        val, errs = bundle.format('foo', {})
        self.assertEqual(val, 'Foo')
Ejemplo n.º 4
0
 def test_format_term(self):
     bundle = FluentBundle.from_string(
         'en-US', dedent_ftl("""
         -foo = Foo
     """))
     self.assertRaises(LookupError, bundle.format, '-foo')
     self.assertRaises(LookupError, bundle.format, 'foo')
Ejemplo n.º 5
0
    def test_has_message_for_term(self):
        bundle = FluentBundle.from_string(
            'en-US', dedent_ftl("""
            -foo = Foo
        """))

        self.assertFalse(bundle.has_message('-foo'))
Ejemplo n.º 6
0
 def setUp(self):
     self.bundle = FluentBundle.from_string('en-US',
                                            dedent_ftl("""
         msg = Msg is {$arg}
         -foo = {msg}
         ref-foo = {-foo(arg: 1)}
     """),
                                            use_isolating=False)
Ejemplo n.º 7
0
 def setUp(self):
     self.bundle = FluentBundle.from_string('en-US',
                                            dedent_ftl("""
         implicit-call    = { $date }
         explicit-call    = { DATETIME($date) }
         call-with-arg    = { DATETIME($date, dateStyle: "long") }
     """),
                                            use_isolating=False)
Ejemplo n.º 8
0
 def setUp(self):
     self.bundle = FluentBundle.from_string(
         'en-US',
         dedent_ftl("""
         -brand-short-name = Amaya
         foo = { -brand-short-name }
         with-arg = { $arg }
     """))
Ejemplo n.º 9
0
 def test_check_messages_duplicate(self):
     bundle = FluentBundle.from_string('en-US', "foo = Foo\n" "foo = Bar\n")
     checks = bundle.check_messages()
     self.assertEqual(checks,
                      [('foo',
                        FluentDuplicateMessageId(
                            "Additional definition for 'foo' discarded."))])
     # Earlier takes precedence
     self.assertEqual(bundle.format('foo')[0], 'Foo')
Ejemplo n.º 10
0
 def setUp(self):
     self.bundle = FluentBundle.from_string(
         'en-US',
         dedent_ftl("""
         foo = Foo
         bar = { foo } Bar
         baz = { $arg } Baz
         qux = { bar } { baz }
     """))
Ejemplo n.º 11
0
 def test_message_and_term_separate(self):
     bundle = FluentBundle.from_string(
         'en-US',
         dedent_ftl("""
         foo = Refers to { -foo }
         -foo = Foo
     """))
     val, errs = bundle.format('foo', {})
     self.assertEqual(val, 'Refers to \u2068Foo\u2069')
     self.assertEqual(errs, [])
Ejemplo n.º 12
0
    def test_has_message(self):
        bundle = FluentBundle.from_string(
            'en-US',
            dedent_ftl("""
            foo = Foo
            -term = Term
        """))

        self.assertTrue(bundle.has_message('foo'))
        self.assertFalse(bundle.has_message('bar'))
Ejemplo n.º 13
0
 def setUp(self):
     self.bundle = FluentBundle.from_string('en-US',
                                            dedent_ftl("""
         -foo = {$a} {$b}
         -bar = {-foo(b: 2)}
         -baz = {-foo}
         ref-bar = {-bar(a: 1)}
         ref-baz = {-baz(a: 1)}
     """),
                                            use_isolating=False)
Ejemplo n.º 14
0
    def test_has_message_with_attribute(self):
        bundle = FluentBundle.from_string(
            'en-US',
            dedent_ftl("""
            foo = Foo
                .attr = Foo Attribute
        """))

        self.assertTrue(bundle.has_message('foo'))
        self.assertFalse(bundle.has_message('foo.attr'))
        self.assertFalse(bundle.has_message('foo.other-attribute'))
Ejemplo n.º 15
0
 def test_with_argument_expression(self):
     bundle = FluentBundle.from_string(
         'en-US',
         dedent_ftl("""
         foo = { $arg ->
             [a] A
            *[b] B
          }
     """))
     val, errs = bundle.format('foo', {'arg': 'a'})
     self.assertEqual(val, "A")
Ejemplo n.º 16
0
 def setUp(self):
     self.bundle = FluentBundle.from_string('en-US',
                                            dedent_ftl("""
         foo = Foo
             .attr = Foo Attribute
         bar = { foo } Bar
             .attr = Bar Attribute
         ref-foo = { foo.attr }
         ref-bar = { bar.attr }
     """),
                                            use_isolating=True)
Ejemplo n.º 17
0
 def setUp(self):
     self.bundle = FluentBundle.from_string('en-US',
                                            dedent_ftl("""
         one           =  { 1 }
         one_point_two =  { 1.2 }
         select        =  { 1 ->
            *[0] Zero
             [1] One
          }
     """),
                                            use_isolating=False)
Ejemplo n.º 18
0
 def setUp(self):
     self.bundle = FluentBundle.from_string('en-US',
                                            dedent_ftl("""
         foo = Foo { $num }
         bar = { foo }
         baz =
             .attr = Baz Attribute { $num }
         qux = { "a" ->
            *[a]     Baz Variant A { $num }
          }
     """),
                                            use_isolating=False)
Ejemplo n.º 19
0
 def test_with_a_non_matching_selector(self):
     bundle = FluentBundle.from_string(
         'en-US',
         dedent_ftl("""
         foo = { "c" ->
             [a] A
            *[b] B
          }
     """))
     val, errs = bundle.format('foo', {})
     self.assertEqual(val, "B")
     self.assertEqual(errs, [])
Ejemplo n.º 20
0
 def setUp(self):
     self.bundle = FluentBundle.from_string('en-US',
                                            dedent_ftl("""
         -thing = { $count ->
               *[1] one thing
                [2] two things
         }
         thing-no-arg = { -thing }
         thing-no-arg-alt = { -thing() }
         thing-one = { -thing(count: 1) }
         thing-two = { -thing(count: 2) }
     """),
                                            use_isolating=False)
Ejemplo n.º 21
0
 def test_with_a_missing_selector(self):
     bundle = FluentBundle.from_string(
         'en-US',
         dedent_ftl("""
         foo = { $none ->
             [a] A
            *[b] B
          }
     """))
     val, errs = bundle.format('foo', {})
     self.assertEqual(val, "B")
     self.assertEqual(
         errs,
         [FluentReferenceError("<string>:2:9: Unknown external: none")])
Ejemplo n.º 22
0
 def setUp(self):
     self.bundle = FluentBundle.from_string('en-US',
                                            dedent_ftl("""
         implicit-call    = { 123456 }
         implicit-call2   = { $arg }
         defaults         = { NUMBER(123456) }
         percent-style    = { NUMBER(1.234, style: "percent") }
         from-arg         = { NUMBER($arg) }
         merge-params     = { NUMBER($arg, useGrouping: 0) }
         bad-kwarg        = { NUMBER(1, badkwarg: 0) }
         bad-arity        = { NUMBER(1, 2) }
         currency-name    = { NUMBER($arg, currencyDisplay: "name") }
     """),
                                            use_isolating=False)
Ejemplo n.º 23
0
    def test_external_arguments_in_variants(self):
        # We are testing several things:
        # - that [b] variant doesn't trigger 'Unknown external: arg'
        # - some logic in compiler implementation regarding when variables are looked up,
        #   so that [a] and [c] variants both can find 'arg'.
        bundle = FluentBundle.from_string(
            'en-US',
            dedent_ftl("""
            foo = { $lookup ->
                 [a]    { $arg }
                 [b]    B
                *[c]    { $arg }
             }
        """))
        # No args:
        val1, errs1 = bundle.format('foo', {})
        self.assertEqual(val1, "arg")
        self.assertEqual(errs1, [
            FluentReferenceError("<string>:2:9: Unknown external: lookup"),
            FluentReferenceError("<string>:5:15: Unknown external: arg"),
        ])

        # [a] branch, arg supplied
        val2, errs2 = bundle.format('foo', {'lookup': 'a', 'arg': 'A'})
        self.assertEqual(val2, "A")
        self.assertEqual(errs2, [])

        # [a] branch, arg not supplied
        val3, errs3 = bundle.format('foo', {'lookup': 'a'})
        self.assertEqual(val3, "arg")
        self.assertEqual(
            errs3,
            [FluentReferenceError("<string>:3:15: Unknown external: arg")])

        # [b] branch
        val4, errs4 = bundle.format('foo', {'lookup': 'b'})
        self.assertEqual(val4, "B")
        self.assertEqual(errs4, [])

        # [c] branch, arg supplied
        val5, errs5 = bundle.format('foo', {'lookup': 'c', 'arg': 'C'})
        self.assertEqual(val5, "C")
        self.assertEqual(errs5, [])

        # [c] branch, arg not supplied
        val6, errs6 = bundle.format('foo', {'lookup': 'c'})
        self.assertEqual(val6, "arg")
        self.assertEqual(
            errs6,
            [FluentReferenceError("<string>:5:15: Unknown external: arg")])
Ejemplo n.º 24
0
 def setUp(self):
     self.bundle = FluentBundle.from_string('en-US',
                                            dedent_ftl("""
         foo = Foo
         bar = Bar
             .attr = { foo } Attribute
         baz = { foo } Baz
             .attr = { foo } Attribute
         qux = Qux
             .attr = { qux } Attribute
         ref-bar = { bar.attr }
         ref-baz = { baz.attr }
         ref-qux = { qux.attr }
     """),
                                            use_isolating=False)
Ejemplo n.º 25
0
    def setUp(self):
        self.args_passed = []

        def number_processor(number):
            self.args_passed.append(number)
            return number

        self.bundle = FluentBundle.from_string(
            'en-US',
            dedent_ftl("""
            pass-number = { NUMBER_PROCESSOR(1) }
            pass-arg = { NUMBER_PROCESSOR($arg) }
        """),
            use_isolating=False,
            functions={'NUMBER_PROCESSOR': number_processor},
        )
Ejemplo n.º 26
0
 def setUp(self):
     self.bundle = FluentBundle.from_string('en-US',
                                            dedent_ftl("""
         -thing = { $article ->
               *[definite] the thing
                [indefinite] a thing
                [none] thing
         }
         thing-no-arg = { -thing }
         thing-no-arg-alt = { -thing() }
         thing-with-arg = { -thing(article: "indefinite") }
         thing-positional-arg = { -thing("foo") }
         thing-fallback = { -thing(article: "somethingelse") }
         bad-term = { -missing() }
     """),
                                            use_isolating=False)
Ejemplo n.º 27
0
 def setUp(self):
     self.bundle = FluentBundle.from_string('en-US',
                                            dedent_ftl("""
         foo = Foo
         bar = Bar
             .attr = Bar Attribute
         baz = { foo } Baz
         qux = { foo } Qux
             .attr = Qux Attribute
         ref-foo = { foo.missing }
         ref-bar = { bar.missing }
         ref-baz = { baz.missing }
         ref-qux = { qux.missing }
         attr-only =
                  .attr  = Attr Only Attribute
         ref-double-missing = { missing.attr }
     """),
                                            use_isolating=False)
Ejemplo n.º 28
0
    def setUp(self):
        self.args_passed = []

        def my_function(arg, kwarg1=None, kwarg2="default"):
            self.args_passed.append((arg, kwarg1, kwarg2))
            return arg

        self.bundle = FluentBundle.from_string(
            'en-US',
            dedent_ftl("""
            pass-arg        = { MYFUNC("a") }
            pass-kwarg1     = { MYFUNC("a", kwarg1: 1) }
            pass-kwarg2     = { MYFUNC("a", kwarg2: "other") }
            pass-kwargs     = { MYFUNC("a", kwarg1: 1, kwarg2: "other") }
            pass-user-arg   = { MYFUNC($arg) }
        """),
            use_isolating=False,
            functions={'MYFUNC': my_function},
        )
Ejemplo n.º 29
0
    def setUp(self):
        self.bundle = FluentBundle.from_string('en-US',
                                               dedent_ftl("""
            -thing = { $article ->
                  *[definite]    the { -other }
                   [indefinite]  a { -other }
                 }

            -other = thing

            thing-with-arg = { -thing(article: "indefinite") }
            thing-fallback = { -thing(article: "somethingelse") }

            -bad-term = { $article ->
                 *[all]   Something wrong { -missing }
             }

            uses-bad-term = { -bad-term }
        """),
                                               use_isolating=False)
Ejemplo n.º 30
0
    def setUp(self):
        self.bundle = FluentBundle.from_string('en-US',
                                               dedent_ftl("""
            -thing = { $article ->
                *[definite] { $first-letter ->
                    *[lower] the thing
                     [upper] The thing
                 }
                 [indefinite] { $first-letter ->
                    *[lower] a thing
                     [upper] A thing
                 }
             }

            both-args = { -thing(first-letter: "upper", article: "indefinite") }.
            outer-arg = This is { -thing(article: "indefinite") }.
            inner-arg = { -thing(first-letter: "upper") }.
            neither-arg = { -thing() }.
        """),
                                               use_isolating=False)