aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@redhat.com>2010-07-20 12:22:10 +0200
committerMatěj Cepl <mcepl@redhat.com>2010-07-20 12:22:10 +0200
commit0b74818ba503207595d56fa91c70ba3e83a481af (patch)
tree2b9bc1ebb709e76b369cd225611a440f7d919eb8
parent5405da4f392988c0d396afd33be049ae64045c63 (diff)
downloadbugzilla-triage-0b74818ba503207595d56fa91c70ba3e83a481af.tar.gz
Add util.getObjectKeys for better diagnostic.
-rw-r--r--lib/util.js19
-rw-r--r--tests/test-util.js14
2 files changed, 25 insertions, 8 deletions
diff --git a/lib/util.js b/lib/util.js
index 4648ee9..4f3964e 100644
--- a/lib/util.js
+++ b/lib/util.js
@@ -1,4 +1,4 @@
-/*global exports: false, require: false, console: false */
+/*global exports: false, require: false, console: false, Cc: false, Ci: false */
/*jslint onevar: false */
// Released under the MIT/X11 license
// http://www.opensource.org/licenses/mit-license.php
@@ -28,12 +28,11 @@ var {Cc,Ci} = require("chrome");
* </pre>
*/
exports.heir = function heir(p) {
- function f() {};
- f.prototype = p.prototype;
- return new f();
+ function F() {};
+ F.prototype = p.prototype;
+ return new F();
};
-
exports.getBugNo = function getBugNo(url) {
var re = new RegExp(".*id=([0-9]+).*$");
var bugNo = null;
@@ -187,3 +186,13 @@ var filterByRegexp = exports.filterByRegexp =
return "";
}
};
+
+exports.getObjectKeys = function getObjectKeys(obj) {
+ var keys = [];
+ for (var key in obj) {
+ if (obj.hasOwnProperty(key)) {
+ keys.push(key);
+ }
+ }
+ return keys;
+}; \ No newline at end of file
diff --git a/tests/test-util.js b/tests/test-util.js
index c2214d6..54896ff 100644
--- a/tests/test-util.js
+++ b/tests/test-util.js
@@ -4,9 +4,6 @@
"use strict";
var util = require("util");
-var testString = "When in the Course of human events it becomes necessary for one people to dissolve the political bands which have connected them with another and to assume among the powers of the earth, the separate and equal station to which the Laws of Nature and of Nature's God entitle them, a decent respect to the opinions of mankind requires that they should declare the causes which impel them to the separation.\n";
-var pushkinTestString = "Byl pozdní večer první máj!\n\nАРИОН.\n\nНас было много на челне;\nИные парус напрягали,\nДругие дружно упирали\nВ глубь мощны веслы. В тишине\nНа руль склонясь, наш кормщик умный\nВ молчаньи правил грузный чолн;\nА я — беспечной веры полн —\nПловцам я пел … Вдруг лоно волн\nИзмял с налету вихорь шумный …\nПогиб и кормщик и пловец! –\nЛишь я, таинственный певец,\nНа берег выброшен грозою,\nЯ гимны прежние пою\nИ ризу влажную мою\nСушу на солнце под скалою.\n"
-
// testing util.heir
exports.ensureHeir = function (test) {
var fedlimid = {}, naoise = {};
@@ -169,4 +166,15 @@ exports.ensureCSVRemoveEmpty = function (test) {
exports.ensureGetBugNo = function (test) {
var bugNo = util.getBugNo("https://bugzilla.redhat.com/show_bug.cgi?id=597141");
test.assertEqual(bugNo, 597141, "getting bug number");
+};
+
+// testing util.getObjectKeys
+exports.ensureGetObjectKeys = function (test) {
+ var testObj = {
+ a: 1,
+ b: 2
+ };
+ test.assertEqual(JSON.stringify(util.getObjectKeys(testObj)),
+ JSON.stringify(["a","b"]),
+ "getting keys from a object");
}; \ No newline at end of file