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

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

Issue 18860003: Use JSONEncoder to escape JSON strings. (Closed) Base URL: https://grit-i18n.googlecode.com/svn/trunk
Patch Set: Created 7 years, 5 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/chrome_messages_json.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 chrome_messages_json.py. 6 """Unittest for chrome_messages_json.py.
7 """ 7 """
8 8
9 import os 9 import os
10 import sys 10 import sys
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 46
47 buf = StringIO.StringIO() 47 buf = StringIO.StringIO()
48 build.RcBuilder.ProcessNode(root, DummyOutput('chrome_messages_json', 'en'), buf) 48 build.RcBuilder.ProcessNode(root, DummyOutput('chrome_messages_json', 'en'), buf)
49 output = buf.getvalue() 49 output = buf.getvalue()
50 test = u""" 50 test = u"""
51 { 51 {
52 "IDS_SIMPLE_MESSAGE": { 52 "IDS_SIMPLE_MESSAGE": {
53 "message": "Simple message." 53 "message": "Simple message."
54 }, 54 },
55 "IDS_QUOTES": { 55 "IDS_QUOTES": {
56 "message": "element\u2019s \u201c%s\u201d attribute" 56 "message": "element\\u2019s \\u201c%s\\u201d attribute"
57 }, 57 },
58 "IDS_PLACEHOLDERS": { 58 "IDS_PLACEHOLDERS": {
59 "message": "%1$d error, %2$d warning" 59 "message": "%1$d error, %2$d warning"
60 }, 60 },
61 "IDS_STARTS_WITH_SPACE": { 61 "IDS_STARTS_WITH_SPACE": {
62 "message": "(%d)" 62 "message": "(%d)"
63 }, 63 },
64 "IDS_DOUBLE_QUOTES": { 64 "IDS_DOUBLE_QUOTES": {
65 "message": "A \\"double quoted\\" message." 65 "message": "A \\"double quoted\\" message."
66 }, 66 },
(...skipping 12 matching lines...) Expand all
79 Joi</ex></ph></message> 79 Joi</ex></ph></message>
80 </messages> 80 </messages>
81 """) 81 """)
82 82
83 buf = StringIO.StringIO() 83 buf = StringIO.StringIO()
84 build.RcBuilder.ProcessNode(root, DummyOutput('chrome_messages_json', 'fr'), buf) 84 build.RcBuilder.ProcessNode(root, DummyOutput('chrome_messages_json', 'fr'), buf)
85 output = buf.getvalue() 85 output = buf.getvalue()
86 test = u""" 86 test = u"""
87 { 87 {
88 "ID_HELLO": { 88 "ID_HELLO": {
89 "message": "H\xe9P\xe9ll\xf4P\xf4!" 89 "message": "H\\u00e9P\\u00e9ll\\u00f4P\\u00f4!"
90 }, 90 },
91 "ID_HELLO_USER": { 91 "ID_HELLO_USER": {
92 "message": "H\xe9P\xe9ll\xf4P\xf4 %s" 92 "message": "H\\u00e9P\\u00e9ll\\u00f4P\\u00f4 %s"
93 } 93 }
94 } 94 }
95 """ 95 """
96 self.assertEqual(test.strip(), output.strip()) 96 self.assertEqual(test.strip(), output.strip())
97 97
98 98
99 class DummyOutput(object): 99 class DummyOutput(object):
100 100
101 def __init__(self, type, language): 101 def __init__(self, type, language):
102 self.type = type 102 self.type = type
103 self.language = language 103 self.language = language
104 104
105 def GetType(self): 105 def GetType(self):
106 return self.type 106 return self.type
107 107
108 def GetLanguage(self): 108 def GetLanguage(self):
109 return self.language 109 return self.language
110 110
111 def GetOutputFilename(self): 111 def GetOutputFilename(self):
112 return 'hello.gif' 112 return 'hello.gif'
113 113
114 114
115 if __name__ == '__main__': 115 if __name__ == '__main__':
116 unittest.main() 116 unittest.main()
OLDNEW
« no previous file with comments | « grit/format/chrome_messages_json.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698