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

Side by Side Diff: tools/json_schema_compiler/code_test.py

Issue 1010603007: [Extension API Extern Generation] Fix comment indentation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: True 80 char limit Created 5 years, 9 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 | « tools/json_schema_compiler/code.py ('k') | tools/json_schema_compiler/js_externs_generator.py » ('j') | 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 from code import Code 6 from code import Code
7 import unittest 7 import unittest
8 8
9 class CodeTest(unittest.TestCase): 9 class CodeTest(unittest.TestCase):
10 def testAppend(self): 10 def testAppend(self):
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 c.Append('%(var1)s') 110 c.Append('%(var1)s')
111 self.assertRaises(KeyError, c.Substitute, {'clearlynotvar1': 'one'}) 111 self.assertRaises(KeyError, c.Substitute, {'clearlynotvar1': 'one'})
112 112
113 def testIsEmpty(self): 113 def testIsEmpty(self):
114 c = Code() 114 c = Code()
115 self.assertTrue(c.IsEmpty()) 115 self.assertTrue(c.IsEmpty())
116 c.Append('asdf') 116 c.Append('asdf')
117 self.assertFalse(c.IsEmpty()) 117 self.assertFalse(c.IsEmpty())
118 118
119 def testComment(self): 119 def testComment(self):
120 long_comment = ('This comment is eighty nine characters in longness, ' 120 long_comment = ('This comment is ninety one characters in longness, '
121 'that is, to use another word, length') 121 'that is, using a different word, length.')
122 c = Code() 122 c = Code()
123 c.Comment(long_comment) 123 c.Comment(long_comment)
124 self.assertEquals( 124 self.assertEquals(
125 '// This comment is eighty nine characters ' 125 '// This comment is ninety one characters '
126 'in longness, that is, to use another\n' 126 'in longness, that is, using a different\n'
127 '// word, length', 127 '// word, length.',
128 c.Render()) 128 c.Render())
129 c = Code() 129 c = Code()
130 c.Sblock('sblock') 130 c.Sblock('sblock')
131 c.Comment(long_comment) 131 c.Comment(long_comment)
132 c.Eblock('eblock') 132 c.Eblock('eblock')
133 c.Comment(long_comment) 133 c.Comment(long_comment)
134 self.assertEquals( 134 self.assertEquals(
135 'sblock\n' 135 'sblock\n'
136 ' // This comment is eighty nine characters ' 136 ' // This comment is ninety one characters '
137 'in longness, that is, to use\n' 137 'in longness, that is, using a\n'
138 ' // another word, length\n' 138 ' // different word, length.\n'
139 'eblock\n' 139 'eblock\n'
140 '// This comment is eighty nine characters in ' 140 '// This comment is ninety one characters in '
141 'longness, that is, to use another\n' 141 'longness, that is, using a different\n'
142 '// word, length', 142 '// word, length.',
143 c.Render()) 143 c.Render())
144 long_word = 'x' * 100 144 long_word = 'x' * 100
145 c = Code() 145 c = Code()
146 c.Comment(long_word) 146 c.Comment(long_word)
147 self.assertEquals( 147 self.assertEquals(
148 '// ' + 'x' * 77 + '\n' 148 '// ' + 'x' * 77 + '\n'
149 '// ' + 'x' * 23, 149 '// ' + 'x' * 23,
150 c.Render()) 150 c.Render())
151 c = Code(indent_size=2, comment_length=40)
152 c.Comment('Pretend this is a Closure Compiler style comment, which should '
153 'both wrap and indent', comment_prefix=' * ', wrap_indent=4)
154 self.assertEquals(
155 ' * Pretend this is a Closure Compiler\n'
156 ' * style comment, which should both\n'
157 ' * wrap and indent',
158 c.Render())
151 159
152 def testCommentWithSpecialCharacters(self): 160 def testCommentWithSpecialCharacters(self):
153 c = Code() 161 c = Code()
154 c.Comment('20% of 80%s') 162 c.Comment('20% of 80%s')
155 c.Substitute({}) 163 c.Substitute({})
156 self.assertEquals('// 20% of 80%s', c.Render()) 164 self.assertEquals('// 20% of 80%s', c.Render())
157 d = Code() 165 d = Code()
158 d.Append('90') 166 d.Append('90')
159 d.Concat(c) 167 d.Concat(c)
160 self.assertEquals('90\n' 168 self.assertEquals('90\n'
161 '// 20% of 80%s', 169 '// 20% of 80%s',
162 d.Render()) 170 d.Render())
163 171
164 if __name__ == '__main__': 172 if __name__ == '__main__':
165 unittest.main() 173 unittest.main()
OLDNEW
« no previous file with comments | « tools/json_schema_compiler/code.py ('k') | tools/json_schema_compiler/js_externs_generator.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698