From 55d9a312fbba91f1bcf5e3f3291b7bece8abb178 Mon Sep 17 00:00:00 2001 From: Matěj Cepl Date: Thu, 28 Apr 2011 13:28:55 +0200 Subject: Reformatting to MoFo coding style --- tests/pagemod-test-helpers.js | 12 +-- tests/test-color.js | 20 ++-- tests/test-logger.js | 52 ++++----- tests/test-match-pattern.js | 20 ++-- tests/test-pageMod.js | 195 +++++++++++++++++----------------- tests/test-util.js | 240 +++++++++++++++++++++++------------------- tests/test-xmlrpc.js | 39 +++---- 7 files changed, 300 insertions(+), 278 deletions(-) (limited to 'tests') diff --git a/tests/pagemod-test-helpers.js b/tests/pagemod-test-helpers.js index 8621421..9980715 100644 --- a/tests/pagemod-test-helpers.js +++ b/tests/pagemod-test-helpers.js @@ -1,10 +1,10 @@ "use strict"; -const {Cc,Ci} = require("chrome"); - +const Cc = require("chrome").Cc; +const Ci = require("chrome").Ci; /** - * A helper function that creates a PageMod, then opens the specified URL - * and checks the effect of the page mod on 'onload' event via testCallback. + * A helper function that creates a PageMod, then opens the specified URL and + * checks the effect of the page mod on 'onload' event via testCallback. */ exports.testPageMod = function testPageMod(test, testURL, pageModOptions, testCallback, timeout) { @@ -20,7 +20,7 @@ exports.testPageMod = function testPageMod(test, testURL, pageModOptions, var browserWindow = wm.getMostRecentWindow("navigator:browser"); if (!browserWindow) { test.pass("page-mod tests: could not find the browser window, so " + - "will not run. Use -a firefox to run the pagemod tests.") + "will not run. Use -a firefox to run the pagemod tests."); return null; } @@ -44,7 +44,7 @@ exports.testPageMod = function testPageMod(test, testURL, pageModOptions, function onPageLoad() { b.removeEventListener("load", onPageLoad, true); testCallback(b.contentWindow.wrappedJSObject, function done() { - pageMods.forEach(function(mod) mod.destroy()); + pageMods.forEach(function(mod) {mod.destroy()}); // XXX leaks reported if we don't close the tab? tabBrowser.removeTab(newTab); test.done(); diff --git a/tests/test-color.js b/tests/test-color.js index eefb97d..95d3e16 100644 --- a/tests/test-color.js +++ b/tests/test-color.js @@ -1,31 +1,31 @@ /*global exports: false, require: false */ // TODO: add some failing tests as well "use strict"; -//var util = require("color"); +// var util = require("color"); // testing Color object -var ensureColorNew = function (test) { +var ensureColorNew = function(test) { var col = new util.Color(255, 255, 166); test.assertEqual(col.toString(), "#ffffa6", - "creation of new RGB Color object"); + "creation of new RGB Color object"); }; -var ensureColorUpdate = function (test) { +var ensureColorUpdate = function(test) { var col = new util.Color(255, 255, 166); col.update(255, 224, 176); test.assertEqual(col.toString(), "#ffe0b0", - "updating Color object"); + "updating Color object"); }; -var ensureColorHSL = function (test) { +var ensureColorHSL = function(test) { var col = new util.Color(255, 224, 176); test.assertEqual(col.hsl().toSource(), - "[0.10126582278481013, 1, 0.8450980392156863]", - "converting to HSL model"); + "[0.10126582278481013, 1, 0.8450980392156863]", + "converting to HSL model"); }; -var ensureColorLight = function (test) { +var ensureColorLight = function(test) { var col = new util.Color(255, 224, 176); test.assertEqual(col.lightColor().toString(), "#e8dcc9", - "getting a light color"); + "getting a light color"); }; diff --git a/tests/test-logger.js b/tests/test-logger.js index 2b087f8..d814838 100644 --- a/tests/test-logger.js +++ b/tests/test-logger.js @@ -6,34 +6,34 @@ var logMod = require("logger"); var selfMod = require("self"); var testGenerateTimeSheetDataLogs = { - "2010-07-27+bugzilla.redhat.com+533567": { - "date": "2010-07-27T21:28:47.103Z", - "url": "https://bugzilla.redhat.com/show_bug.cgi?id=533567", - "title": "KMS:RS480:X200M - GPU lockup (screen goes black)", - "comment": "removing filled in chip type for Guadec" + "2010-07-27+bugzilla.redhat.com+533567" : { + "date" : "2010-07-27T21:28:47.103Z", + "url" : "https://bugzilla.redhat.com/show_bug.cgi?id=533567", + "title" : "KMS:RS480:X200M - GPU lockup (screen goes black)", + "comment" : "removing filled in chip type for Guadec" }, - "2010-07-27+bugzilla.redhat.com+618769": { - "date": "2010-07-27T21:30:18.845Z", - "url": "https://bugzilla.redhat.com/show_bug.cgi?id=618769", - "title": "gdm and display unstable with ATI FirePro V3700 graphics card", - "comment": "asking for logs" + "2010-07-27+bugzilla.redhat.com+618769" : { + "date" : "2010-07-27T21:30:18.845Z", + "url" : "https://bugzilla.redhat.com/show_bug.cgi?id=618769", + "title" : "gdm and display unstable with ATI FirePro V3700 graphics card", + "comment" : "asking for logs" } }; -var testGenerateTimeSheetResultStr = "\n\n"+ - "TimeSheet-2011-04-17\n\n\n

TimeSheet

\n"+ - "

2010-07-27

\n

"+ - "Bug RH/533567: "+ - "KMS:RS480:X200M - GPU lockup (screen goes black) \n
removing filled "+ - "in chip type for Guadec

\n

Bug RH/618769: "+ - "gdm and display unstable with ATI FirePro V3700 graphics card \n"+ - "
asking for logs

\n"; +var testGenerateTimeSheetResultStr = "\n\n" + + "TimeSheet-2011-04-17\n\n\n

TimeSheet

\n" + + "

2010-07-27

\n

" + + "Bug RH/533567: " + + "KMS:RS480:X200M - GPU lockup (screen goes black) \n
removing filled " + + "in chip type for Guadec

\n

Bug RH/618769: " + + "gdm and display unstable with ATI FirePro V3700 graphics card \n" + + "
asking for logs

\n"; -exports.ensureTimeSheetRecordsPrinter = function (test) { - logMod.initialize(JSON.parse(selfMod.data.load( - "bugzillalabelAbbreviations.json"))) - test.assertEqual(logMod.timeSheetRecordsPrinter(testGenerateTimeSheetDataLogs, - new Date("2011-04-17")), testGenerateTimeSheetResultStr, - "Generates correct log report from given data."); +exports.ensureTimeSheetRecordsPrinter = function(test) { + logMod.initialize(JSON.parse(selfMod.data + .load("bugzillalabelAbbreviations.json"))); + test.assertEqual(logMod.timeSheetRecordsPrinter( + testGenerateTimeSheetDataLogs, new Date("2011-04-17")), + testGenerateTimeSheetResultStr, + "Generates correct log report from given data."); }; - diff --git a/tests/test-match-pattern.js b/tests/test-match-pattern.js index 9e3d2bd..106937a 100644 --- a/tests/test-match-pattern.js +++ b/tests/test-match-pattern.js @@ -1,11 +1,15 @@ -var { MatchPattern } = require("match-pattern"); +var MatchPattern = require("match-pattern").MatchPattern; -exports.ensureMatchPattern = function (test) { - var pattern = new MatchPattern("https://bugzilla.redhat.com/attachment.cgi"); +exports.ensureMatchPattern = function(test) { + var pattern = new MatchPattern( + "https://bugzilla.redhat.com/attachment.cgi"); console.log("pattern = " + pattern); - test.assert(pattern. - test("https://bugzilla.redhat.com/attachment.cgi"), "testing match pattern"); - test.assert(!pattern. - test("https://bugzilla.redhat.com/attachment.cgi?bugid=676538&action=enter"), - "testing failing match pattern"); + test.assert(pattern + .test("https://bugzilla.redhat.com/attachment.cgi"), + "testing match pattern"); + test + .assert( + !pattern + .test("https://bugzilla.redhat.com/attachment.cgi?bugid=676538&action=enter"), + "testing failing match pattern"); }; diff --git a/tests/test-pageMod.js b/tests/test-pageMod.js index 5434bbd..31cb3dd 100644 --- a/tests/test-pageMod.js +++ b/tests/test-pageMod.js @@ -13,126 +13,121 @@ var testURL = self.data.url('tests/change-more-bugs01.html'); var JSONifiedMessage = '{"cmd":"testMessage","data":{"a":"first","b":"second"}}'; exports.ensureMessagesWork = function(test) { - var msg = new utilMod.Message("testMessage", { a: "first", b: "second" } ); + var msg = new utilMod.Message("testMessage", { + a : "first", + b : "second" + }); test.assertEqual(msg.cmd, "testMessage", - "msg.cmd comes over well"); + "msg.cmd comes over well"); test.assertEqual(msg.data.a, "first", - "msg.data.a comes over well"); + "msg.data.a comes over well"); test.assertEqual(msg.data.b, "second", - "msg.data.b comes over well"); + "msg.data.b comes over well"); test.assertEqual(JSON.stringify(msg), JSONifiedMessage, - "JSONification of Message works as well"); + "JSONification of Message works as well"); }; /* + * + * var theURL = main.theURL; var testURL = + * self.data.url('tests/change-more-bugs01.html'); + * + * var contentScriptLibraries = { "bugzilla.redhat.com": [ + * self.data.url("util.js"), self.data.url("color.js"), + * self.data.url("rhbzpage.js"), self.data.url("bzpage.js") ] }; + * + * libbz.initialize(libbz.config, function () { pageMod.PageMod({ include: [ + * "https://bugzilla.redhat.com/show_bug.cgi?id=*" ], contentScriptWhen: + * 'ready', contentScriptFile: contentScriptLibraries["bugzilla.redhat.com"], + * onAttach: function onAttach(worker, msg) { console.log("worker: " + worker); + * worker.on('message', function (msg) { messageHandler(worker, msg); }); } }); + * }); + * + * pageMod.PageMod({ include: [ "https://bugzilla.redhat.com/process_bug.cgi" ], + * contentScriptWhen: 'ready', contentScriptFile: self.data.url("skip-bug.js") + * }); + */ -var theURL = main.theURL; -var testURL = self.data.url('tests/change-more-bugs01.html'); - -var contentScriptLibraries = { - "bugzilla.redhat.com": [ - self.data.url("util.js"), - self.data.url("color.js"), - self.data.url("rhbzpage.js"), - self.data.url("bzpage.js") - ] -}; - -libbz.initialize(libbz.config, function () { - pageMod.PageMod({ - include: [ - "https://bugzilla.redhat.com/show_bug.cgi?id=*" - ], - contentScriptWhen: 'ready', - contentScriptFile: contentScriptLibraries["bugzilla.redhat.com"], - onAttach: function onAttach(worker, msg) { - console.log("worker: " + worker); - worker.on('message', function (msg) { - messageHandler(worker, msg); - }); +var ensureSimplePageLoad = function(test) { + console.log("testURL = " + testURL); + testPageMod(test, testURL, [ + { + include : [ + "*" + ], + contentScriptWhen : 'ready', + contentScriptFile : [ + self.data.url("libPW.js"), + self.data.url("simplePageWorker.js") + ], + onAttach : function onAttach(worker) { + worker.on('message', function(msg) { + switch (msg.cmd) { + case "LogMessage": + log(msg.data); + break; + case "CallBack": + worker + .postMessage(new utilMod.Message("Main", null)); + break; + default: + console.error(msg); + } + }); + } } + ], function(win, done) { + test.assertNotEqual(win.document + .getElementsByTagName("form")[0], null, + "test of loading the page"); + done(); }); -}); - -pageMod.PageMod({ - include: [ - "https://bugzilla.redhat.com/process_bug.cgi" - ], - contentScriptWhen: 'ready', - contentScriptFile: self.data.url("skip-bug.js") -}); - */ - -var ensureSimplePageLoad = function (test) { - console.log("testURL = " + testURL); - testPageMod(test, testURL, [{ - include: ["*"], - contentScriptWhen: 'ready', - contentScriptFile: [ - self.data.url("libPW.js"), - self.data.url("simplePageWorker.js") - ], - onAttach: function onAttach(worker) { - worker.on('message', function (msg) { - switch (msg.cmd) { - case "LogMessage": - log(msg.data); - break; - case "CallBack": - worker.postMessage(new utilMod.Message("Main", null)); - break; - default: - console.error(msg); - } - }); - } - }], - function (win, done) { - test.assertNotEqual(win.document.getElementsByTagName("form")[0], - null, "test of loading the page"); - done(); - }); }; -var ensurePageLoadsWell = function (test) { +var ensurePageLoadsWell = function(test) { var wm = Cc['@mozilla.org/appshell/window-mediator;1'] - .getService(Ci.nsIWindowMediator); - var browserWindow = wm.getMostRecentWindow("navigator:browser"); + .getService(Ci.nsIWindowMediator); + var browserWindow = wm + .getMostRecentWindow("navigator:browser"); if (!browserWindow) { - test.fail("page-mod tests: could not find the browser window, so " + - "will not run. Use -a firefox to run the pagemod tests."); - return null; + test + .fail("page-mod tests: could not find the browser window, so " + + "will not run. Use -a firefox to run the pagemod tests."); + return null; } var loader = test.makeSandboxedLoader(); var pageMod = loader.require("page-mod"); - var testDoc = {}, b = {}, tabBrowser = {}, newTab = {}; + var testDoc = {}, b = {}, tabBrowser = {}, newTab = {}; pageMod.PageMod({ - include: ["*"], - contentScriptWhen: 'ready', - contentScriptFile: [ - self.data.url("libPW.js"), - self.data.url("pageWorker.js") - ], - onAttach: function onAttach(worker) { - worker.on('message', function (msg) { - switch (msg.cmd) { - case "testReady": - testDoc = b.contentWindow.wrappedJSObject.document; - test.assertNotEqual(testDoc.getElementById("dupeid_action"), - null, "test of DOM modifications of the page"); - pageMod.destroy(); - tabBrowser.removeTab(newTab); - test.done(); - // the test itself - break; - default: - main.messageHandler(worker, msg); - } - }); - } - }); + include : [ + "*" + ], + contentScriptWhen : 'ready', + contentScriptFile : [ + self.data.url("libPW.js"), + self.data.url("pageWorker.js") + ], + onAttach : function onAttach(worker) { + worker.on('message', function(msg) { + switch (msg.cmd) { + case "testReady": + testDoc = b.contentWindow.wrappedJSObject.document; + test.assertNotEqual(testDoc + .getElementById("dupeid_action"), null, + "test of DOM modifications of the page"); + pageMod.destroy(); + tabBrowser.removeTab(newTab); + test.done(); + // the test itself + break; + default: + main.messageHandler(worker, msg); + } + }); + } + }); tabBrowser = browserWindow.gBrowser; newTab = tabBrowser.addTab(testURL); diff --git a/tests/test-util.js b/tests/test-util.js index 26c5f6d..7ab6280 100644 --- a/tests/test-util.js +++ b/tests/test-util.js @@ -6,13 +6,13 @@ var util = require("util"); var urlMod = require("url"); // testing util.heir -var ensureHeir = function (test) { +var ensureHeir = function(test) { var fedlimid = {}, naoise = {}; function Father(x) { this.family = x; } - + Father.prototype.getFamily = function getFamily() { return this.family; }; @@ -21,194 +21,216 @@ var ensureHeir = function (test) { Father.call(this, x); this.wife = w; } - + Son.prototype = util.heir(Father); Son.prototype.constructor = Son; - + Son.prototype.getWife = function getWife() { return this.wife; }; - + Son.prototype.getFamily = function getFamily() { - var upFamily = - Father.prototype.getFamily.call(this); + var upFamily = Father.prototype.getFamily.call(this); return upFamily + ", " + this.wife; }; - + // for curious and non-Celtic // http://en.wikipedia.org/wiki/Deirdre :) fedlimid = new Father("mac Daill"); naoise = new Son("Usnech", "Deirdre"); - + test.assertEqual(fedlimid.getFamily(), "mac Daill", - "checking creation of new simple object"); - + "checking creation of new simple object"); + test.assertEqual(naoise.getWife(), "Deirdre", - "checking creation of new daughter object"); + "checking creation of new daughter object"); test.assertEqual(naoise.getFamily(), "Usnech, Deirdre", - "checking creation of new overloaded method"); + "checking creation of new overloaded method"); }; // testing util.isInList -var ensureIsInListTrue = function (test) { - test.assert(util.isInList("a", ["a"]), - "conversion of a string to an array"); +var ensureIsInListTrue = function(test) { + test.assert(util.isInList("a", [ + "a" + ]), "conversion of a string to an array"); }; -var ensureIsInListFalse = function (test) { - test.assert(!util.isInList("b", ["a"]), - "conversion of a string to an array"); +var ensureIsInListFalse = function(test) { + test.assert(!util.isInList("b", [ + "a" + ]), "conversion of a string to an array"); }; -var ensureIsInListEmpty = function (test) { +var ensureIsInListEmpty = function(test) { test.assert(!util.isInList("b", []), - "conversion of a string to an array"); + "conversion of a string to an array"); }; -var ensureIsInListNoMember = function (test) { - test.assert(!util.isInList("", ["x"]), - "conversion of a string to an array"); +var ensureIsInListNoMember = function(test) { + test.assert(!util.isInList("", [ + "x" + ]), "conversion of a string to an array"); }; // testing util.filterByRegexp -var ensureFilterByRegexp = function (test) { +var ensureFilterByRegexp = function(test) { var list = [ - { - "regexp": "test(ing|ed)", - "addr": "correct" - }, - { - "regexp": "ba.*d", - "addr": true - } + { + "regexp" : "test(ing|ed)", + "addr" : "correct" + }, { + "regexp" : "ba.*d", + "addr" : true + } ]; - - test.assertEqual(util.filterByRegexp(list, "testing"), "correct", - "simple testing of filterByRegexp"); - test.assertEqual(util.filterByRegexp(list, "unknown value"), "", - "simple testing of filterByRegexp with non-found address"); - test.assert(util.filterByRegexp(list, "baaad"), - "simple testing of filterByRegexp with non-string return value"); + + test.assertEqual(util.filterByRegexp(list, "testing"), + "correct", "simple testing of filterByRegexp"); + test.assertEqual(util.filterByRegexp(list, "unknown value"), + "", + "simple testing of filterByRegexp with non-found address"); + test + .assert(util.filterByRegexp(list, "baaad"), + "simple testing of filterByRegexp with non-string return value"); }; -var ensureFilterByRegexpEmpty = function (test) { - test.assertRaises(function () { - util.filterByRegexp(undefined, "tralala"); - }, - "list is undefined", - "filterByRegexp throws an exception with empty list"); +var ensureFilterByRegexpEmpty = function(test) { + test.assertRaises(function() { + util.filterByRegexp(undefined, "tralala"); + }, "list is undefined", + "filterByRegexp throws an exception with empty list"); }; // testing util.getISODate -var ensureGetISODate = function (test) { - test.assertEqual(util.getISODate("Mon May 31 2010 23:29:09 GMT+0200 (CET)"), - "2010-05-31", "conversion of a Date to ISO-formatted String"); +var ensureGetISODate = function(test) { + test.assertEqual(util + .getISODate("Mon May 31 2010 23:29:09 GMT+0200 (CET)"), + "2010-05-31", + "conversion of a Date to ISO-formatted String"); }; // testing util.valToArray -var ensureValToArrayString = function (test) { - test.assertEqual(JSON.stringify(util.valToArray("a")), - JSON.stringify(["a"]), - "conversion of a string to an array"); +var ensureValToArrayString = function(test) { + test.assertEqual(JSON.stringify(util.valToArray("a")), JSON + .stringify([ + "a" + ]), "conversion of a string to an array"); }; -var ensureValToArrayEmpty = function (test) { - test.assertEqual(JSON.stringify(util.valToArray("")), - JSON.stringify([""]), - "conversion of an empty string to an array"); +var ensureValToArrayEmpty = function(test) { + test.assertEqual(JSON.stringify(util.valToArray("")), JSON + .stringify([ + "" + ]), "conversion of an empty string to an array"); }; -var ensureValToArrayArray = function (test) { - test.assertEqual(JSON.stringify(util.valToArray(["a"])), - JSON.stringify(["a"]), - "non-conversion of an array"); +var ensureValToArrayArray = function(test) { + test.assertEqual(JSON.stringify(util.valToArray([ + "a" + ])), JSON.stringify([ + "a" + ]), "non-conversion of an array"); }; // testing util.addCSVValue -var ensureCSVAddedToNull = function (test) { +var ensureCSVAddedToNull = function(test) { test.assertEqual(util.addCSVValue("", "b"), "b", - "adding a string to empty string"); + "adding a string to empty string"); }; -var ensureCSVAddedNull = function (test) { +var ensureCSVAddedNull = function(test) { test.assertEqual(util.addCSVValue("a", ""), "a", - "adding nothing to a string"); + "adding nothing to a string"); }; -var ensureCSVAddedString = function (test) { +var ensureCSVAddedString = function(test) { test.assertEqual(util.addCSVValue("a", "b"), "a, b", - "adding one string to another one"); + "adding one string to another one"); }; -var ensureCSVAddedArray = function (test) { - test.assertEqual(util.addCSVValue("a", ["b", "c"]), "a, b, c", - "adding array to a string"); +var ensureCSVAddedArray = function(test) { + test.assertEqual(util.addCSVValue("a", [ + "b", "c" + ]), "a, b, c", "adding array to a string"); }; -var ensureCSVAddedArray2Array = function (test) { - test.assertEqual(util.addCSVValue("a, b", ["c", "d"]), "a, b, c, d", - "adding one array to another"); +var ensureCSVAddedArray2Array = function(test) { + test.assertEqual(util.addCSVValue("a, b", [ + "c", "d" + ]), "a, b, c, d", "adding one array to another"); }; // testing util.removeCSVValue -var ensureCSVRemoveSimple = function (test) { +var ensureCSVRemoveSimple = function(test) { test.assertEqual(util.removeCSVValue("a, b", "b"), "a", - "removing one string from an array"); + "removing one string from an array"); }; // also checking a tolerancy against different ways of writing arrays -var ensureCSVRemoveNonMember = function (test) { - test.assertEqual(util.removeCSVValue("a,b", "c"), "a, b", - "removing a string from an array of which it isn't a member"); +var ensureCSVRemoveNonMember = function(test) { + test + .assertEqual(util.removeCSVValue("a,b", "c"), "a, b", + "removing a string from an array of which it isn't a member"); }; -var ensureCSVRemoveEmpty = function (test) { +var ensureCSVRemoveEmpty = function(test) { test.assertEqual(util.removeCSVValue("", "c"), "", - "removing a string from an empty array"); + "removing a string from an empty array"); }; // testing util.getObjectKeys -var ensureGetObjectKeys = function (test) { +var ensureGetObjectKeys = function(test) { var testObj = { - a: 1, - b: 2 + a : 1, + b : 2 }; test.assertEqual(JSON.stringify(util.getObjectKeys(testObj)), - JSON.stringify(["a", "b"]), - "getting keys from a object"); + JSON.stringify([ + "a", "b" + ]), "getting keys from a object"); }; // testing util.getParamsFromURL -var ensureGetParamsFromURL = function (test) { - test.assertEqual(JSON.stringify(util.getParamsFromURL("https://bugzilla.redhat.com/show_bug.cgi?id=549066")), - JSON.stringify({id:"549066"}), - "simply compare result of bugzilla show_page URL"); - var complexURL = new urlMod.URL("http://www.google.com/search?ie=UTF-8&oe=UTF-8&sourceid=navclient"+ - "&gfns=1&q=gg+javascript+url+parse"); - test.assertEqual(JSON.stringify(util.getParamsFromURL(complexURL)), - JSON.stringify({ - "ie":"UTF-8", - "oe":"UTF-8", - "sourceid":"navclient", - "gfns":"1", - "q":"gg+javascript+url+parse" - }), - "simply compare result of bugzilla show_page URL"); - test.assertEqual(JSON.stringify(util.getParamsFromURL("https://bugzilla.redhat.com/")), - JSON.stringify({}), - "URL without any parameters"); - test.assertRaises(function () {util.getParamsFromURL("");}, - "Missing URL value!", "No URL"); +var ensureGetParamsFromURL = function(test) { + test + .assertEqual( + JSON + .stringify(util + .getParamsFromURL("https://bugzilla.redhat.com/show_bug.cgi?id=549066")), + JSON.stringify({ + id : "549066" + }), "simply compare result of bugzilla show_page URL"); + var complexURL = new urlMod.URL( + "http://www.google.com/search?ie=UTF-8&oe=UTF-8&sourceid=navclient" + + "&gfns=1&q=gg+javascript+url+parse"); + test.assertEqual(JSON.stringify(util + .getParamsFromURL(complexURL)), JSON.stringify({ + "ie" : "UTF-8", + "oe" : "UTF-8", + "sourceid" : "navclient", + "gfns" : "1", + "q" : "gg+javascript+url+parse" + }), "simply compare result of bugzilla show_page URL"); + test.assertEqual(JSON.stringify(util + .getParamsFromURL("https://bugzilla.redhat.com/")), JSON + .stringify({}), "URL without any parameters"); + test.assertRaises(function() { + util.getParamsFromURL(""); + }, "Missing URL value!", "No URL"); }; // testing util.getBugNo -var ensureGetBugNo = function (test) { - var bugNo = util.getBugNo("https://bugzilla.redhat.com/show_bug.cgi?id=597141"); +var ensureGetBugNo = function(test) { + var bugNo = util + .getBugNo("https://bugzilla.redhat.com/show_bug.cgi?id=597141"); test.assertEqual(bugNo, 597141, "getting bug number"); - bugNo = util.getBugNo("https://bugzilla.redhat.com/show_bug.cgi?id=serialWacom"); - test.assertEqual(bugNo, "serialWacom", "getting a bug alias; there is no guarantee of getting number!"); + bugNo = util + .getBugNo("https://bugzilla.redhat.com/show_bug.cgi?id=serialWacom"); + test + .assertEqual(bugNo, "serialWacom", + "getting a bug alias; there is no guarantee of getting number!"); }; diff --git a/tests/test-xmlrpc.js b/tests/test-xmlrpc.js index f3f2e56..78bf9d5 100644 --- a/tests/test-xmlrpc.js +++ b/tests/test-xmlrpc.js @@ -2,21 +2,21 @@ /*jslint plusplus: false */ "use strict"; var xrpc = require("xmlrpc"); -var xmlOut = "\n" + - "\nbugzilla.updateAttachMimeType\n" + - "\n\n\n\nattach_id\n" + - "myId\n\n\n" + - "mime_type\ntext/plain\n\n" + - "\nnomail\nbillg@microsoft.com" + - "\n\n\n\n\n\n" + - "me@example.com\n\n" + - "\nsecret\n\n" + - "\n3.14\n\n" + - "\n1\n\n" + - "\n"; +var xmlOut = "\n" + + "\nbugzilla.updateAttachMimeType\n" + + "\n\n\n\nattach_id\n" + + "myId\n\n\n" + + "mime_type\ntext/plain\n\n" + + "\nnomail\nbillg@microsoft.com" + + "\n\n\n\n\n\n" + + "me@example.com\n\n" + + "\nsecret\n\n" + + "\n3.14\n\n" + + "\n1\n\n" + + "\n"; -exports.ensureLeadingZero = function (test) { - test.assert(typeof(xrpc.leadingZero) == "function"); +exports.ensureLeadingZero = function(test) { + test.assert(typeof (xrpc.leadingZero) == "function"); test.assertEqual(xrpc.leadingZero("1"), "01"); test.assertEqual(xrpc.leadingZero(1), "01"); test.assertEqual(xrpc.leadingZero("11"), "11"); @@ -25,12 +25,13 @@ exports.ensureLeadingZero = function (test) { test.assertEqual(xrpc.leadingZero(111), "111"); test.assertEqual(xrpc.leadingZero("-1"), "-1"); test.assertEqual(xrpc.leadingZero(-1), "-1"); - test.assertEqual(xrpc.leadingZero("zzz"),"zzz"); + test.assertEqual(xrpc.leadingZero("zzz"), "zzz"); }; // testing xrpc.XMLRPCMessage -exports.ensureGenerateXMLRPC = function (test) { - var msg = new xrpc.XMLRPCMessage("bugzilla.updateAttachMimeType"); +exports.ensureGenerateXMLRPC = function(test) { + var msg = new xrpc.XMLRPCMessage( + "bugzilla.updateAttachMimeType"); msg.addParameter({ 'attach_id' : "myId", 'mime_type' : "text/plain", @@ -40,6 +41,6 @@ exports.ensureGenerateXMLRPC = function (test) { msg.addParameter("secret"); msg.addParameter(3.14); msg.addParameter(true); - test.assertEqual(msg.xml(), xmlOut, - "generate XML-RPC message"); + test + .assertEqual(msg.xml(), xmlOut, "generate XML-RPC message"); }; -- cgit