1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
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());
}
}
}
|