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

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

Issue 1258833004: Compile plural strings to android <plurals> elem (Closed) Base URL: https://chromium.googlesource.com/external/grit-i18n.git@master
Patch Set: Added a test Created 5 years, 4 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
« no previous file with comments | « grit/format/android_xml.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Unittest for android_xml.py.""" 6 """Unittest for android_xml.py."""
7 7
8 import os 8 import os
9 import StringIO 9 import StringIO
10 import sys 10 import sys
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 desc="A string that only applies if there's no sdcard"> 43 desc="A string that only applies if there's no sdcard">
44 Lasers will probably be helpful. 44 Lasers will probably be helpful.
45 </message> 45 </message>
46 <message name="IDS_PRODUCT_DEFAULT" desc="New style product tag" 46 <message name="IDS_PRODUCT_DEFAULT" desc="New style product tag"
47 formatter_data="android_java_product=default android_java_name=cus tom_name"> 47 formatter_data="android_java_product=default android_java_name=cus tom_name">
48 You have an SD card 48 You have an SD card
49 </message> 49 </message>
50 <message name="IDS_PLACEHOLDERS" desc="A string with placeholders"> 50 <message name="IDS_PLACEHOLDERS" desc="A string with placeholders">
51 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>. 51 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>.
52 </message> 52 </message>
53 <message name="IDS_PLURALS" desc="A string using the ICU plural format ">
54 {NUM_THINGS, plural,
55 =1 {Maybe I'll get one laser.}
56 other {Maybe I'll get # lasers.}}
57 </message>
53 </messages> 58 </messages>
54 """) 59 """)
55 60
56 buf = StringIO.StringIO() 61 buf = StringIO.StringIO()
57 build.RcBuilder.ProcessNode(root, DummyOutput('android', 'en'), buf) 62 build.RcBuilder.ProcessNode(root, DummyOutput('android', 'en'), buf)
58 output = buf.getvalue() 63 output = buf.getvalue()
59 expected = ur""" 64 expected = ur"""
60 <?xml version="1.0" encoding="utf-8"?> 65 <?xml version="1.0" encoding="utf-8"?>
61 <resources xmlns:android="http://schemas.android.com/apk/res/android"> 66 <resources xmlns:android="http://schemas.android.com/apk/res/android">
62 <string name="simple">"Martha"</string> 67 <string name="simple">"Martha"</string>
63 <string name="one_line">"sat and wondered"</string> 68 <string name="one_line">"sat and wondered"</string>
64 <string name="quotes">"out loud, \"Why don\'t I build a flying car?\""</string> 69 <string name="quotes">"out loud, \"Why don\'t I build a flying car?\""</string>
65 <string name="multiline">"She gathered 70 <string name="multiline">"She gathered
66 wood, charcoal, and 71 wood, charcoal, and
67 a sledge hammer."</string> 72 a sledge hammer."</string>
68 <string name="whitespace">" How old fashioned -- she thought. "</string> 73 <string name="whitespace">" How old fashioned -- she thought. "</string>
69 <string name="product_specific" product="nosdcard">"Lasers will probably be help ful."</string> 74 <string name="product_specific" product="nosdcard">"Lasers will probably be help ful."</string>
70 <string name="custom_name" product="default">"You have an SD card"</string> 75 <string name="custom_name" product="default">"You have an SD card"</string>
71 <string name="placeholders">"I\'ll buy a %d nm laser at %s."</string> 76 <string name="placeholders">"I\'ll buy a %d nm laser at %s."</string>
77 <plurals name="plurals">
78 <item quantity="one">"Maybe I\'ll get one laser."</item>
79 <item quantity="other">"Maybe I\'ll get %d lasers."</item>
80 </plurals>
72 </resources> 81 </resources>
73 """ 82 """
74 self.assertEqual(output.strip(), expected.strip()) 83 self.assertEqual(output.strip(), expected.strip(), msg=output.strip() + '\n' + expected.strip())
newt (away) 2015/08/04 18:15:11 why this custom msg? assertEqual() already prints
conleyo 2015/08/04 18:53:55 Sorry, debugging output. The standard string diff
conleyo 2015/08/04 22:56:14 Done.
75 84
76 def testTaggedOnly(self): 85 def testTaggedOnly(self):
77 root = util.ParseGrdForUnittest(ur""" 86 root = util.ParseGrdForUnittest(ur"""
78 <messages> 87 <messages>
79 <message name="IDS_HELLO" desc="" formatter_data="android_java"> 88 <message name="IDS_HELLO" desc="" formatter_data="android_java">
80 Hello 89 Hello
81 </message> 90 </message>
82 <message name="IDS_WORLD" desc=""> 91 <message name="IDS_WORLD" desc="">
83 world 92 world
84 </message> 93 </message>
(...skipping 17 matching lines...) Expand all
102 return self.type 111 return self.type
103 112
104 def GetLanguage(self): 113 def GetLanguage(self):
105 return self.language 114 return self.language
106 115
107 def GetOutputFilename(self): 116 def GetOutputFilename(self):
108 return 'hello.gif' 117 return 'hello.gif'
109 118
110 if __name__ == '__main__': 119 if __name__ == '__main__':
111 unittest.main() 120 unittest.main()
OLDNEW
« no previous file with comments | « grit/format/android_xml.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698