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

Unified Diff: tools/grit/grit/format/js_map_format_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/js_map_format.py ('k') | tools/grit/grit/format/policy_templates/PRESUBMIT.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/grit/grit/format/js_map_format_unittest.py
diff --git a/tools/grit/grit/format/js_map_format_unittest.py b/tools/grit/grit/format/js_map_format_unittest.py
new file mode 100755
index 0000000000000000000000000000000000000000..cac0b2e953a54d7de1edac41958cee8aeec9baab
--- /dev/null
+++ b/tools/grit/grit/format/js_map_format_unittest.py
@@ -0,0 +1,92 @@
+#!/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 js_map_format.py.
+"""
+
+import os
+import sys
+if __name__ == '__main__':
+ sys.path.append(os.path.join(os.path.dirname(__file__), '../..'))
+
+import unittest
+import StringIO
+
+from grit import util
+from grit.tool import build
+
+
+class JsMapFormatUnittest(unittest.TestCase):
+
+ def testMessages(self):
+ root = util.ParseGrdForUnittest(u"""
+ <messages>
+ <message name="IDS_SIMPLE_MESSAGE">
+ Simple message.
+ </message>
+ <message name="IDS_QUOTES">
+ element\u2019s \u201c<ph name="NAME">%s<ex>name</ex></ph>\u201d attribute
+ </message>
+ <message name="IDS_PLACEHOLDERS">
+ <ph name="ERROR_COUNT">%1$d<ex>1</ex></ph> error, <ph name="WARNING_COUNT">%2$d<ex>1</ex></ph> warning
+ </message>
+ <message name="IDS_STARTS_WITH_SPACE">
+ ''' (<ph name="COUNT">%d<ex>2</ex></ph>)
+ </message>
+ <message name="IDS_DOUBLE_QUOTES">
+ A "double quoted" message.
+ </message>
+ <message name="IDS_BACKSLASH">
+ \\
+ </message>
+ </messages>
+ """)
+
+ buf = StringIO.StringIO()
+ build.RcBuilder.ProcessNode(root, DummyOutput('js_map_format', 'en'), buf)
+ output = util.StripBlankLinesAndComments(buf.getvalue())
+ self.assertEqual(u"""\
+localizedStrings["Simple message."] = "Simple message.";
+localizedStrings["element\u2019s \u201c%s\u201d attribute"] = "element\u2019s \u201c%s\u201d attribute";
+localizedStrings["%d error, %d warning"] = "%1$d error, %2$d warning";
+localizedStrings[" (%d)"] = " (%d)";
+localizedStrings["A \\\"double quoted\\\" message."] = "A \\\"double quoted\\\" message.";
+localizedStrings["\\\\"] = "\\\\";""", output)
+
+ def testTranslations(self):
+ root = util.ParseGrdForUnittest("""
+ <messages>
+ <message name="ID_HELLO">Hello!</message>
+ <message name="ID_HELLO_USER">Hello <ph name="USERNAME">%s<ex>
+ Joi</ex></ph></message>
+ </messages>
+ """)
+
+ buf = StringIO.StringIO()
+ build.RcBuilder.ProcessNode(root, DummyOutput('js_map_format', 'fr'), buf)
+ output = util.StripBlankLinesAndComments(buf.getvalue())
+ self.assertEqual(u"""\
+localizedStrings["Hello!"] = "H\xe9P\xe9ll\xf4P\xf4!";
+localizedStrings["Hello %s"] = "H\xe9P\xe9ll\xf4P\xf4 %s";\
+""", output)
+
+
+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/js_map_format.py ('k') | tools/grit/grit/format/policy_templates/PRESUBMIT.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698