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

Side by Side Diff: grit/format/js_map_format_unittest.py

Issue 7994004: Initial source commit to grit-i18n project. (Closed) Base URL: http://grit-i18n.googlecode.com/svn/trunk/
Patch Set: Created 9 years, 2 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « grit/format/js_map_format.py ('k') | grit/format/policy_templates/PRESUBMIT.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 #!/usr/bin/python2.4
2 #
3 # Copyright (c) 2009 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
6
7 """Unittest for js_map_format.py.
8 """
9
10 import os
11 import re
12 import sys
13 if __name__ == '__main__':
14 sys.path.append(os.path.join(os.path.dirname(sys.argv[0]), '../..'))
15
16 import unittest
17 import StringIO
18
19 from grit import grd_reader
20 from grit import util
21 from grit.tool import build
22
23
24 class JsMapFormatUnittest(unittest.TestCase):
25
26 def testMessages(self):
27 grd_text = u"""
28 <messages>
29 <message name="IDS_SIMPLE_MESSAGE">
30 Simple message.
31 </message>
32 <message name="IDS_QUOTES">
33 element\u2019s \u201c<ph name="NAME">%s<ex>name</ex></ph>\u201d at tribute
34 </message>
35 <message name="IDS_PLACEHOLDERS">
36 <ph name="ERROR_COUNT">%1$d<ex>1</ex></ph> error, <ph name="WARNIN G_COUNT">%2$d<ex>1</ex></ph> warning
37 </message>
38 <message name="IDS_STARTS_WITH_SPACE">
39 ''' (<ph name="COUNT">%d<ex>2</ex></ph>)
40 </message>
41 <message name="IDS_DOUBLE_QUOTES">
42 A "double quoted" message.
43 </message>
44 </messages>
45 """
46 root = grd_reader.Parse(StringIO.StringIO(grd_text.encode('utf-8')),
47 flexible_root=True)
48 util.FixRootForUnittest(root)
49
50 buf = StringIO.StringIO()
51 build.RcBuilder.ProcessNode(root, DummyOutput('js_map_format', 'en'), buf)
52 output = buf.getvalue()
53 test = u"""
54 localizedStrings["Simple message."] = "Simple message.";
55 localizedStrings["element\u2019s \u201c%s\u201d attribute"] = "element\u2019s \u 201c%s\u201d attribute";
56 localizedStrings["%d error, %d warning"] = "%1$d error, %2$d warning";
57 localizedStrings[" (%d)"] = " (%d)";
58 localizedStrings["A \\\"double quoted\\\" message."] = "A \\\"double quoted\\\" message.";
59 """
60 self.failUnless(output.strip() == test.strip())
61
62 def testTranslations(self):
63 root = grd_reader.Parse(StringIO.StringIO("""
64 <messages>
65 <message name="ID_HELLO">Hello!</message>
66 <message name="ID_HELLO_USER">Hello <ph name="USERNAME">%s<ex>
67 Joi</ex></ph></message>
68 </messages>
69 """), flexible_root=True)
70 util.FixRootForUnittest(root)
71
72 buf = StringIO.StringIO()
73 build.RcBuilder.ProcessNode(root, DummyOutput('js_map_format', 'fr'), buf)
74 output = buf.getvalue()
75 test = u"""
76 localizedStrings["Hello!"] = "H\xe9P\xe9ll\xf4P\xf4!";
77 localizedStrings["Hello %s"] = "H\xe9P\xe9ll\xf4P\xf4 %s";
78 """
79 self.failUnless(output.strip() == test.strip())
80
81
82 class DummyOutput(object):
83
84 def __init__(self, type, language):
85 self.type = type
86 self.language = language
87
88 def GetType(self):
89 return self.type
90
91 def GetLanguage(self):
92 return self.language
93
94 def GetOutputFilename(self):
95 return 'hello.gif'
96
97 if __name__ == '__main__':
98 unittest.main()
OLDNEW
« no previous file with comments | « grit/format/js_map_format.py ('k') | grit/format/policy_templates/PRESUBMIT.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698