| OLD | NEW |
| 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 from js_externs_generator import JsExternsGenerator | 7 from js_externs_generator import JsExternsGenerator |
| 8 from datetime import datetime | 8 from datetime import datetime |
| 9 import model | 9 import model |
| 10 import unittest | 10 import unittest |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 callback VoidCallback = void(); | 47 callback VoidCallback = void(); |
| 48 | 48 |
| 49 callback BazGreekCallback = void(Baz baz, Greek greek); | 49 callback BazGreekCallback = void(Baz baz, Greek greek); |
| 50 | 50 |
| 51 interface Functions { | 51 interface Functions { |
| 52 // Does something exciting! And what's more, this is a multiline function | 52 // Does something exciting! And what's more, this is a multiline function |
| 53 // comment! It goes onto multiple lines! | 53 // comment! It goes onto multiple lines! |
| 54 // |baz| : The baz to use. | 54 // |baz| : The baz to use. |
| 55 static void doSomething(Baz baz, VoidCallback callback); | 55 static void doSomething(Baz baz, VoidCallback callback); |
| 56 | 56 |
| 57 // |callback| : The callback which will most assuredly in all cases be |
| 58 // called; that is, of course, assuming such a callback was provided and is |
| 59 // not at all null. |
| 57 static void bazGreek(optional BazGreekCallback callback); | 60 static void bazGreek(optional BazGreekCallback callback); |
| 58 | 61 |
| 59 [deprecated="Use a new method."] static DOMString returnString(); | 62 [deprecated="Use a new method."] static DOMString returnString(); |
| 60 }; | 63 }; |
| 61 }; | 64 }; |
| 62 """ | 65 """ |
| 63 | 66 |
| 64 # The output we expect from our fake idl file. | 67 # The output we expect from our fake idl file. |
| 65 expected_output = """// Copyright %s The Chromium Authors. All rights reserved. | 68 expected_output = """// Copyright %s The Chromium Authors. All rights reserved. |
| 66 // Use of this source code is governed by a BSD-style license that can be | 69 // Use of this source code is governed by a BSD-style license that can be |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 | 113 |
| 111 /** | 114 /** |
| 112 * Does something exciting! And what's more, this is a multiline function | 115 * Does something exciting! And what's more, this is a multiline function |
| 113 * comment! It goes onto multiple lines! | 116 * comment! It goes onto multiple lines! |
| 114 * @param {Baz} baz The baz to use. | 117 * @param {Baz} baz The baz to use. |
| 115 * @param {function():void} callback | 118 * @param {function():void} callback |
| 116 */ | 119 */ |
| 117 chrome.fakeApi.doSomething = function(baz, callback) {}; | 120 chrome.fakeApi.doSomething = function(baz, callback) {}; |
| 118 | 121 |
| 119 /** | 122 /** |
| 120 * @param {function(Baz, !chrome.fakeApi.Greek):void=} callback | 123 * @param {function(Baz, !chrome.fakeApi.Greek):void=} callback The callback |
| 124 * which will most assuredly in all cases be called; that is, of course, |
| 125 * assuming such a callback was provided and is not at all null. |
| 121 */ | 126 */ |
| 122 chrome.fakeApi.bazGreek = function(callback) {}; | 127 chrome.fakeApi.bazGreek = function(callback) {}; |
| 123 | 128 |
| 124 /** | 129 /** |
| 125 * @return {string} | 130 * @return {string} |
| 126 * @deprecated Use a new method. | 131 * @deprecated Use a new method. |
| 127 */ | 132 */ |
| 128 chrome.fakeApi.returnString = function() {}; | 133 chrome.fakeApi.returnString = function() {}; |
| 129 """ % datetime.now().year | 134 """ % datetime.now().year |
| 130 | 135 |
| 131 | 136 |
| 132 class JsExternGeneratorTest(unittest.TestCase): | 137 class JsExternGeneratorTest(unittest.TestCase): |
| 133 def testBasic(self): | 138 def testBasic(self): |
| 134 self.maxDiff = None # Lets us see the full diff when inequal. | 139 self.maxDiff = None # Lets us see the full diff when inequal. |
| 135 filename = 'fake_api.idl' | 140 filename = 'fake_api.idl' |
| 136 api_def = idl_schema.Process(fake_idl, filename) | 141 api_def = idl_schema.Process(fake_idl, filename) |
| 137 m = model.Model() | 142 m = model.Model() |
| 138 namespace = m.AddNamespace(api_def[0], filename) | 143 namespace = m.AddNamespace(api_def[0], filename) |
| 139 self.assertMultiLineEqual(expected_output, | 144 self.assertMultiLineEqual(expected_output, |
| 140 JsExternsGenerator().Generate(namespace).Render()) | 145 JsExternsGenerator().Generate(namespace).Render()) |
| 141 | 146 |
| 142 | 147 |
| 143 if __name__ == '__main__': | 148 if __name__ == '__main__': |
| 144 unittest.main() | 149 unittest.main() |
| OLD | NEW |