Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(199)

Side by Side Diff: tools/json_schema_compiler/js_externs_generator_test.py

Issue 1034553003: [Extension API Extern Generation] Fix array, choices specification (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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 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
27 dictionary Bar { 27 dictionary Bar {
28 long num; 28 long num;
29 }; 29 };
30 30
31 dictionary Baz { 31 dictionary Baz {
32 DOMString str; 32 DOMString str;
33 long num; 33 long num;
34 boolean b; 34 boolean b;
35 Greek letter; 35 Greek letter;
36 long[] arr; 36 long[] arr;
37 Bar[]? optionalObjArr;
38 Greek[] enumArr;
37 Bar obj; 39 Bar obj;
38 long? maybe; 40 long? maybe;
41 (DOMString or Greek or long[]) choice;
39 }; 42 };
40 43
41 callback VoidCallback = void(); 44 callback VoidCallback = void();
42 45
43 interface Functions { 46 interface Functions {
44 // Does something exciting! 47 // Does something exciting!
45 // |baz| : The baz to use. 48 // |baz| : The baz to use.
46 static void doSomething(Baz baz, optional VoidCallback callback); 49 static void doSomething(Baz baz, optional VoidCallback callback);
47 }; 50 };
48 }; 51 };
(...skipping 27 matching lines...) Expand all
76 * }} 79 * }}
77 */ 80 */
78 var Bar; 81 var Bar;
79 82
80 /** 83 /**
81 * @typedef {{ 84 * @typedef {{
82 * str: string, 85 * str: string,
83 * num: number, 86 * num: number,
84 * b: boolean, 87 * b: boolean,
85 * letter: chrome.fakeApi.Greek, 88 * letter: chrome.fakeApi.Greek,
86 * arr: Array, 89 * arr: !Array<number>,
90 * optionalObjArr: (!Array<Bar>|undefined),
91 * enumArr: !Array<chrome.fakeApi.Greek>,
Tyler Breisacher (Chromium) 2015/03/24 22:45:03 should this be !Array<!chrome.fakeApi.Greek> ?
Devlin 2015/03/24 23:10:37 Yes, I suppose that makes sense, as long as we mai
87 * obj: Bar, 92 * obj: Bar,
88 * maybe: (number|undefined) 93 * maybe: (number|undefined),
94 * choice: (string|chrome.fakeApi.Greek|!Array<number>)
Tyler Breisacher (Chromium) 2015/03/24 22:45:03 (string|!chrome.fakeApi.Greek|!Array<number>) ?
Devlin 2015/03/24 23:10:37 Done.
89 * }} 95 * }}
90 */ 96 */
91 var Baz; 97 var Baz;
92 98
93 /** 99 /**
94 * Does something exciting! 100 * Does something exciting!
95 * @param {Baz} baz The baz to use. 101 * @param {Baz} baz The baz to use.
96 * @param {Function=} callback 102 * @param {Function=} callback
97 */ 103 */
98 chrome.fakeApi.doSomething = function(baz, callback) {}; 104 chrome.fakeApi.doSomething = function(baz, callback) {};
99 """ % datetime.now().year 105 """ % datetime.now().year
100 106
101 class JsExternGeneratorTest(unittest.TestCase): 107 class JsExternGeneratorTest(unittest.TestCase):
102 def testBasic(self): 108 def testBasic(self):
109 self.maxDiff = None # Lets us see the full diff when inequal.
103 filename = 'fake_api.idl' 110 filename = 'fake_api.idl'
104 api_def = idl_schema.Process(fake_idl, filename) 111 api_def = idl_schema.Process(fake_idl, filename)
105 m = model.Model() 112 m = model.Model()
106 namespace = m.AddNamespace(api_def[0], filename) 113 namespace = m.AddNamespace(api_def[0], filename)
107 self.assertEquals(expected_output, 114 self.assertMultiLineEqual(expected_output,
108 JsExternsGenerator().Generate(namespace).Render()) 115 JsExternsGenerator().Generate(namespace).Render())
109 116
110 if __name__ == '__main__': 117 if __name__ == '__main__':
111 unittest.main() 118 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