def test_concat_two(self): msg = FTL.Entity( FTL.Identifier('hello'), value=CONCAT( LITERAL_FROM(self.strings, 'hello.start'), LITERAL_FROM(self.strings, 'hello.end'), ) ) result = evaluate(self, msg) self.assertEqual( len(result.value.elements), 1, 'The constructed value should have only one element' ) self.assertIsInstance( result.value.elements[0], FTL.TextElement, 'The constructed element should be a TextElement.' ) self.assertEqual( result.value.elements[0].value, 'Hello, world!', 'The TextElement should be a concatenation of the sources.' ) self.assertEqual( result.toJSON(), ftl_message_to_json(''' hello = Hello, world! ''') )
def test_plural_too_many_variants(self): self.plural_categories = ('one',) self.assertEqual( evaluate(self, self.message).toJSON(), ftl_message_to_json(''' delete-all = { $num -> *[one] Delete this download? } ''') )
def test_plural(self): self.assertEqual( evaluate(self, self.message).toJSON(), ftl_message_to_json(''' delete-all = { $num -> [one] Delete this download? *[other] Delete all downloads? } ''') )
def test_plural_too_few_variants(self): self.plural_categories = ('one', 'few', 'many', 'other') self.assertEqual( evaluate(self, self.message).toJSON(), ftl_message_to_json(''' delete-all = { $num -> [one] Delete this download? *[few] Delete all downloads? } ''') )
def test_copy_html_entity(self): msg = FTL.Entity( FTL.Identifier('foo-html-entity'), value=LITERAL_FROM(self.strings, 'foo.html.entity') ) self.assertEqual( evaluate(self, msg).toJSON(), ftl_message_to_json(''' foo-html-entity = <⇧⌘K> ''') )
def test_copy_escape_unicode_end(self): msg = FTL.Entity( FTL.Identifier('foo-unicode-end'), value=LITERAL_FROM(self.strings, 'foo.unicode.end') ) self.assertEqual( evaluate(self, msg).toJSON(), ftl_message_to_json(''' foo-unicode-end = "Foo " ''') )
def test_copy(self): msg = FTL.Entity( FTL.Identifier('foo'), value=LITERAL_FROM(self.strings, 'foo') ) self.assertEqual( evaluate(self, msg).toJSON(), ftl_message_to_json(''' foo = Foo ''') )
def test_concat_one(self): msg = FTL.Entity( FTL.Identifier('hello'), value=CONCAT( LITERAL_FROM(self.strings, 'hello'), ) ) self.assertEqual( evaluate(self, msg).toJSON(), ftl_message_to_json(''' hello = Hello, world! ''') )
def test_concat_whitespace_end(self): msg = FTL.Entity( FTL.Identifier('hello'), value=CONCAT( LITERAL_FROM(self.strings, 'whitespace.end.start'), LITERAL_FROM(self.strings, 'whitespace.end.end'), ) ) self.assertEqual( evaluate(self, msg).toJSON(), ftl_message_to_json(''' hello = "Hello, world! " ''') )
def test_replace_last(self): msg = FTL.Entity( FTL.Identifier(u'last'), value=REPLACE_FROM( self.strings, 'last', {'#1': [FTL.ExternalArgument(u'bar')]} ) ) self.assertEqual( evaluate(self, msg).toJSON(), ftl_message_to_json(''' last = Foo { $bar } ''') )
def test_concat_replace(self): msg = FTL.Entity( FTL.Identifier('channel-desc'), value=CONCAT( LITERAL_FROM(self.strings, 'channel.description.start'), EXTERNAL('channelname'), LITERAL_FROM(self.strings, 'channel.description.end'), ) ) self.assertEqual( evaluate(self, msg).toJSON(), ftl_message_to_json(''' channel-desc = "You are on the { $channelname } channel. " ''') )
def test_replace_too_few(self): msg = FTL.Entity( FTL.Identifier(u'welcome'), value=REPLACE_FROM( self.strings, 'welcome', {'#1': [FTL.ExternalArgument(u'username')]} ) ) self.assertEqual( evaluate(self, msg).toJSON(), ftl_message_to_json(''' welcome = Welcome, { $username }, to #2! ''') )
def test_replace_one(self): msg = FTL.Entity( FTL.Identifier(u'hello'), value=REPLACE_FROM( self.strings, 'hello', {'#1': [FTL.ExternalArgument(u'username')]} ) ) self.assertEqual( evaluate(self, msg).toJSON(), ftl_message_to_json(''' hello = Hello, { $username }! ''') )
def test_concat_literal(self): msg = FTL.Entity( FTL.Identifier('update-failed'), value=CONCAT( LITERAL_FROM(self.strings, 'update.failed.start'), LITERAL('<a>'), LITERAL_FROM(self.strings, 'update.failed.linkText'), LITERAL('</a>'), LITERAL_FROM(self.strings, 'update.failed.end'), ) ) self.assertEqual( evaluate(self, msg).toJSON(), ftl_message_to_json(''' update-failed = Update failed. <a>Download manually</a>! ''') )
def test_concat_replace(self): msg = FTL.Entity( FTL.Identifier('community'), value=CONCAT( REPLACE_FROM( self.strings, 'community.start', { '&brandShortName;': [ FTL.ExternalArgument('brand-short-name') ] } ), LITERAL('<a>'), REPLACE_FROM( self.strings, 'community.mozillaLink', { '&vendorShortName;': [ FTL.ExternalArgument('vendor-short-name') ] } ), LITERAL('</a>'), LITERAL_FROM(self.strings, 'community.middle'), LITERAL('<a>'), LITERAL_FROM(self.strings, 'community.creditsLink'), LITERAL('</a>'), LITERAL_FROM(self.strings, 'community.end') ) ) self.assertEqual( evaluate(self, msg).toJSON(), ftl_message_to_json( 'community = { $brand-short-name } is designed by ' '<a>{ $vendor-short-name }</a>, a <a>global community</a> ' 'working together to…' ) )
def test_plural_replace(self): msg = FTL.Entity( FTL.Identifier('delete-all'), value=PLURALS_FROM( self.strings, 'deleteAll', FTL.ExternalArgument('num'), lambda var: REPLACE( var, {'#1': [FTL.ExternalArgument('num')]} ) ) ) self.assertEqual( evaluate(self, msg).toJSON(), ftl_message_to_json(''' delete-all = { $num -> [one] Delete this download? *[other] Delete { $num } downloads? } ''') )
def test_copy_accesskey(self): msg = FTL.Entity( FTL.Identifier('check-for-updates'), traits=[ FTL.Member( FTL.Keyword('label', 'xul'), LITERAL_FROM(self.strings, 'checkForUpdatesButton.label') ), FTL.Member( FTL.Keyword('accesskey', 'xul'), LITERAL_FROM(self.strings, 'checkForUpdatesButton.accesskey') ), ] ) self.assertEqual( evaluate(self, msg).toJSON(), ftl_message_to_json(''' check-for-updates = [xul/label] Check for updates [xul/accesskey] C ''') )