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

Unified Diff: tools/json_schema_compiler/js_externs_generator_test.py

Issue 1015033003: [Extension API Extern Generation] Auto-generate enums (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Tyler's 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/json_schema_compiler/js_externs_generator.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/json_schema_compiler/js_externs_generator_test.py
diff --git a/tools/json_schema_compiler/js_externs_generator_test.py b/tools/json_schema_compiler/js_externs_generator_test.py
new file mode 100755
index 0000000000000000000000000000000000000000..4cd294e300ffa4c475d0a41403b8d1ab260cc832
--- /dev/null
+++ b/tools/json_schema_compiler/js_externs_generator_test.py
@@ -0,0 +1,111 @@
+#!/usr/bin/env python
+# Copyright 2015 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import idl_schema
+from js_externs_generator import JsExternsGenerator
+from datetime import datetime
+import model
+import unittest
+
Dan Beam 2015/03/24 21:19:18 nit: \n\n
Devlin 2015/03/24 21:26:26 Done.
+# The contents of a fake idl file.
+fake_idl = """
+// Copyright %s The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// A totally fake API.
+namespace fakeApi {
+ enum Greek {
+ ALPHA,
+ BETA,
+ GAMMA,
+ DELTA
+ };
+
+ dictionary Bar {
+ long num;
+ };
+
+ dictionary Baz {
+ DOMString str;
+ long num;
+ boolean b;
+ Greek letter;
+ long[] arr;
+ Bar obj;
+ long? maybe;
+ };
+
+ callback VoidCallback = void();
+
+ interface Functions {
+ // Does something exciting!
+ // |baz| : The baz to use.
+ static void doSomething(Baz baz, optional VoidCallback callback);
+ };
+};
+"""
+
+# The output we expect from our fake idl file.
+expected_output = """// Copyright %s The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+/** @fileoverview Externs generated from namespace: fakeApi */
+
+/**
+ * @const
+ */
+chrome.fakeApi = {};
+
+/**
+ * @enum {string}
+ */
+chrome.fakeApi.Greek = {
+ ALPHA: 'ALPHA',
+ BETA: 'BETA',
+ GAMMA: 'GAMMA',
+ DELTA: 'DELTA',
+};
+
+/**
+ * @typedef {{
+ * num: number
+ * }}
+ */
+var Bar;
+
+/**
+ * @typedef {{
+ * str: string,
+ * num: number,
+ * b: boolean,
+ * letter: chrome.fakeApi.Greek,
+ * arr: Array,
+ * obj: Bar,
+ * maybe: (number|undefined)
+ * }}
+ */
+var Baz;
+
+/**
+ * Does something exciting!
+ * @param {Baz} baz The baz to use.
+ * @param {Function=} callback
+ */
+chrome.fakeApi.doSomething = function(baz, callback) {};
+""" % datetime.now().year
+
Dan Beam 2015/03/24 21:19:18 nit: \n\n
Devlin 2015/03/24 21:26:26 Done.
+class JsExternGeneratorTest(unittest.TestCase):
+ def testBasic(self):
+ filename = 'fake_api.idl'
+ api_def = idl_schema.Process(fake_idl, filename)
+ m = model.Model()
+ namespace = m.AddNamespace(api_def[0], filename)
+ self.assertEquals(expected_output,
+ JsExternsGenerator().Generate(namespace).Render())
+
Dan Beam 2015/03/24 21:19:18 nit: \n\n
Devlin 2015/03/24 21:26:26 Done.
+if __name__ == '__main__':
+ unittest.main()
« 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