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
4 # found in the LICENSE file.
9 class CodeTest(unittest.TestCase):
13 self.assertEquals('line', c.Render())
62 self.assertEquals('', a.Render())
73 def testConcatErrors(self):
77 self.assertRaises(TypeError, c.Concat, d)
79 d.Append('%(classname)s')
80 self.assertRaises(TypeError, c.Concat, d)
82 self.assertRaises(TypeError, c.Concat, d)
84 def testSubstitute(self):
86 c.Append('%(var1)s %(var2)s %(var1)s')
87 c.Substitute({'var1': 'one', 'var2': 'two'})
88 self.assertEquals('one two one', c.Render())
89 c.Append('%(var1)s %(var2)s %(var3)s')
90 c.Append('%(var2)s %(var1)s %(var3)s')
91 c.Substitute({'var1': 'one', 'var2': 'two', 'var3': 'three'})
98 def testSubstituteErrors(self):
99 # No unnamed placeholders allowed when substitute is run
102 self.assertRaises(TypeError, c.Substitute, ('var1', 'one'))
104 c.Append('%s %(var1)s')
105 self.assertRaises(TypeError, c.Substitute, {'var1': 'one'})
107 c.Append('%s %(var1)s')
108 self.assertRaises(TypeError, c.Substitute, {'var1': 'one'})
111 self.assertRaises(KeyError, c.Substitute, {'clearlynotvar1': 'one'})
113 def testIsEmpty(self):
115 self.assertTrue(c.IsEmpty())
117 self.assertFalse(c.IsEmpty())
119 def testComment(self):
120 long_comment = ('This comment is eighty nine characters in longness, '
121 'that is, to use another word, length')
123 c.Comment(long_comment)
125 '// This comment is eighty nine characters '
126 'in longness, that is, to use another\n'
131 c.Comment(long_comment)
133 c.Comment(long_comment)
136 ' // This comment is eighty nine characters '
137 'in longness, that is, to use\n'
138 ' // another word, length\n'
140 '// This comment is eighty nine characters in '
141 'longness, that is, to use another\n'
144 long_word = 'x' * 100
148 '// ' + 'x' * 77 + '\n'
152 def testCommentWithSpecialCharacters(self):
154 c.Comment('20% of 80%s')
156 self.assertEquals('// 20% of 80%s', c.Render())
160 self.assertEquals('90\n'
164 if __name__ == '__main__':