More tests and changed 'verify' to live separately.

This commit is contained in:
rogerl%netscape.com 2000-11-07 00:58:42 +00:00
parent ebb9375a31
commit 3e4ebc2d54
10 changed files with 198 additions and 44 deletions

View File

@ -1,4 +1,6 @@
load("verify.js");
function f1(a = 1) { return a; }
@ -36,16 +38,6 @@ function f14(| a, b, c) { return a + b - c; }
function f15(| a, b = 2, c) { return a + b - c; }
count = 0;
function verify(a, b)
{
if (a == b)
print("Test " + count + " succeeded");
else
print("Test " + count + " failed, expected " + b + ", got " + a);
count++;
}
verify( f1(), 1);
verify( f1(2), 2);

View File

@ -0,0 +1,22 @@
load("verify.js");
class C {
var a:String;
constructor C(p:String) {this.a = "New "+p}
constructor make(p:String) {this.a = "Make "+p}
static function obtain(p:String):C {return new C(p)}
}
var c:C = new C("one");
var d:C = C.C("two");
var e:C = C.make("three");
var f:C = C.obtain("four");
verify( c.a, "New one" );
verify( d.a, "New two" );
verify( e.a, "Make three" );
verify( f.a, "New four" );

View File

@ -1,3 +1,6 @@
load("verify.js");
class C {
virtual var x:Integer;
var y:Integer;
@ -8,18 +11,6 @@ override function set x(a:Integer):Integer {return y = a*2}
}
count = 0;
function verify(a, b)
{
if ((a == b) || ((b != b) && (a == undefined)) )
print("Test " + count + " succeeded");
else
print("Test " + count + " failed, expected " + b + ", got " + a);
count++;
}
var c:C = new C;
c.x = 5;

61
js/js2/tests/statics.js Normal file
View File

@ -0,0 +1,61 @@
load("verify.js");
class C {
static var v = "Cv";
static var x = "Cx";
static var y = "Cy";
static var z = "Cz";
}
/*
interface A {
static var x = "Ax";
static var i = "Ai";
static var j = "Aj";
}
interface B {
static var x = "Bx";
static var y = "By";
static var j = "Bj";
}
*/
class D extends C implements A, B {
static var v = "Dv";
}
verify( C.v, "Cv" );
verify( C.x, "Cx" );
verify( C.y, "Cy" );
verify( C.z, "Cz" );
/*
verify( A.x, "Ax" );
verify( B.y, "By" );
*/
verify( D.v, "Dv" );
verify( D.x, "Cx" );
verify( D.y, "Cy" );
verify( D.z, "Cz" );
/*
verify( D.i, "Ai" );
*/
// verify( D.j; // error because of ambiguity: "Aj" or "Bj"?
/*
verify( D.A::j, "Aj" );
verify( D.B::j, "Bj" );
verify( D.A::x, "Ax" );
verify( D.A::i, "Ai" );
*/
D.x = 5;
verify( C.x, 5 );
C.v = 7;
verify( D.v, "Dv" );
verify( C.v, 7 );

11
js/js2/tests/verify.js Normal file
View File

@ -0,0 +1,11 @@
count = 0;
function verify(a, b)
{
if ((a == b) || ((b != b) && (a == undefined)) )
print("Test " + count + " succeeded");
else
print("Test " + count + " failed, expected " + b + ", got " + a);
count++;
}

View File

@ -1,4 +1,6 @@
load("verify.js");
function f1(a = 1) { return a; }
@ -36,16 +38,6 @@ function f14(| a, b, c) { return a + b - c; }
function f15(| a, b = 2, c) { return a + b - c; }
count = 0;
function verify(a, b)
{
if (a == b)
print("Test " + count + " succeeded");
else
print("Test " + count + " failed, expected " + b + ", got " + a);
count++;
}
verify( f1(), 1);
verify( f1(2), 2);

View File

@ -0,0 +1,22 @@
load("verify.js");
class C {
var a:String;
constructor C(p:String) {this.a = "New "+p}
constructor make(p:String) {this.a = "Make "+p}
static function obtain(p:String):C {return new C(p)}
}
var c:C = new C("one");
var d:C = C.C("two");
var e:C = C.make("three");
var f:C = C.obtain("four");
verify( c.a, "New one" );
verify( d.a, "New two" );
verify( e.a, "Make three" );
verify( f.a, "New four" );

View File

@ -1,3 +1,6 @@
load("verify.js");
class C {
virtual var x:Integer;
var y:Integer;
@ -8,18 +11,6 @@ override function set x(a:Integer):Integer {return y = a*2}
}
count = 0;
function verify(a, b)
{
if ((a == b) || ((b != b) && (a == undefined)) )
print("Test " + count + " succeeded");
else
print("Test " + count + " failed, expected " + b + ", got " + a);
count++;
}
var c:C = new C;
c.x = 5;

61
js2/src/tests/statics.js Normal file
View File

@ -0,0 +1,61 @@
load("verify.js");
class C {
static var v = "Cv";
static var x = "Cx";
static var y = "Cy";
static var z = "Cz";
}
/*
interface A {
static var x = "Ax";
static var i = "Ai";
static var j = "Aj";
}
interface B {
static var x = "Bx";
static var y = "By";
static var j = "Bj";
}
*/
class D extends C implements A, B {
static var v = "Dv";
}
verify( C.v, "Cv" );
verify( C.x, "Cx" );
verify( C.y, "Cy" );
verify( C.z, "Cz" );
/*
verify( A.x, "Ax" );
verify( B.y, "By" );
*/
verify( D.v, "Dv" );
verify( D.x, "Cx" );
verify( D.y, "Cy" );
verify( D.z, "Cz" );
/*
verify( D.i, "Ai" );
*/
// verify( D.j; // error because of ambiguity: "Aj" or "Bj"?
/*
verify( D.A::j, "Aj" );
verify( D.B::j, "Bj" );
verify( D.A::x, "Ax" );
verify( D.A::i, "Ai" );
*/
D.x = 5;
verify( C.x, 5 );
C.v = 7;
verify( D.v, "Dv" );
verify( C.v, 7 );

11
js2/src/tests/verify.js Normal file
View File

@ -0,0 +1,11 @@
count = 0;
function verify(a, b)
{
if ((a == b) || ((b != b) && (a == undefined)) )
print("Test " + count + " succeeded");
else
print("Test " + count + " failed, expected " + b + ", got " + a);
count++;
}