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 16 matching lines...) Expand all Loading... |
27 | 27 |
28 dictionary Bar { | 28 dictionary Bar { |
29 long num; | 29 long num; |
30 }; | 30 }; |
31 | 31 |
32 dictionary Baz { | 32 dictionary Baz { |
33 DOMString str; | 33 DOMString str; |
34 long num; | 34 long num; |
35 boolean b; | 35 boolean b; |
36 Greek letter; | 36 Greek letter; |
| 37 Greek? optionalLetter; |
37 long[] arr; | 38 long[] arr; |
| 39 Bar[]? optionalObjArr; |
| 40 Greek[] enumArr; |
| 41 any[] anythingGoes; |
38 Bar obj; | 42 Bar obj; |
39 long? maybe; | 43 long? maybe; |
| 44 (DOMString or Greek or long[]) choice; |
40 }; | 45 }; |
41 | 46 |
42 callback VoidCallback = void(); | 47 callback VoidCallback = void(); |
43 | 48 |
44 interface Functions { | 49 interface Functions { |
45 // Does something exciting! | 50 // Does something exciting! |
46 // |baz| : The baz to use. | 51 // |baz| : The baz to use. |
47 static void doSomething(Baz baz, optional VoidCallback callback); | 52 static void doSomething(Baz baz, optional VoidCallback callback); |
48 }; | 53 }; |
49 }; | 54 }; |
(...skipping 26 matching lines...) Expand all Loading... |
76 * num: number | 81 * num: number |
77 * }} | 82 * }} |
78 */ | 83 */ |
79 var Bar; | 84 var Bar; |
80 | 85 |
81 /** | 86 /** |
82 * @typedef {{ | 87 * @typedef {{ |
83 * str: string, | 88 * str: string, |
84 * num: number, | 89 * num: number, |
85 * b: boolean, | 90 * b: boolean, |
86 * letter: chrome.fakeApi.Greek, | 91 * letter: !chrome.fakeApi.Greek, |
87 * arr: Array, | 92 * optionalLetter: (!chrome.fakeApi.Greek|undefined), |
| 93 * arr: !Array<number>, |
| 94 * optionalObjArr: (!Array<Bar>|undefined), |
| 95 * enumArr: !Array<!chrome.fakeApi.Greek>, |
| 96 * anythingGoes: !Array<*>, |
88 * obj: Bar, | 97 * obj: Bar, |
89 * maybe: (number|undefined) | 98 * maybe: (number|undefined), |
| 99 * choice: (string|!chrome.fakeApi.Greek|!Array<number>) |
90 * }} | 100 * }} |
91 */ | 101 */ |
92 var Baz; | 102 var Baz; |
93 | 103 |
94 /** | 104 /** |
95 * Does something exciting! | 105 * Does something exciting! |
96 * @param {Baz} baz The baz to use. | 106 * @param {Baz} baz The baz to use. |
97 * @param {Function=} callback | 107 * @param {Function=} callback |
98 */ | 108 */ |
99 chrome.fakeApi.doSomething = function(baz, callback) {}; | 109 chrome.fakeApi.doSomething = function(baz, callback) {}; |
100 """ % datetime.now().year | 110 """ % datetime.now().year |
101 | 111 |
102 | 112 |
103 class JsExternGeneratorTest(unittest.TestCase): | 113 class JsExternGeneratorTest(unittest.TestCase): |
104 def testBasic(self): | 114 def testBasic(self): |
| 115 self.maxDiff = None # Lets us see the full diff when inequal. |
105 filename = 'fake_api.idl' | 116 filename = 'fake_api.idl' |
106 api_def = idl_schema.Process(fake_idl, filename) | 117 api_def = idl_schema.Process(fake_idl, filename) |
107 m = model.Model() | 118 m = model.Model() |
108 namespace = m.AddNamespace(api_def[0], filename) | 119 namespace = m.AddNamespace(api_def[0], filename) |
109 self.assertEquals(expected_output, | 120 self.assertMultiLineEqual(expected_output, |
110 JsExternsGenerator().Generate(namespace).Render()) | 121 JsExternsGenerator().Generate(namespace).Render()) |
111 | 122 |
112 | 123 |
113 if __name__ == '__main__': | 124 if __name__ == '__main__': |
114 unittest.main() | 125 unittest.main() |
OLD | NEW |