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

Unified Diff: grit/format/c_format_unittest.py

Issue 9924009: Add c_format as a format option. (Closed) Base URL: https://grit-i18n.googlecode.com/svn/trunk
Patch Set: Created 8 years, 9 months 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 | « grit/format/c_format.py ('k') | grit/format/rc.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: grit/format/c_format_unittest.py
diff --git a/grit/format/c_format_unittest.py b/grit/format/c_format_unittest.py
new file mode 100644
index 0000000000000000000000000000000000000000..21d7b1c267d05fa3e32bc0bba03aba753c439ab7
--- /dev/null
+++ b/grit/format/c_format_unittest.py
@@ -0,0 +1,75 @@
+#!/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 c_format.py.
+"""
+
+import unittest
+import StringIO
+
+from grit import grd_reader
+from grit import util
+from grit.tool import build
+
+
+class CFormatUnittest(unittest.TestCase):
+
+ def testMessages(self):
+ root = grd_reader.Parse(StringIO.StringIO("""
+ <messages>
+ <message name="IDS_QUESTIONS">Do you want to play questions?</message>
+ <message name="IDS_QUOTES">
+ "What's in a name, <ph name="NAME">%s<ex>Brandon</ex></ph>?"
+ </message>
+ <message name="IDS_LINE_BREAKS">
+ Was that rhetoric?
+No.
+Statement. Two all. Game point.
+</message>
+ <message name="IDS_NON_ASCII">
+ \xc3\xb5\\xc2\\xa4\\\xc2\xa4\\\\xc3\\xb5\xe4\xa4\xa4
+ </message>
+ </messages>
+ """), flexible_root=True)
+ util.FixRootForUnittest(root)
+
+ buf = StringIO.StringIO()
+ build.RcBuilder.ProcessNode(root, DummyOutput('c_format', 'en'), buf)
+ output = buf.getvalue()
+ test = u"""
+const char* GetString(int id) {
+ switch (id) {
+ case IDS_QUESTIONS:
+ return "Do you want to play questions?";
+ case IDS_QUOTES:
+ return "\\"What\\'s in a name, %s?\\"";
+ case IDS_LINE_BREAKS:
+ return "Was that rhetoric?\\nNo.\\nStatement. Two all. Game point.";
+ case IDS_NON_ASCII:
+ return "\\303\\265\\xc2\\xa4\\\\302\\244\\\\xc3\\xb5\\344\\244\\244";
+ default:
+ return 0;
+ }
+}"""
+ self.failUnless(output.strip() == test.strip())
+
+
+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 | « grit/format/c_format.py ('k') | grit/format/rc.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698