예제 #1
0
    def testSplitTextWithCurlies(self):
        self.assertBuildTree(
            '''{COUNT, plural,
  =0  {Open all in &incognito window}
  =1 {Open in &incognito window}
  other {Open all ({COUNT}) in &incognito window}}''',
            pl.Plural('{COUNT, plural,\n  ', [
                pl.PluralOption('=0  {',
                                [pl.RawText('Open all in &incognito window')]),
                pl.PluralOption('=1 {',
                                [pl.RawText('Open in &incognito window')]),
                pl.PluralOption('other {', [
                    pl.RawText('Open all ('),
                    pl.BasicVariable('{COUNT}'),
                    pl.RawText(') in &incognito window'),
                ]),
            ]))

        self.assertBuildTree(
            '''{ATTEMPTS_LEFT, plural,
  =1 {{0} attempt left}
  other {{0}<a>attempts</a> left}}''',
            pl.Plural('{ATTEMPTS_LEFT, plural,\n  ', [
                pl.PluralOption(
                    '=1 {',
                    [pl.BasicVariable('{0}'),
                     pl.RawText(' attempt left')]),
                pl.PluralOption('other {', [
                    pl.BasicVariable('{0}'),
                    pl.HtmlTag('<a>'),
                    pl.RawText('attempts'),
                    pl.HtmlTag('</a>'),
                    pl.RawText(' left')
                ])
            ]))
예제 #2
0
 def testSplitTextTags(self):
     self.assertBuildTree(
         'foo<a href="url">bar</a>baz',
         pl.NodeSequence([
             pl.RawText('foo'),
             pl.HtmlTag('<a href="url">'),
             pl.RawText('bar'),
             pl.HtmlTag('</a>'),
             pl.RawText('baz'),
         ]))
예제 #3
0
 def testSplitTextVariables(self):
     self.assertBuildTree(
         'Downloaded by <a href="{PLACEHOLDER}">{PLACEHOLDER}</a>${foo}{bar}',
         pl.NodeSequence([
             pl.RawText('Downloaded by '),
             pl.HtmlTag('<a href="{PLACEHOLDER}">'),
             pl.BasicVariable('{PLACEHOLDER}'),
             pl.HtmlTag('</a>'),
             pl.BasicVariable('${foo}'),
             pl.BasicVariable('{bar}'),
         ]))
예제 #4
0
 def testToString(self):
     self.assertEqual(pl.RawText('Hello world').ToString(), 'Hello world')
     self.assertEqual(pl.BasicVariable('{0}').ToString(), '{0}')
     self.assertEqual(pl.HtmlTag('<a>').ToString(), '<a>')
     self.assertEqual(
         pl.NodeSequence([pl.RawText('Hello'),
                          pl.RawText('World')]).ToString(), 'HelloWorld')
     self.assertEqual(
         pl.Plural('{ATTEMPTS_LEFT, plural,\n  ', [
             pl.PluralOption('=1 {', [pl.RawText('hello')]),
             pl.PluralOption('other {', [pl.RawText('world')])
         ]).ToString(),
         '{ATTEMPTS_LEFT, plural,\n  =1 {hello}\nother {world}\n}')
예제 #5
0
 def testTransform(self):
     self.assertTransformsInto(pl.RawText('HI WORLD'),
                               pl.RawText('Hi World'))
     self.assertTransformsInto(pl.BasicVariable('{HELLO}'),
                               pl.BasicVariable('{HELLO}'))
     self.assertTransformsInto(pl.HtmlTag('<a>'), pl.HtmlTag('<a>'))
     self.assertTransformsInto(
         pl.NodeSequence(
             [pl.RawText('HELLO'),
              pl.HtmlTag('<a>'),
              pl.RawText('WORLD')]),
         pl.NodeSequence(
             [pl.RawText('Hello'),
              pl.HtmlTag('<a>'),
              pl.RawText('World')]))
     self.assertTransformsInto(
         pl.Plural('{ATTEMPTS_LEFT, plural,\n  ', [
             pl.PluralOption('=1 {', [pl.RawText('hello')]),
             pl.PluralOption('other {', [pl.RawText('world')])
         ]),
         pl.Plural('{ATTEMPTS_LEFT, plural,\n  ', [
             pl.PluralOption('=1 {', [pl.RawText('Hello')]),
             pl.PluralOption('other {', [pl.RawText('World')])
         ]))
예제 #6
0
    def testTreeNumWords(self):
        self.assertEqual(pl.HtmlTag('<a href="blah">').GetNumWords(), 0)
        self.assertEqual(pl.BasicVariable('{COUNT}').GetNumWords(), 1)

        self.assertEqual(
            pl.NodeSequence([pl.RawText('hi'),
                             pl.RawText('World')]).GetNumWords(), 2)
        self.assertEqual(
            pl.PluralOption(
                'other {',
                [pl.RawText('hello'), pl.RawText('World')]).GetNumWords(), 2)
        self.assertEqual(
            pl.Plural('{COUNT, plural, {', [
                pl.PluralOption('=0 {', [pl.RawText('1 2')]),
                pl.PluralOption('=0 {', [pl.RawText('1 2 3')]),
                pl.PluralOption('=0 {', [pl.RawText('1 2 3 4 5 6 7 8 9 10')]),
            ]).GetNumWords(), 10)