aboutsummaryrefslogtreecommitdiffstats
path: root/test/testAll.js
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@redhat.com>2013-05-13 15:48:02 +0200
committerMatěj Cepl <mcepl@redhat.com>2013-05-13 21:27:37 +0200
commitf23003947b2b34644cdedf9fd9699d8173b20ac7 (patch)
tree04fcd591a2097f65a4f64f2a51c8cee6a3625acb /test/testAll.js
parent22afe0326408b03551b655aee52d151cef442b9e (diff)
downloadparseLDIF-f23003947b2b34644cdedf9fd9699d8173b20ac7.tar.gz
Add a simple testsuite.
Example files from RFC2849
Diffstat (limited to 'test/testAll.js')
-rwxr-xr-xtest/testAll.js106
1 files changed, 106 insertions, 0 deletions
diff --git a/test/testAll.js b/test/testAll.js
new file mode 100755
index 0000000..9aabd43
--- /dev/null
+++ b/test/testAll.js
@@ -0,0 +1,106 @@
+#!/usr/bin/rhino
+
+load("../parseLDIF.js");
+
+Object.prototype.equals = function(x) {
+ var p;
+ for(p in this) {
+ if(typeof(x[p])=='undefined') {return false;}
+ }
+
+ for(p in this) {
+ if (this[p]) {
+ switch(typeof(this[p])) {
+ case 'object':
+ if (!this[p].equals(x[p])) { return false; } break;
+ case 'function':
+ if (typeof(x[p])=='undefined' ||
+ (p != 'equals' && this[p].toString() != x[p].toString()))
+ return false;
+ break;
+ default:
+ if (this[p] != x[p]) { return false; }
+ }
+ } else {
+ if (x[p])
+ return false;
+ }
+ }
+
+ for(p in x) {
+ if(typeof(this[p])=='undefined') {return false;}
+ }
+
+ return true;
+}
+
+var observed = {};
+var expResults = {
+ 1: [
+ {
+ cn: ["Barbara Jensen", "Barbara J Jensen", "Babs Jensen"],
+ sn:"Jensen",
+ telephoneNumber:"+1 408 555 1212",
+ description:"A big sailing fan."
+ },
+ {
+ cn:"Bjorn Jensen",
+ sn:"Jensen",
+ telephoneNumber:"+1 408 555 1212"
+ }
+ ],
+ 2: [
+ {
+ cn: ["Barbara Jensen", "Barbara J Jensen", "Babs Jensen"],
+ sn:"Jensen",
+ telephoneNumber:"+1 408 555 1212",
+ description:'Babs is a big sailing fan, and travels extensively in ' +
+ 'search of perfect sailing conditions.',
+ title:"Product Manager, Rod and Reel Division"
+ }
+ ],
+ 3: [
+ {
+ cn: ["Gern Jensen", "Gern O Jensen"],
+ sn:"Jensen",
+ telephoneNumber:"+1 408 555 1212",
+ description:'What a careful reader you are! This value is base-64-encoded' +
+ ' because it has a control character in it (a CR).\r By the way,' +
+ ' you should really get out more.'
+ }
+ ],
+ 4: [
+ {
+ mail:"rogasawara@airius.co.jp",
+ givenname:"ロドニー",
+ sn: "小笠原",
+ cn:"小笠原 ロドニー",
+ title:"営業部 部長",
+ }
+ ],
+ 5: [
+ {
+ cn: ["Horatio Jensen", "Horatio N Jensen"],
+ sn:"Jensen",
+ telephoneNumber:"+1 408 555 1212"
+ }
+ ]
+};
+
+var resultsCount = Object.keys(expResults).length;
+
+for (var key in expResults) {
+ if (expResults.hasOwnProperty(key)) {
+ var lines = readFile("example0" + key + ".ldif").replace(/\r\n/g,"\n");
+ observed = parseLDIF(lines.split("\n"));
+ if (observed.equals(expResults[key])) {
+ print(key + "/" + resultsCount + " ... OK");
+ }
+ else {
+ print("Test " + key + " fails! Expected:\n" +
+ expResults[key].toSource() +
+ "\n----\nObserved:\n" + observed.toSource());
+ }
+ }
+}
+