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

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

Issue 1513573012: Fix line wrapping in json_schema_compiler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Generate -> Append Created 4 years, 11 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
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 import json_parse 7 import json_parse
8 from js_interface_generator import JsInterfaceGenerator 8 from js_interface_generator import JsInterfaceGenerator
9 from datetime import datetime 9 from datetime import datetime
10 import model 10 import model
11 import sys 11 import sys
12 import unittest 12 import unittest
13 13
14 # The contents of a fake idl file. 14 # The contents of a fake idl file.
15 fake_idl = """ 15 fake_idl = """
16 // Copyright 2014 The Chromium Authors. All rights reserved. 16 // Copyright 2014 The Chromium Authors. All rights reserved.
17 // Use of this source code is governed by a BSD-style license that can be 17 // Use of this source code is governed by a BSD-style license that can be
18 // found in the LICENSE file. 18 // found in the LICENSE file.
19 19
20 // A totally fake API. 20 // A totally fake API.
21 namespace fakeApi { 21 namespace fakeApi {
22 enum Grk { 22 enum Greek {
23 ALPHA, 23 ALPHA,
24 BETA, 24 BETA,
25 GAMMA, 25 GAMMA,
26 DELTA 26 DELTA
27 }; 27 };
28 28
29 dictionary Bar { 29 dictionary Bar {
30 long num; 30 long num;
31 }; 31 };
32 32
33 dictionary Baz { 33 dictionary Baz {
34 DOMString str; 34 DOMString str;
35 long num; 35 long num;
36 boolean b; 36 boolean b;
37 Grk letter; 37 Greek letter;
38 Grk? optionalLetter; 38 Greek? optionalLetter;
39 long[] arr; 39 long[] arr;
40 Bar[]? optionalObjArr; 40 Bar[]? optionalObjArr;
41 Grk[] enumArr; 41 Greek[] enumArr;
42 any[] anythingGoes; 42 any[] anythingGoes;
43 Bar obj; 43 Bar obj;
44 long? maybe; 44 long? maybe;
45 (DOMString or Grk or long[]) choice; 45 (DOMString or Greek or long[]) choice;
46 object plainObj; 46 object plainObj;
47 }; 47 };
48 48
49 callback VoidCallback = void(); 49 callback VoidCallback = void();
50 50
51 callback BazGrkCallback = void(Baz baz, Grk greek); 51 callback BazGreekCallback = void(Baz baz, Greek greek);
52 52
53 interface Functions { 53 interface Functions {
54 // Does something exciting! And what's more, this is a multiline function 54 // Does something exciting! And what's more, this is a multiline function
55 // comment! It goes onto multiple lines! 55 // comment! It goes onto multiple lines!
56 // |baz| : The baz to use. 56 // |baz| : The baz to use.
57 static void doSomething(Baz baz, VoidCallback callback); 57 static void doSomething(Baz baz, VoidCallback callback);
58 58
59 // |callback| : The callback which will most assuredly in all cases be 59 // |callback| : The callback which will most assuredly in all cases be
60 // called; that is, of course, iff such a callback was provided and is 60 // called; that is, of course, iff such a callback was provided and is
61 // not at all null. 61 // not at all null.
62 static void bazGrk(optional BazGrkCallback callback); 62 static void bazGreek(optional BazGreekCallback callback);
63 63
64 [deprecated="Use a new method."] static DOMString returnString(); 64 [deprecated="Use a new method."] static DOMString returnString();
65 }; 65 };
66 66
67 interface Events { 67 interface Events {
68 // Fired when we realize it's a trap! 68 // Fired when we realize it's a trap!
69 static void onTrapDetected(Baz baz); 69 static void onTrapDetected(Baz baz);
70 }; 70 };
71 }; 71 };
72 """ 72 """
(...skipping 17 matching lines...) Expand all
90 /** 90 /**
91 * Does something exciting! And what's more, this is a multiline function 91 * Does something exciting! And what's more, this is a multiline function
92 * comment! It goes onto multiple lines! 92 * comment! It goes onto multiple lines!
93 * @param {!chrome.fakeApi.Baz} baz The baz to use. 93 * @param {!chrome.fakeApi.Baz} baz The baz to use.
94 * @param {function():void} callback 94 * @param {function():void} callback
95 * @see https://developer.chrome.com/extensions/fakeApi#method-doSomething 95 * @see https://developer.chrome.com/extensions/fakeApi#method-doSomething
96 */ 96 */
97 doSomething: assertNotReached, 97 doSomething: assertNotReached,
98 98
99 /** 99 /**
100 * @param {function(!chrome.fakeApi.Baz, !chrome.fakeApi.Grk):void=} callback 100 * @param {function(!chrome.fakeApi.Baz, !chrome.fakeApi.Greek):void=}
101 * The callback which will most assuredly in all cases be called; that is, 101 * callback The callback which will most assuredly in all cases be called;
102 * of course, iff such a callback was provided and is not at all null. 102 * that is, of course, iff such a callback was provided and is not at all
103 * @see https://developer.chrome.com/extensions/fakeApi#method-bazGrk 103 * null.
104 * @see https://developer.chrome.com/extensions/fakeApi#method-bazGreek
104 */ 105 */
105 bazGrk: assertNotReached, 106 bazGreek: assertNotReached,
106 107
107 /** 108 /**
108 * Fired when we realize it's a trap! 109 * Fired when we realize it's a trap!
109 * @type {!ChromeEvent} 110 * @type {!ChromeEvent}
110 * @see https://developer.chrome.com/extensions/fakeApi#event-onTrapDetected 111 * @see https://developer.chrome.com/extensions/fakeApi#event-onTrapDetected
111 */ 112 */
112 onTrapDetected: new ChromeEvent(), 113 onTrapDetected: new ChromeEvent(),
113 };""" % (datetime.now().year, sys.argv[0])) 114 };""" % (datetime.now().year, sys.argv[0]))
114 115
115 class JsExternGeneratorTest(unittest.TestCase): 116 class JsExternGeneratorTest(unittest.TestCase):
116 def _GetNamespace(self, fake_content, filename): 117 def _GetNamespace(self, fake_content, filename):
117 """Returns a namespace object for the given content""" 118 """Returns a namespace object for the given content"""
118 api_def = idl_schema.Process(fake_content, filename) 119 api_def = idl_schema.Process(fake_content, filename)
119 m = model.Model() 120 m = model.Model()
120 return m.AddNamespace(api_def[0], filename) 121 return m.AddNamespace(api_def[0], filename)
121 122
122 def setUp(self): 123 def setUp(self):
123 self.maxDiff = None # Lets us see the full diff when inequal. 124 self.maxDiff = None # Lets us see the full diff when inequal.
124 125
125 def testBasic(self): 126 def testBasic(self):
126 namespace = self._GetNamespace(fake_idl, 'fake_api.idl') 127 namespace = self._GetNamespace(fake_idl, 'fake_api.idl')
127 self.assertMultiLineEqual( 128 self.assertMultiLineEqual(
128 expected_output, 129 expected_output,
129 JsInterfaceGenerator().Generate(namespace).Render()) 130 JsInterfaceGenerator().Generate(namespace).Render())
130 131
131 132
132 if __name__ == '__main__': 133 if __name__ == '__main__':
133 unittest.main() 134 unittest.main()
OLDNEW
« no previous file with comments | « tools/json_schema_compiler/js_interface_generator.py ('k') | tools/json_schema_compiler/js_util.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698