Chromium Code Reviews| Index: tools/json_schema_compiler/js_externs_generator_test.py |
| diff --git a/tools/json_schema_compiler/js_externs_generator_test.py b/tools/json_schema_compiler/js_externs_generator_test.py |
| index 2ca31695665633e29ed76154f7ba274416c3adb9..57725f7bb68aa6429533bd8db8fd181143dc2d14 100755 |
| --- a/tools/json_schema_compiler/js_externs_generator_test.py |
| +++ b/tools/json_schema_compiler/js_externs_generator_test.py |
| @@ -4,6 +4,7 @@ |
| # found in the LICENSE file. |
| import idl_schema |
| +import json_parse |
| from js_externs_generator import JsExternsGenerator |
| from datetime import datetime |
| import model |
| @@ -134,16 +135,121 @@ chrome.fakeApi.returnString = function() {}; |
| """ % datetime.now().year |
| +fake_json = """// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +[ |
| + { |
| + "namespace": "fakeJson", |
| + "description": "Fake JSON API Stuff", |
| + "functions": [ { |
| + "name": "funcWithInlineObj", |
| + "type": "function", |
| + "parameters": [ |
| + { |
| + "type": "object", |
| + "name": "inlineObj", |
| + "description": "Evil inline object! With a super duper duper long string description that causes problems!", |
| + "properties": { |
| + "foo": { |
| + "type": "boolean", |
| + "optional": "true", |
| + "description": "The foo." |
| + }, |
| + "bar": { |
| + "type": "integer", |
| + "description": "The bar." |
| + }, |
| + "baz": { |
| + "type": "object", |
| + "description": "Inception object.", |
| + "properties": { |
| + "depth": { |
| + "type": "integer" |
| + } |
| + } |
| + } |
| + } |
| + }, |
| + { |
| + "name": "callback", |
| + "type": "function", |
| + "parameters": [ |
| + { |
| + "type": "object", |
| + "name": "returnObj", |
| + "properties": { |
| + "str": { "type": "string"} |
| + } |
| + } |
| + ], |
| + "description": "The callback to this heinous method" |
| + } |
| + ], |
| + "returns": { |
| + "type": "object", |
| + "properties": { |
| + "str": { "type": "string" }, |
| + "int": { "type": "number" } |
| + } |
| + } |
| + } ] |
| + } |
| +]""" |
| + |
| +json_expected = """// Copyright %s The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +/** @fileoverview Externs generated from namespace: fakeJson */ |
| + |
| +/** |
| + * @const |
| + */ |
| +chrome.fakeJson = {}; |
| + |
| +/** |
| + * @param {{ |
|
Devlin
2015/03/27 18:51:33
Yay!
For reference, before, this would have read:
|
| + * foo: (boolean|undefined), |
| + * bar: number, |
| + * baz: { |
| + * depth: number |
| + * } |
| + * }} inlineObj Evil inline object! With a super duper duper long string |
| + * description that causes problems! |
| + * @param {function({ |
| + * str: string |
| + * }):void} callback The callback to this heinous method |
| + * @return {{ |
| + * str: string, |
| + * int: number |
| + * }} |
| + */ |
| +chrome.fakeJson.funcWithInlineObj = function(inlineObj, callback) {}; |
| +""" % datetime.now().year |
|
Dan Beam
2015/03/27 19:05:25
if you're actually testing that the copyright is u
Devlin
2015/03/27 20:50:11
That's probably wise. Done.
|
| + |
| + |
| class JsExternGeneratorTest(unittest.TestCase): |
| + def _GetNamespace(self, fake_content, filename, is_idl): |
| + """Returns a namespace object for the given content""" |
| + api_def = (idl_schema.Process(fake_content, filename) if is_idl |
| + else json_parse.Parse(fake_content)) |
| + m = model.Model() |
| + return m.AddNamespace(api_def[0], filename) |
| + |
| def testBasic(self): |
| self.maxDiff = None # Lets us see the full diff when inequal. |
| - filename = 'fake_api.idl' |
| - api_def = idl_schema.Process(fake_idl, filename) |
| - m = model.Model() |
| - namespace = m.AddNamespace(api_def[0], filename) |
| + namespace = self._GetNamespace(fake_idl, 'fake_api.idl', True) |
| self.assertMultiLineEqual(expected_output, |
| JsExternsGenerator().Generate(namespace).Render()) |
| + def testJsonWithInlineObjects(self): |
| + self.maxDiff = None # Lets us see the full diff when inequal. |
| + namespace = self._GetNamespace(fake_json, 'fake_api.json', False) |
| + self.assertMultiLineEqual(json_expected, |
| + JsExternsGenerator().Generate(namespace).Render()) |
| + |
| if __name__ == '__main__': |
| unittest.main() |