aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test-util.js
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test-util.js')
-rw-r--r--tests/test-util.js75
1 files changed, 73 insertions, 2 deletions
diff --git a/tests/test-util.js b/tests/test-util.js
index c97776a..552868f 100644
--- a/tests/test-util.js
+++ b/tests/test-util.js
@@ -4,6 +4,12 @@
"use strict";
var util = require("util");
+var pushkinTestString = "Byl pozdní večer první máj!\n\n" +
+ "Нас было много на челне;\nИные парус напрягали,\nДругие дружно упирали\n\n" +
+ "В глубь мощны веслы. В тишине\nНа руль склонясь, наш кормщик умный\n" +
+ "В молчаньи правил грузный чолн;\nА я — беспечной веры полн —\n" +
+ "Пловцам я пел....";
+
// shamelessly stolen from
// http://www.breakingpar.com/bkp/home.nsf/0/87256B280015193F87256BFB0077DFFD
var areArraysEqual = function areArraysEqual(array1, array2) {
@@ -42,12 +48,51 @@ var areArraysEqual = function areArraysEqual(array1, array2) {
return true;
};
+// testing util.isInList
+exports.ensureIsInListTrue = function (test) {
+ test.assert(util.isInList("a", ["a"]),
+ "conversion of a string to an array");
+};
+
+exports.ensureIsInListFalse = function (test) {
+ test.assert(!util.isInList("b", ["a"]),
+ "conversion of a string to an array");
+};
+
+exports.ensureIsInListEmpty = function (test) {
+ test.assert(!util.isInList("b", []),
+ "conversion of a string to an array");
+};
+
+exports.ensureIsInListNoMember = function (test) {
+ test.assert(!util.isInList("", ["x"]),
+ "conversion of a string to an array");
+};
+
+// testing util.getISODate
+exports.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
-exports.ensureValToArray = function (test) {
+exports.ensureValToArrayString = function (test) {
test.assert(areArraysEqual(util.valToArray("a"), ["a"]),
"conversion of a string to an array");
};
+// TODO: somehow cannot pass array as a parameter
+// waiting on https://bugzilla.mozilla.org/show_bug.cgi?id=569273
+//exports.ensureValToArrayEmpty = function (test) {
+// test.assert(areArraysEqual(util.valToArray(""), [""]),
+// "conversion of a string to an array");
+//};
+
+//exports.ensureValToArrayArray = function (test) {
+// test.assert(areArraysEqual(util.valToArray("a"), ["a"]),
+// "conversion of a string to an array");
+//};
+
// testing util.addCSVValue
exports.ensureCSVAddedToNull = function (test) {
test.assertEqual(util.addCSVValue("", "b"), "b",
@@ -81,8 +126,9 @@ exports.ensureCSVRemoveSimple = function (test) {
};
+// also checking a tolerancy against different ways of writing arrays
exports.ensureCSVRemoveNonMember = function (test) {
- test.assertEqual(util.removeCSVValue("a, b", "c"), "a, b",
+ test.assertEqual(util.removeCSVValue("a,b", "c"), "a, b",
"removing a string from an array of which it isn't a member");
};
@@ -92,3 +138,28 @@ exports.ensureCSVRemoveEmpty = function (test) {
"removing a string from an empty array");
};
+
+// testing util.getBugNo
+exports.ensureGetBugNo = function (test) {
+ var bugNo = util.getBugNo("https://bugzilla.redhat.com/show_bug.cgi?id=597141");
+ test.assertEqual(bugNo, 597141, "getting bug number");
+};
+
+// TODO: waiting on https://bugzilla.mozilla.org/show_bug.cgi?id=569271
+//// testing util.loadText
+//exports.ensureLoadText = function (test) {
+// var url = "http://www.ceplovi.cz/matej/progs/data/pushkin.txt";
+// var text = "";
+// util.loadText(url,function(txt) {
+// test.assertEqual(txt,pushkinTestString);
+// });
+//};
+
+//// testing util.loadJSON
+//exports.ensureLoadJSON = function (test) {
+// var url = "http://www.ceplovi.cz/matej/progs/data/test.json";
+// var date = {};
+// util.loadJSON(url,function(data) {
+// test.assertEqual(data,[1,2,3]);
+// });
+//};