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 28 matching lines...) Expand all Loading... |
39 Bar[]? optionalObjArr; | 39 Bar[]? optionalObjArr; |
40 Greek[] enumArr; | 40 Greek[] enumArr; |
41 any[] anythingGoes; | 41 any[] anythingGoes; |
42 Bar obj; | 42 Bar obj; |
43 long? maybe; | 43 long? maybe; |
44 (DOMString or Greek or long[]) choice; | 44 (DOMString or Greek or long[]) choice; |
45 }; | 45 }; |
46 | 46 |
47 callback VoidCallback = void(); | 47 callback VoidCallback = void(); |
48 | 48 |
| 49 callback BazGreekCallback = void(Baz baz, Greek greek); |
| 50 |
49 interface Functions { | 51 interface Functions { |
50 // Does something exciting! | 52 // Does something exciting! And what's more, this is a multiline function |
| 53 // comment! It goes onto multiple lines! |
51 // |baz| : The baz to use. | 54 // |baz| : The baz to use. |
52 static void doSomething(Baz baz, optional VoidCallback callback); | 55 static void doSomething(Baz baz, VoidCallback callback); |
| 56 |
| 57 static void bazGreek(optional BazGreekCallback callback); |
| 58 |
| 59 [deprecated="Use a new method."] static DOMString returnString(); |
53 }; | 60 }; |
54 }; | 61 }; |
55 """ | 62 """ |
56 | 63 |
57 # The output we expect from our fake idl file. | 64 # The output we expect from our fake idl file. |
58 expected_output = """// Copyright %s The Chromium Authors. All rights reserved. | 65 expected_output = """// Copyright %s The Chromium Authors. All rights reserved. |
59 // Use of this source code is governed by a BSD-style license that can be | 66 // Use of this source code is governed by a BSD-style license that can be |
60 // found in the LICENSE file. | 67 // found in the LICENSE file. |
61 | 68 |
62 /** @fileoverview Externs generated from namespace: fakeApi */ | 69 /** @fileoverview Externs generated from namespace: fakeApi */ |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 * enumArr: !Array<!chrome.fakeApi.Greek>, | 102 * enumArr: !Array<!chrome.fakeApi.Greek>, |
96 * anythingGoes: !Array<*>, | 103 * anythingGoes: !Array<*>, |
97 * obj: Bar, | 104 * obj: Bar, |
98 * maybe: (number|undefined), | 105 * maybe: (number|undefined), |
99 * choice: (string|!chrome.fakeApi.Greek|!Array<number>) | 106 * choice: (string|!chrome.fakeApi.Greek|!Array<number>) |
100 * }} | 107 * }} |
101 */ | 108 */ |
102 var Baz; | 109 var Baz; |
103 | 110 |
104 /** | 111 /** |
105 * Does something exciting! | 112 * Does something exciting! And what's more, this is a multiline function |
| 113 * comment! It goes onto multiple lines! |
106 * @param {Baz} baz The baz to use. | 114 * @param {Baz} baz The baz to use. |
107 * @param {Function=} callback | 115 * @param {function():void} callback |
108 */ | 116 */ |
109 chrome.fakeApi.doSomething = function(baz, callback) {}; | 117 chrome.fakeApi.doSomething = function(baz, callback) {}; |
| 118 |
| 119 /** |
| 120 * @param {function(Baz, !chrome.fakeApi.Greek):void=} callback |
| 121 */ |
| 122 chrome.fakeApi.bazGreek = function(callback) {}; |
| 123 |
| 124 /** |
| 125 * @return {string} |
| 126 * @deprecated Use a new method. |
| 127 */ |
| 128 chrome.fakeApi.returnString = function() {}; |
110 """ % datetime.now().year | 129 """ % datetime.now().year |
111 | 130 |
112 | 131 |
113 class JsExternGeneratorTest(unittest.TestCase): | 132 class JsExternGeneratorTest(unittest.TestCase): |
114 def testBasic(self): | 133 def testBasic(self): |
115 self.maxDiff = None # Lets us see the full diff when inequal. | 134 self.maxDiff = None # Lets us see the full diff when inequal. |
116 filename = 'fake_api.idl' | 135 filename = 'fake_api.idl' |
117 api_def = idl_schema.Process(fake_idl, filename) | 136 api_def = idl_schema.Process(fake_idl, filename) |
118 m = model.Model() | 137 m = model.Model() |
119 namespace = m.AddNamespace(api_def[0], filename) | 138 namespace = m.AddNamespace(api_def[0], filename) |
120 self.assertMultiLineEqual(expected_output, | 139 self.assertMultiLineEqual(expected_output, |
121 JsExternsGenerator().Generate(namespace).Render()) | 140 JsExternsGenerator().Generate(namespace).Render()) |
122 | 141 |
123 | 142 |
124 if __name__ == '__main__': | 143 if __name__ == '__main__': |
125 unittest.main() | 144 unittest.main() |
OLD | NEW |