class TestAndroidFormatter(unittest.TestCase): def setUp(self): self.dictionary = Dictionary() self.dictionary.add_translation('hello', 'en', 'Hi') self.dictionary.add_translation('welcome', 'en', 'Welcome') def _generate_result(self, elements=()): result = "<resources>" for element in elements: result += '<string name="%s">%s</string>' % element result += "</resources>" return result def test_template(self): formatter = DictionaryToAndroid(dictionary=self.dictionary, use_pretty_xml=False) formatted_string = formatter.format('en') dictionary_result = self._generate_result( (('hello', 'Hi'), ('welcome', 'Welcome'))) self.assertEqual(formatted_string, dictionary_result) def test_empty(self): self.dictionary.clear() formatter = DictionaryToAndroid(dictionary=self.dictionary, use_pretty_xml=False) result = formatter.format('en') expected_result = self._generate_result() self.assertEqual(result, expected_result)
class TestSwiftFormatter(unittest.TestCase): def setUp(self): self.dictionary = Dictionary() self.dictionary.add_translation('hello', 'en', 'Hi') self.dictionary.add_translation('welcome', 'en', 'Welcome') self.dictionary_result = '''"hello" = "Hi";\n"welcome" = "Welcome";\n''' def test_template(self): formatter = DictionaryToSwift(self.dictionary) formatted_string = formatter.format('en') self.assertEqual(formatted_string, self.dictionary_result) def test_empty(self): self.dictionary.clear() formatter = DictionaryToSwift(self.dictionary) formatted_string = formatter.format('en') self.assertTrue(len(formatted_string) == 0)