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

Side by Side Diff: grit/node/message_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, 3 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/node/message.py ('k') | grit/node/misc.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 # Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 '''Unit tests for grit.node.message'''
7
8
9 import os
10 import sys
11 if __name__ == '__main__':
12 sys.path.append(os.path.join(os.path.dirname(sys.argv[0]), '../..'))
13
14 import unittest
15 import StringIO
16
17 from grit.node import message
18 from grit import grd_reader
19 from grit import tclib
20
21 class MessageUnittest(unittest.TestCase):
22 def testMessage(self):
23 buf = StringIO.StringIO('''<message name="IDS_GREETING"
24 desc="Printed to greet the currently logged in user">
25 Hello <ph name="USERNAME">%s<ex>Joi</ex></ph>, how are you doing today?
26 </message>''')
27 res = grd_reader.Parse(buf, flexible_root = True)
28 cliques = res.GetCliques()
29 content = cliques[0].GetMessage().GetPresentableContent()
30 self.failUnless(content == 'Hello USERNAME, how are you doing today?')
31
32 def testMessageWithWhitespace(self):
33 buf = StringIO.StringIO('<message name="IDS_BLA" desc="">'
34 '\'\'\' Hello there <ph name="USERNAME">%s</ph> \ '\'\''
35 '</message>')
36 res = grd_reader.Parse(buf, flexible_root = True)
37 content = res.GetCliques()[0].GetMessage().GetPresentableContent()
38 self.failUnless(content == 'Hello there USERNAME')
39 self.failUnless(res.ws_at_start == ' ')
40 self.failUnless(res.ws_at_end == ' ')
41
42 def testConstruct(self):
43 msg = tclib.Message(text=" Hello USERNAME, how are you? BINGO\t\t",
44 placeholders=[tclib.Placeholder('USERNAME', '%s', 'Joi') ,
45 tclib.Placeholder('BINGO', '%d', '11')])
46 msg_node = message.MessageNode.Construct(None, msg, 'BINGOBONGO')
47 self.failUnless(msg_node.children[0].name == 'ph')
48 self.failUnless(msg_node.children[0].children[0].name == 'ex')
49 self.failUnless(msg_node.children[0].children[0].GetCdata() == 'Joi')
50 self.failUnless(msg_node.children[1].children[0].GetCdata() == '11')
51 self.failUnless(msg_node.ws_at_start == ' ')
52 self.failUnless(msg_node.ws_at_end == '\t\t')
53
54 def testUnicodeConstruct(self):
55 text = u'Howdie \u00fe'
56 msg = tclib.Message(text=text)
57 msg_node = message.MessageNode.Construct(None, msg, 'BINGOBONGO')
58 msg_from_node = msg_node.GetCdata()
59 self.failUnless(msg_from_node == text)
60
61 if __name__ == '__main__':
62 unittest.main()
OLDNEW
« no previous file with comments | « grit/node/message.py ('k') | grit/node/misc.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698