Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Unified Diff: tools/grit/grit/format/android_xml_unittest.py

Issue 1410853008: Move grit from DEPS into src. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: webview licenses Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/grit/grit/format/android_xml.py ('k') | tools/grit/grit/format/c_format.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/grit/grit/format/android_xml_unittest.py
diff --git a/tools/grit/grit/format/android_xml_unittest.py b/tools/grit/grit/format/android_xml_unittest.py
new file mode 100755
index 0000000000000000000000000000000000000000..cdec6c9013e93286a5b686014555a2b6354d8d8a
--- /dev/null
+++ b/tools/grit/grit/format/android_xml_unittest.py
@@ -0,0 +1,110 @@
+#!/usr/bin/env python
+# Copyright (c) 2012 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Unittest for android_xml.py."""
+
+import os
+import StringIO
+import sys
+import unittest
+
+if __name__ == '__main__':
+ sys.path.append(os.path.join(os.path.dirname(__file__), '../..'))
+
+from grit import util
+from grit.format import android_xml
+from grit.node import message
+from grit.tool import build
+
+
+class AndroidXmlUnittest(unittest.TestCase):
+
+ def testMessages(self):
+ root = util.ParseGrdForUnittest(ur"""
+ <messages>
+ <message name="IDS_SIMPLE" desc="A vanilla string">
+ Martha
+ </message>
+ <message name="IDS_ONE_LINE" desc="On one line">sat and wondered</message>
+ <message name="IDS_QUOTES" desc="A string with quotation marks">
+ out loud, "Why don't I build a flying car?"
+ </message>
+ <message name="IDS_MULTILINE" desc="A string split over several lines">
+ She gathered
+wood, charcoal, and
+a sledge hammer.
+ </message>
+ <message name="IDS_WHITESPACE" desc="A string with extra whitespace.">
+ ''' How old fashioned -- she thought. '''
+ </message>
+ <message name="IDS_PLACEHOLDERS" desc="A string with placeholders">
+ I'll buy a <ph name="WAVELENGTH">%d<ex>200</ex></ph> nm laser at <ph name="STORE_NAME">%s<ex>the grocery store</ex></ph>.
+ </message>
+ <message name="IDS_PLURALS" desc="A string using the ICU plural format">
+ {NUM_THINGS, plural,
+ =1 {Maybe I'll get one laser.}
+ other {Maybe I'll get # lasers.}}
+ </message>
+ </messages>
+ """)
+
+ buf = StringIO.StringIO()
+ build.RcBuilder.ProcessNode(root, DummyOutput('android', 'en'), buf)
+ output = buf.getvalue()
+ expected = ur"""
+<?xml version="1.0" encoding="utf-8"?>
+<resources xmlns:android="http://schemas.android.com/apk/res/android">
+<string name="simple">"Martha"</string>
+<string name="one_line">"sat and wondered"</string>
+<string name="quotes">"out loud, \"Why don\'t I build a flying car?\""</string>
+<string name="multiline">"She gathered
+wood, charcoal, and
+a sledge hammer."</string>
+<string name="whitespace">" How old fashioned -- she thought. "</string>
+<string name="placeholders">"I\'ll buy a %d nm laser at %s."</string>
+<plurals name="plurals">
+ <item quantity="one">"Maybe I\'ll get one laser."</item>
+ <item quantity="other">"Maybe I\'ll get %d lasers."</item>
+</plurals>
+</resources>
+"""
+ self.assertEqual(output.strip(), expected.strip())
+
+ def testTaggedOnly(self):
+ root = util.ParseGrdForUnittest(ur"""
+ <messages>
+ <message name="IDS_HELLO" desc="" formatter_data="android_java">
+ Hello
+ </message>
+ <message name="IDS_WORLD" desc="">
+ world
+ </message>
+ </messages>
+ """)
+
+ msg_hello, msg_world = root.GetChildrenOfType(message.MessageNode)
+ self.assertTrue(android_xml.ShouldOutputNode(msg_hello, tagged_only=True))
+ self.assertFalse(android_xml.ShouldOutputNode(msg_world, tagged_only=True))
+ self.assertTrue(android_xml.ShouldOutputNode(msg_hello, tagged_only=False))
+ self.assertTrue(android_xml.ShouldOutputNode(msg_world, tagged_only=False))
+
+
+class DummyOutput(object):
+
+ def __init__(self, type, language):
+ self.type = type
+ self.language = language
+
+ def GetType(self):
+ return self.type
+
+ def GetLanguage(self):
+ return self.language
+
+ def GetOutputFilename(self):
+ return 'hello.gif'
+
+if __name__ == '__main__':
+ unittest.main()
« no previous file with comments | « tools/grit/grit/format/android_xml.py ('k') | tools/grit/grit/format/c_format.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698