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/js_externs_generator_test.py

Issue 2915423002: Externs generation: spit out src/-normalized path in generation messages (Closed)
Patch Set: path comments Created 3 years, 6 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/js_externs_generator.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 2015 The Chromium Authors. All rights reserved. 2 # Copyright 2015 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 import idl_schema 6 import idl_schema
7 import json_parse 7 import json_parse
8 from js_externs_generator import JsExternsGenerator 8 from js_externs_generator import JsExternsGenerator
9 from datetime import datetime 9 from datetime import datetime
10 import model 10 import model
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 }; 82 };
83 83
84 interface Events { 84 interface Events {
85 // Fired when we realize it's a trap! 85 // Fired when we realize it's a trap!
86 static void onTrapDetected(Baz baz); 86 static void onTrapDetected(Baz baz);
87 }; 87 };
88 }; 88 };
89 """ 89 """
90 90
91 # The output we expect from our fake idl file. 91 # The output we expect from our fake idl file.
92 expected_output = ("""// Copyright %s The Chromium Authors. All rights reserved. 92 expected_output = """// Copyright %s The Chromium Authors. All rights reserved.
93 // Use of this source code is governed by a BSD-style license that can be 93 // Use of this source code is governed by a BSD-style license that can be
94 // found in the LICENSE file. 94 // found in the LICENSE file.
95 95
96 // This file was generated by: 96 // This file was generated by:
97 // %s. 97 // tools/json_schema_compiler/compiler.py.
98 // NOTE: The format of types has changed. 'FooType' is now 98 // NOTE: The format of types has changed. 'FooType' is now
99 // 'chrome.fakeApi.FooType'. 99 // 'chrome.fakeApi.FooType'.
100 // Please run the closure compiler before committing changes. 100 // Please run the closure compiler before committing changes.
101 // See https://chromium.googlesource.com/chromium/src/+/master/docs/closure_comp ilation.md 101 // See https://chromium.googlesource.com/chromium/src/+/master/docs/closure_comp ilation.md
102 102
103 /** @fileoverview Externs generated from namespace: fakeApi */ 103 /** @fileoverview Externs generated from namespace: fakeApi */
104 104
105 /** 105 /**
106 * @const 106 * @const
107 */ 107 */
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 * @param {function((!chrome.fakeApi.Qux|undefined)):void=} callback 212 * @param {function((!chrome.fakeApi.Qux|undefined)):void=} callback
213 * @see https://developer.chrome.com/extensions/fakeApi#method-optionalParam 213 * @see https://developer.chrome.com/extensions/fakeApi#method-optionalParam
214 */ 214 */
215 chrome.fakeApi.optionalParam = function(callback) {}; 215 chrome.fakeApi.optionalParam = function(callback) {};
216 216
217 /** 217 /**
218 * Fired when we realize it's a trap! 218 * Fired when we realize it's a trap!
219 * @type {!ChromeEvent} 219 * @type {!ChromeEvent}
220 * @see https://developer.chrome.com/extensions/fakeApi#event-onTrapDetected 220 * @see https://developer.chrome.com/extensions/fakeApi#event-onTrapDetected
221 */ 221 */
222 chrome.fakeApi.onTrapDetected;""" % (datetime.now().year, sys.argv[0])) 222 chrome.fakeApi.onTrapDetected;""" % datetime.now().year
223 223
224 224
225 fake_json = """// Copyright 2014 The Chromium Authors. All rights reserved. 225 fake_json = """// Copyright 2014 The Chromium Authors. All rights reserved.
226 // Use of this source code is governed by a BSD-style license that can be 226 // Use of this source code is governed by a BSD-style license that can be
227 // found in the LICENSE file. 227 // found in the LICENSE file.
228 228
229 [ 229 [
230 { 230 {
231 "namespace": "fakeJson", 231 "namespace": "fakeJson",
232 "description": "Fake JSON API Stuff", 232 "description": "Fake JSON API Stuff",
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 "type": "object", 289 "type": "object",
290 "properties": { 290 "properties": {
291 "str": { "type": "string" }, 291 "str": { "type": "string" },
292 "int": { "type": "number" } 292 "int": { "type": "number" }
293 } 293 }
294 } 294 }
295 } ] 295 } ]
296 } 296 }
297 ]""" 297 ]"""
298 298
299 json_expected = ("""// Copyright %s The Chromium Authors. All rights reserved. 299 json_expected = """// Copyright %s The Chromium Authors. All rights reserved.
300 // Use of this source code is governed by a BSD-style license that can be 300 // Use of this source code is governed by a BSD-style license that can be
301 // found in the LICENSE file. 301 // found in the LICENSE file.
302 302
303 // This file was generated by: 303 // This file was generated by:
304 // %s. 304 // tools/json_schema_compiler/compiler.py.
305 // NOTE: The format of types has changed. 'FooType' is now 305 // NOTE: The format of types has changed. 'FooType' is now
306 // 'chrome.fakeJson.FooType'. 306 // 'chrome.fakeJson.FooType'.
307 // Please run the closure compiler before committing changes. 307 // Please run the closure compiler before committing changes.
308 // See https://chromium.googlesource.com/chromium/src/+/master/docs/closure_comp ilation.md 308 // See https://chromium.googlesource.com/chromium/src/+/master/docs/closure_comp ilation.md
309 309
310 /** @fileoverview Externs generated from namespace: fakeJson */ 310 /** @fileoverview Externs generated from namespace: fakeJson */
311 311
312 /** 312 /**
313 * @const 313 * @const
314 */ 314 */
(...skipping 22 matching lines...) Expand all
337 * description that causes problems! 337 * description that causes problems!
338 * @param {function({ 338 * @param {function({
339 * str: string 339 * str: string
340 * }):void} callback The callback to this heinous method 340 * }):void} callback The callback to this heinous method
341 * @return {{ 341 * @return {{
342 * str: string, 342 * str: string,
343 * int: number 343 * int: number
344 * }} 344 * }}
345 * @see https://developer.chrome.com/extensions/fakeJson#method-funcWithInlineOb j 345 * @see https://developer.chrome.com/extensions/fakeJson#method-funcWithInlineOb j
346 */ 346 */
347 chrome.fakeJson.funcWithInlineObj = function(inlineObj, callback) {};""" % 347 chrome.fakeJson.funcWithInlineObj = function(inlineObj, callback) {};""" % (
348 (datetime.now().year, sys.argv[0])) 348 datetime.now().year)
349 349
350 350
351 class JsExternGeneratorTest(unittest.TestCase): 351 class JsExternGeneratorTest(unittest.TestCase):
352 def _GetNamespace(self, fake_content, filename, is_idl): 352 def _GetNamespace(self, fake_content, filename, is_idl):
353 """Returns a namespace object for the given content""" 353 """Returns a namespace object for the given content"""
354 api_def = (idl_schema.Process(fake_content, filename) if is_idl 354 api_def = (idl_schema.Process(fake_content, filename) if is_idl
355 else json_parse.Parse(fake_content)) 355 else json_parse.Parse(fake_content))
356 m = model.Model() 356 m = model.Model()
357 return m.AddNamespace(api_def[0], filename) 357 return m.AddNamespace(api_def[0], filename)
358 358
359 def setUp(self): 359 def setUp(self):
360 self.maxDiff = None # Lets us see the full diff when inequal. 360 self.maxDiff = None # Lets us see the full diff when inequal.
361 361
362 def testBasic(self): 362 def testBasic(self):
363 namespace = self._GetNamespace(fake_idl, 'fake_api.idl', True) 363 namespace = self._GetNamespace(fake_idl, 'fake_api.idl', True)
364 self.assertMultiLineEqual(expected_output, 364 self.assertMultiLineEqual(expected_output,
365 JsExternsGenerator().Generate(namespace).Render()) 365 JsExternsGenerator().Generate(namespace).Render())
366 366
367 def testJsonWithInlineObjects(self): 367 def testJsonWithInlineObjects(self):
368 namespace = self._GetNamespace(fake_json, 'fake_api.json', False) 368 namespace = self._GetNamespace(fake_json, 'fake_api.json', False)
369 self.assertMultiLineEqual(json_expected, 369 self.assertMultiLineEqual(json_expected,
370 JsExternsGenerator().Generate(namespace).Render()) 370 JsExternsGenerator().Generate(namespace).Render())
371 371
372 372
373 if __name__ == '__main__': 373 if __name__ == '__main__':
374 unittest.main() 374 unittest.main()
OLDNEW
« no previous file with comments | « tools/json_schema_compiler/js_externs_generator.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698