blob: 0c1cecb486ebb117ed2a52fefbc36f8a94109452 (
plain)
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
/*
demonstrate some bugs in ejs
tridge <appweb@tridgell.net>
*/
/****************************************
demo a bug in constructing arrays
fix at http://build.samba.org/build.pl?function=diff;tree=samba4;revision=7124
status: FIXED
*****************************************/
function arraybug() {
var a;
println("First with 3 elements");
a = new Array("one", "two", "three");
printVars(a);
assert(a.length == 3);
assert(a[0] == "one");
assert(a[1] == "two");
assert(a[2] == "three");
println("with a array length");
a = new Array(5);
printVars(a);
assert(a.length == 5);
println("\nNow with 1 element");
a = new Array("one");
printVars(a);
assert(a.length == 1);
assert(a[0] == "one");
println("ALL OK");
}
/****************************************
demo a bug in variable arguments
fix at http://build.samba.org/build.pl?function=diff;tree=samba4;revision=7085
status: FIXED
*****************************************/
function argsbug() {
println("we should have been called with 3 arguments");
assert(arguments.length == 3);
assert(arguments[0] == "one");
assert(arguments[1] == "two");
assert(arguments[2] == "three");
}
/****************************************
demo a bug in constructing objects
no fix available yet
status: SUBMITTED
*****************************************/
function MyObj() {
var o = new Object();
o.test = 42;
return o;
}
function objbug() {
println("the docs say you should use 'new'");
var o1 = new MyObj();
var o2 = MyObj();
printVars(o1);
printVars(o2);
assert(o1.test == 42);
assert(o2.test == 42);
}
/*
demo a expression handling bug
status: FIXED
*/
function exprbug() {
var a = new Array(10);
var i;
for (i=0;i<4;i++) {
a[1+(i*2)] = i;
a[2+(i*2)] = i*2;
}
}
/****************************************
demo lack of recursion
fix in http://build.samba.org/build.pl?function=diff;tree=samba4;revision=7127
status: FIXED
*****************************************/
function fibonacci(n) {
if (n < 3) {
return 1;
}
return fibonacci(n-1) + fibonacci(n-2);
}
function recursebug() {
println("First 10 fibonacci numbers:");
for (i=0;i<10;i++) {
println("fibonacci(" + i + ")=" + fibonacci(i));
}
}
/****************************************
demo lack of function variables inside functions
status: FIXED IN SAMBA
*****************************************/
function callback()
{
return "testing";
}
function fnbug(c)
{
s = c();
assert(s == "testing");
}
/****************************************
demo incorrect handling of reserved words in strings
status: SUBMITTED
*****************************************/
function reservedbug()
{
assert("funct" + "ion" == 'function');
}
/****************************************
demo incorrect handling of boolean functions
status: SUBMITTED
*****************************************/
function no()
{
return false;
}
function boolbug()
{
assert(false == no());
assert(!no());
}
/* run the tests */
arraybug();
argsbug("one", "two", "three");
recursebug();
exprbug();
fnbug(callback);
reservedbug();
boolbug();
objbug();
|