Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 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 | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 import idl_schema | |
| 7 from js_externs_generator import JsExternsGenerator | |
| 8 from datetime import datetime | |
| 9 import model | |
| 10 import unittest | |
| 11 | |
|
Dan Beam
2015/03/24 21:19:18
nit: \n\n
Devlin
2015/03/24 21:26:26
Done.
| |
| 12 # The contents of a fake idl file. | |
| 13 fake_idl = """ | |
| 14 // Copyright %s The Chromium Authors. All rights reserved. | |
| 15 // Use of this source code is governed by a BSD-style license that can be | |
| 16 // found in the LICENSE file. | |
| 17 | |
| 18 // A totally fake API. | |
| 19 namespace fakeApi { | |
| 20 enum Greek { | |
| 21 ALPHA, | |
| 22 BETA, | |
| 23 GAMMA, | |
| 24 DELTA | |
| 25 }; | |
| 26 | |
| 27 dictionary Bar { | |
| 28 long num; | |
| 29 }; | |
| 30 | |
| 31 dictionary Baz { | |
| 32 DOMString str; | |
| 33 long num; | |
| 34 boolean b; | |
| 35 Greek letter; | |
| 36 long[] arr; | |
| 37 Bar obj; | |
| 38 long? maybe; | |
| 39 }; | |
| 40 | |
| 41 callback VoidCallback = void(); | |
| 42 | |
| 43 interface Functions { | |
| 44 // Does something exciting! | |
| 45 // |baz| : The baz to use. | |
| 46 static void doSomething(Baz baz, optional VoidCallback callback); | |
| 47 }; | |
| 48 }; | |
| 49 """ | |
| 50 | |
| 51 # The output we expect from our fake idl file. | |
| 52 expected_output = """// Copyright %s The Chromium Authors. All rights reserved. | |
| 53 // Use of this source code is governed by a BSD-style license that can be | |
| 54 // found in the LICENSE file. | |
| 55 | |
| 56 /** @fileoverview Externs generated from namespace: fakeApi */ | |
| 57 | |
| 58 /** | |
| 59 * @const | |
| 60 */ | |
| 61 chrome.fakeApi = {}; | |
| 62 | |
| 63 /** | |
| 64 * @enum {string} | |
| 65 */ | |
| 66 chrome.fakeApi.Greek = { | |
| 67 ALPHA: 'ALPHA', | |
| 68 BETA: 'BETA', | |
| 69 GAMMA: 'GAMMA', | |
| 70 DELTA: 'DELTA', | |
| 71 }; | |
| 72 | |
| 73 /** | |
| 74 * @typedef {{ | |
| 75 * num: number | |
| 76 * }} | |
| 77 */ | |
| 78 var Bar; | |
| 79 | |
| 80 /** | |
| 81 * @typedef {{ | |
| 82 * str: string, | |
| 83 * num: number, | |
| 84 * b: boolean, | |
| 85 * letter: chrome.fakeApi.Greek, | |
| 86 * arr: Array, | |
| 87 * obj: Bar, | |
| 88 * maybe: (number|undefined) | |
| 89 * }} | |
| 90 */ | |
| 91 var Baz; | |
| 92 | |
| 93 /** | |
| 94 * Does something exciting! | |
| 95 * @param {Baz} baz The baz to use. | |
| 96 * @param {Function=} callback | |
| 97 */ | |
| 98 chrome.fakeApi.doSomething = function(baz, callback) {}; | |
| 99 """ % datetime.now().year | |
| 100 | |
|
Dan Beam
2015/03/24 21:19:18
nit: \n\n
Devlin
2015/03/24 21:26:26
Done.
| |
| 101 class JsExternGeneratorTest(unittest.TestCase): | |
| 102 def testBasic(self): | |
| 103 filename = 'fake_api.idl' | |
| 104 api_def = idl_schema.Process(fake_idl, filename) | |
| 105 m = model.Model() | |
| 106 namespace = m.AddNamespace(api_def[0], filename) | |
| 107 self.assertEquals(expected_output, | |
| 108 JsExternsGenerator().Generate(namespace).Render()) | |
| 109 | |
|
Dan Beam
2015/03/24 21:19:18
nit: \n\n
Devlin
2015/03/24 21:26:26
Done.
| |
| 110 if __name__ == '__main__': | |
| 111 unittest.main() | |
| OLD | NEW |