------ Prefix ------
extern dynamic Console;
var x = new string[];
x.push("Hello");
x.push("World");
x.splice(1, 0, "There");
for (int i=0; i<x.length; i++)
Console.WriteLine(x[i]);
------ Expected Output ------
Hello
There
World
------ Generated JavaScript ------
(function() {
// Start Global Code
var x=[];
x.push("Hello");
x.push("World");
x.splice(1, 0, "There");
for (var i=0; i<x.length; i++)
Console.WriteLine(x[i]);
})();
------ Actual Output ------
Hello
There
World
Test passed!
------ Prefix ------
extern dynamic Console;
void dump(int[] arr)
{
Console.WriteLine("[" + arr.join(",") + "]");
}
var x = new int[];
x.push(1);
x.push(2);
dump(x);
var y = new int[];
y.push(3);
y.push(4);
dump(y);
var z= x.concat(y);
dump(z);
z.reverse();
dump(z);
dump(z.slice(1,3));
dump(z.slice(1));
z.push(5,6,7,8);
dump(z);
z.splice(2,1,98,99);
dump(z);
------ Expected Output ------
[1,2]
[3,4]
[1,2,3,4]
[4,3,2,1]
[3,2]
[3,2,1]
[4,3,2,1,5,6,7,8]
[4,3,98,99,1,5,6,7,8]
------ Generated JavaScript ------
(function() {
function dump(arr)
{
Console.WriteLine("[" + arr.join(",") + "]");
};
// Start Global Code
var x=[];
x.push(1);
x.push(2);
dump(x);
var y=[];
y.push(3);
y.push(4);
dump(y);
var z=x.concat(y);
dump(z);
z.reverse();
dump(z);
dump(z.slice(1, 3));
dump(z.slice(1));
z.push(5, 6, 7, 8);
dump(z);
z.splice(2, 1, 98, 99);
dump(z);
})();
------ Actual Output ------
[1,2]
[3,4]
[1,2,3,4]
[4,3,2,1]
[3,2]
[3,2,1]
[4,3,2,1,5,6,7,8]
[4,3,98,99,1,5,6,7,8]
Test passed!
------ Prefix ------
// should not generate: instanceof
extern dynamic Console;
class Foo
{
}
class Bar : Foo
{
}
Bar x = new Bar();
Foo y = x as Foo;
Console.WriteLine((y!=null).toString());
------ Expected Output ------
true
------ Generated JavaScript ------
(function() {
// class Foo
var Foo = function() {};
Foo.typeName = 'Foo';
// class Bar
var Bar = function() {};
Bar.typeName = 'Bar';
Bar.prototype = new Foo();
Bar.prototype.constructor = Bar;
// Start Global Code
var x=new Bar();
var y=x;
Console.WriteLine((y!==null).toString());
})();
------ Actual Output ------
true
Test passed!
------ Prefix ------
// should generate: instanceof
extern dynamic Console;
class Foo
{
}
class Bar : Foo
{
}
Foo x = new Bar();
Bar y = x as Bar;
Console.WriteLine((y!=null).toString());
------ Expected Output ------
true
------ Generated JavaScript ------
(function() {
// class Foo
var Foo = function() {};
Foo.typeName = 'Foo';
// class Bar
var Bar = function() {};
Bar.typeName = 'Bar';
Bar.prototype = new Foo();
Bar.prototype.constructor = Bar;
// Start Global Code
var $temp;
var x=new Bar();
var y=(($temp=x) instanceof Bar) ? $temp : null;
Console.WriteLine((y!==null).toString());
})();
------ Actual Output ------
true
Test passed!
------ Prefix ------
// should generate: instanceof
extern dynamic Console;
class Foo
{
}
class Bar : Foo
{
}
Foo x = new Bar();
Foo GetIt()
{
Console.WriteLine("GetIt");
return x;
}
Bar y = GetIt() as Bar;
Console.WriteLine((y!=null).toString());
------ Expected Output ------
GetIt
true
------ Generated JavaScript ------
(function() {
// class Foo
var Foo = function() {};
Foo.typeName = 'Foo';
// class Bar
var Bar = function() {};
Bar.typeName = 'Bar';
Bar.prototype = new Foo();
Bar.prototype.constructor = Bar;
function GetIt()
{
Console.WriteLine("GetIt");
return x;
};
// Start Global Code
var $temp;
var x=new Bar();
var y=(($temp=GetIt()) instanceof Bar) ? $temp : null;
Console.WriteLine((y!==null).toString());
})();
------ Actual Output ------
GetIt
true
Test passed!
------ Prefix ------
// should generate: instanceof
extern dynamic Console;
class Foo
{
}
class Bar : Foo
{
}
class Apple : Foo
{
}
Foo x = new Bar();
Apple y = x as Apple;
Console.WriteLine((y!=null).toString());
------ Expected Output ------
false
------ Generated JavaScript ------
(function() {
// class Foo
var Foo = function() {};
Foo.typeName = 'Foo';
// class Bar
var Bar = function() {};
Bar.typeName = 'Bar';
Bar.prototype = new Foo();
Bar.prototype.constructor = Bar;
// class Apple
var Apple = function() {};
Apple.typeName = 'Apple';
Apple.prototype = new Foo();
Apple.prototype.constructor = Apple;
// Start Global Code
var $temp;
var x=new Bar();
var y=(($temp=x) instanceof Apple) ? $temp : null;
Console.WriteLine((y!==null).toString());
})();
------ Actual Output ------
false
Test passed!
------ Prefix ------
// should not generate: instanceof
extern dynamic Console;
class Foo
{
}
class Bar : Foo
{
}
Bar x = new Bar();
Console.WriteLine((x is Foo).toString());
------ Expected Output ------
true
------ Generated JavaScript ------
(function() {
// class Foo
var Foo = function() {};
Foo.typeName = 'Foo';
// class Bar
var Bar = function() {};
Bar.typeName = 'Bar';
Bar.prototype = new Foo();
Bar.prototype.constructor = Bar;
// Start Global Code
var x=new Bar();
Console.WriteLine(((x)!==null).toString());
})();
------ Actual Output ------
true
Test passed!
------ Prefix ------
// should generate: instanceof
extern dynamic Console;
class Foo
{
}
class Bar : Foo
{
}
class Apple : Foo
{
}
Foo x = new Bar();
Console.WriteLine((x is Apple).toString());
------ Expected Output ------
false
------ Generated JavaScript ------
(function() {
// class Foo
var Foo = function() {};
Foo.typeName = 'Foo';
// class Bar
var Bar = function() {};
Bar.typeName = 'Bar';
Bar.prototype = new Foo();
Bar.prototype.constructor = Bar;
// class Apple
var Apple = function() {};
Apple.typeName = 'Apple';
Apple.prototype = new Foo();
Apple.prototype.constructor = Apple;
// Start Global Code
var x=new Bar();
Console.WriteLine((x instanceof Apple).toString());
})();
------ Actual Output ------
false
Test passed!
------ Prefix ------
// should generate: instanceof
extern dynamic Console;
class Foo
{
}
class Bar : Foo
{
}
Foo x = new Bar();
Console.WriteLine((x is Bar).toString());
------ Expected Output ------
true
------ Generated JavaScript ------
(function() {
// class Foo
var Foo = function() {};
Foo.typeName = 'Foo';
// class Bar
var Bar = function() {};
Bar.typeName = 'Bar';
Bar.prototype = new Foo();
Bar.prototype.constructor = Bar;
// Start Global Code
var x=new Bar();
Console.WriteLine((x instanceof Bar).toString());
})();
------ Actual Output ------
true
Test passed!
------ Prefix ------
// should generate: instanceof
extern dynamic Console;
class Foo
{
}
class Bar : Foo
{
}
Foo x = new Bar();
Foo GetIt()
{
Console.WriteLine("GetIt");
return x;
}
Console.WriteLine((GetIt() is Bar).toString());
------ Expected Output ------
GetIt
true
------ Generated JavaScript ------
(function() {
// class Foo
var Foo = function() {};
Foo.typeName = 'Foo';
// class Bar
var Bar = function() {};
Bar.typeName = 'Bar';
Bar.prototype = new Foo();
Bar.prototype.constructor = Bar;
function GetIt()
{
Console.WriteLine("GetIt");
return x;
};
// Start Global Code
var x=new Bar();
Console.WriteLine((GetIt() instanceof Bar).toString());
})();
------ Actual Output ------
GetIt
true
Test passed!
------ Prefix ------
class Foo
{
}
string x=(string)new Foo();
------ Expected Output ------
// exception: cannot convert
------ Actual Exception ------
Tests.CastExplicit.cant_cast_object_to_primitive.txt(5,18): cannot convert class 'Foo' to class 'System.String'
Test passed!
------ Prefix ------
class Foo
{
}
Foo x=(Foo)"OK";
------ Expected Output ------
// exception: cannot convert
------ Actual Exception ------
Tests.CastExplicit.cant_cast_primitive_to_object.txt(5,12): cannot convert class 'System.String' to class 'Foo'
Test passed!
------ Prefix ------
// no warnings
class Foo
{
}
class Bar : Foo
{
}
Bar x = null;
Foo y = (Foo)x;
------ Expected Output ------
------ Generated JavaScript ------
(function() {
// class Foo
var Foo = function() {};
Foo.typeName = 'Foo';
// class Bar
var Bar = function() {};
Bar.typeName = 'Bar';
Bar.prototype = new Foo();
Bar.prototype.constructor = Bar;
// Start Global Code
var x=null;
var y=x;
})();
------ Actual Output ------
Test passed!
------ Prefix ------
// no warnings
class Foo
{
}
class Bar : Foo
{
}
Bar x = null;
Foo y = x;
------ Expected Output ------
------ Generated JavaScript ------
(function() {
// class Foo
var Foo = function() {};
Foo.typeName = 'Foo';
// class Bar
var Bar = function() {};
Bar.typeName = 'Bar';
Bar.prototype = new Foo();
Bar.prototype.constructor = Bar;
// Start Global Code
var x=null;
var y=x;
})();
------ Actual Output ------
Test passed!
------ Prefix ------
// no warnings
class Foo
{
}
class Bar : Foo
{
}
Foo x = null;
Bar y = (Bar)x;
------ Expected Output ------
------ Generated JavaScript ------
(function() {
// class Foo
var Foo = function() {};
Foo.typeName = 'Foo';
// class Bar
var Bar = function() {};
Bar.typeName = 'Bar';
Bar.prototype = new Foo();
Bar.prototype.constructor = Bar;
// Start Global Code
var x=null;
var y=x;
})();
------ Actual Output ------
Test passed!
------ Prefix ------
class Foo
{
}
class Bar : Foo
{
}
Foo x = null;
Bar y = x;
------ Expected Output ------
// exception: cannot implicitly convert
------ Actual Exception ------
Tests.CastExplicit.cast_to_derived_required.txt(10,9): cannot implicitly convert class 'Foo' to class 'Bar'
Test passed!
------ Prefix ------
extern dynamic Console;
double x=23;
int y = (int)x;
Console.WriteLine(y.toString());
------ Expected Output ------
23
------ Generated JavaScript ------
(function() {
// Start Global Code
var x=23;
var y=(x)|0;
Console.WriteLine(y.toString());
})();
------ Actual Output ------
23
Test passed!
------ Prefix ------ double x = 23; int y = x; ------ Expected Output ------ // exception: cannot implicitly convert ------ Actual Exception ------ Tests.CastExplicit.double_to_int_requires_cast.txt(2,9): cannot implicitly convert class 'System.Double' to class 'System.Integer' Test passed!
------ Prefix ------
extern dynamic Console;
double x=23.9;
int y = (int)x;
Console.WriteLine(y.toString());
------ Expected Output ------
23
------ Generated JavaScript ------
(function() {
// Start Global Code
var x=23.9;
var y=(x)|0;
Console.WriteLine(y.toString());
})();
------ Actual Output ------
23
Test passed!
------ Prefix ------
extern dynamic Console;
class Foo {}
dynamic dyn_foo = (dynamic)"string";
Foo foo = dyn_foo;
------ Expected Output ------
// exception: cannot implicitly convert class 'System.Dynamic' to
------ Actual Exception ------
Tests.CastExplicit.from_dynamic.txt(6,11): cannot implicitly convert class 'System.Dynamic' to class 'Foo'
Test passed!
------ Prefix ------
extern dynamic Console;
class Foo
{
public string x="OK";
}
dynamic dyn_foo = (dynamic)new Foo();
Foo foo = (Foo)dyn_foo;
Console.WriteLine(foo.x);
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// class Foo
var Foo = function() {};
Foo.typeName = 'Foo';
Foo.prototype.x = "OK";
// Start Global Code
var dyn_foo=new Foo();
var foo=dyn_foo;
Console.WriteLine(foo.x);
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
extern dynamic Console;
int x=23;
double y = (double)x;
Console.WriteLine(y.toString());
------ Expected Output ------
23
------ Generated JavaScript ------
(function() {
// Start Global Code
var x=23;
var y=x;
Console.WriteLine(y.toString());
})();
------ Actual Output ------
23
Test passed!
------ Prefix ------
extern dynamic Console;
int x=23;
double y = x;
Console.WriteLine(y.toString());
------ Expected Output ------
23
------ Generated JavaScript ------
(function() {
// Start Global Code
var x=23;
var y=x;
Console.WriteLine(y.toString());
})();
------ Actual Output ------
23
Test passed!
------ Prefix ------
// no warnings
extern dynamic Console;
class Foo
{
public string x="OK";
}
dynamic foo = (dynamic)new Foo();
Console.WriteLine(foo.x);
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// class Foo
var Foo = function() {};
Foo.typeName = 'Foo';
Foo.prototype.x = "OK";
// Start Global Code
var foo=new Foo();
Console.WriteLine(foo.x);
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
// no warnings
extern dynamic Console;
class Foo
{
public string x="OK";
}
dynamic foo = new Foo();
Console.WriteLine(foo.x);
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// class Foo
var Foo = function() {};
Foo.typeName = 'Foo';
Foo.prototype.x = "OK";
// Start Global Code
var foo=new Foo();
Console.WriteLine(foo.x);
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
extern dynamic Console;
class Foo
{
public string fn1()
{
return fn2();
}
string fn2()
{
return prop1;
}
string prop1
{
get
{
return _field1;
}
}
string _field1 = "OK";
}
Console.WriteLine(new Foo().fn1());
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// class Foo
var Foo = function() {};
Foo.typeName = 'Foo';
Foo.prototype._field1 = "OK";
Foo.prototype.fn1 = function()
{
return this.fn2();
};
Foo.prototype.fn2 = function()
{
return this.get_prop1();
};
Foo.prototype.get_prop1 = function()
{
return this._field1;
};
// Start Global Code
Console.WriteLine((new Foo()).fn1());
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
extern dynamic Console;
abstract class Foo
{
}
Console.WriteLine(new Foo());
------ Expected Output ------
// exception: as it is marked as abstract
------ Actual Exception ------
Tests.Classes.cant_construct_abstract_classes.txt(7,19): Can't instantiate class 'Foo' as it is marked as abstract
Test passed!
------ Prefix ------
class A : B
{
}
class B : C
{
}
class C : D
{
}
class D : A
{
}
------ Expected Output ------
// exception: circular base class dependency
------ Actual Exception ------
Tests.Classes.cant_have_circular_base_class_dependency.txt(13,1): class 'D': has a circular base class dependency through base class 'A'
Test passed!
------ Prefix ------
class A : B
{
}
class B : A
{
}
------ Expected Output ------
// exception: circular base class dependency
------ Actual Exception ------
Tests.Classes.cant_have_circular_base_class_dependency_2.txt(5,1): class 'B': has a circular base class dependency through base class 'A'
Test passed!
------ Prefix ------
// no warnings
class Foo
{
string Foo;
}
------ Expected Output ------
// exception: member names cannot be the same as their enclosing type
------ Actual Exception ------
Tests.Classes.field_name_cant_be_same_as_class_name.txt(4,2): MemberVariable Foo: member names cannot be the same as their enclosing type
Test passed!
------ Prefix ------
// should generate: Foo.prototype.str = "OK";
// should not generate: this.str =
extern dynamic Console;
class Foo
{
public string str = "OK";
}
Console.WriteLine(new Foo().str);
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// class Foo
var Foo = function() {};
Foo.typeName = 'Foo';
Foo.prototype.str = "OK";
// Start Global Code
Console.WriteLine((new Foo()).str);
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
// should not generate: Foo.prototype._bar = new Bar()
// should generate: this._bar = new Bar()
extern dynamic Console;
class Bar
{
public string get()
{
return "OK";
}
}
class Foo
{
public Bar _bar = new Bar();
}
Console.WriteLine(new Foo()._bar.get());
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// class Bar
var Bar = function() {};
Bar.typeName = 'Bar';
Bar.prototype.get = function()
{
return "OK";
};
// class Foo
var Foo = function()
{
this._bar = new Bar();
};
Foo.typeName = 'Foo';
Foo.prototype._bar = null;
// Start Global Code
Console.WriteLine((new Foo())._bar.get());
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
// should not generate: Foo.prototype._bar = new Bar()
// should generate: this._bar = new Bar()
extern dynamic Console;
class Bar
{
public string get()
{
return "OK";
}
}
class Foo
{
public Foo(string x)
{
}
public Bar _bar = new Bar();
}
Console.WriteLine(new Foo("Hi")._bar.get());
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// class Bar
var Bar = function() {};
Bar.typeName = 'Bar';
Bar.prototype.get = function()
{
return "OK";
};
// class Foo
var Foo = function()
{
this._bar = new Bar();
};
Foo.typeName = 'Foo';
Foo.prototype._bar = null;
Foo.prototype.ctor$1 = function(x)
{
Foo.call(this);
return this;
};
// Start Global Code
Console.WriteLine((new Foo().ctor$1("Hi"))._bar.get());
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
extern dynamic Console;
class Foo
{
public readonly string val="OK";
}
var f = new Foo();
Console.WriteLine(f.val);
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// class Foo
var Foo = function() {};
Foo.typeName = 'Foo';
Foo.prototype.val = "OK";
// Start Global Code
var f=new Foo();
Console.WriteLine(f.val);
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
extern dynamic Console;
class Foo
{
public readonly string val="OK";
}
var f = new Foo();
f.val="Bad";
Console.WriteLine(f.val);
------ Expected Output ------
// exception: A readonly field cannot be assigned to
------ Actual Exception ------
Tests.Classes.readonly_field_cant_set.txt(9,3): MemberVariable val: A readonly field cannot be assigned to (except in a constructor or a variable initializer)
Test passed!
------ Prefix ------
extern dynamic Console;
class Foo
{
public Foo()
{
// Variable forms of "this"
val="OK1";
this.val = "OK2";
(this).val = "OK3";
}
public readonly string val;
}
var f = new Foo();
Console.WriteLine(f.val);
------ Expected Output ------
OK3
------ Generated JavaScript ------
(function() {
// class Foo
var Foo = function() {};
Foo.typeName = 'Foo';
Foo.prototype.val = null;
Foo.prototype.ctor$1 = function()
{
this.val = "OK1";
this.val = "OK2";
(this).val = "OK3";
return this;
};
// Start Global Code
var f=new Foo().ctor$1();
Console.WriteLine(f.val);
})();
------ Actual Output ------
OK3
Test passed!
------ Prefix ------
extern dynamic Console;
public readonly string val="OK";
Console.WriteLine(val);
------ Expected Output ------
OK
------ Generated JavaScript ------
// Exported entities
var val;
(function() {
// Start Global Code
val="OK";
Console.WriteLine(val);
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------ extern dynamic Console; public readonly string val="OK"; val="Bad"; Console.WriteLine(val); ------ Expected Output ------ // exception: A readonly field cannot be assigned to ------ Actual Exception ------ Tests.Classes.readonly_global_field_cant_set.txt(5,1): GlobalVariable val: A readonly field cannot be assigned to (except in a constructor or a variable initializer) Test passed!
------ Prefix ------
extern dynamic Console;
class A : B
{
}
class B
{
}
Console.WriteLine("OK");
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// class B
var B = function() {};
B.typeName = 'B';
// class A
var A = function() {};
A.typeName = 'A';
A.prototype = new B();
A.prototype.constructor = A;
// Start Global Code
Console.WriteLine("OK");
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
extern dynamic Console;
bool t = true, f = false;
string fn()
{
if (t)
{
return "true";
}
}
Console.WriteLine(fn());
------ Expected Output ------
// exception: Not all code paths return a value
------ Actual Exception ------
Tests.CodePathAnalysis.all_paths_must_return_1.txt(5,1): function 'fn()': Not all code paths return a value
Test passed!
------ Prefix ------
extern dynamic Console;
bool t = true;
string fn()
{
if (t)
{
return "true";
}
else
{
return "false";
}
}
Console.WriteLine(fn());
------ Expected Output ------
true
------ Generated JavaScript ------
(function() {
function fn()
{
if (t)
{
return "true";
}
else
{
return "false";
}
};
// Start Global Code
var t=true;
Console.WriteLine(fn());
})();
------ Actual Output ------
true
Test passed!
------ Prefix ------
extern dynamic Console;
string fn()
{
if (true)
{
if (true)
{
if (true)
{
if (true)
{
return "true";
}
}
}
}
}
Console.WriteLine(fn());
------ Expected Output ------
true
------ Generated JavaScript ------
(function() {
function fn()
{
if (true)
{
if (true)
{
if (true)
{
if (true)
{
return "true";
}
}
}
}
};
// Start Global Code
Console.WriteLine(fn());
})();
------ Actual Output ------
true
Test passed!
------ Prefix ------
extern dynamic Console;
bool t = true;
string fn()
{
if (true)
{
if (true)
{
if (t)
{
if (true)
{
return "true";
}
}
}
}
}
Console.WriteLine(fn());
------ Expected Output ------
// exception: Not all code paths return
------ Actual Exception ------
Tests.CodePathAnalysis.all_paths_must_return_4.txt(5,1): function 'fn()': Not all code paths return a value
Test passed!
------ Prefix ------
extern dynamic Console;
string x;
bool b = false;
do
{
x="Hello";
} while (true);
Console.WriteLine(x);
------ Expected Output ------
// exception: Unreachable code detected
------ Actual Exception ------
Tests.CodePathAnalysis.dowhile_const_statement.txt(10,1): Unreachable code detected
Test passed!
------ Prefix ------
extern dynamic Console;
string x;
bool b = true;
do
{
x="Hello";
break;
} while (b);
Console.WriteLine(x);
------ Expected Output ------
Hello
------ Generated JavaScript ------
(function() {
// Start Global Code
var x;
var b=true;
do {
x = "Hello";
break;
}
while (b);
Console.WriteLine(x);
})();
------ Actual Output ------
Hello
Test passed!
------ Prefix ------
extern dynamic Console;
string x;
do
{
} while (true);
Console.WriteLine(x);
------ Expected Output ------
// exception: Unreachable code detected
------ Actual Exception ------
Tests.CodePathAnalysis.dowhile_statement_infinite.txt(7,1): Unreachable code detected
Test passed!
------ Prefix ------
extern dynamic Console;
string x;
bool b = false;
do
{
x="Hello";
} while (b);
Console.WriteLine(x);
------ Expected Output ------
Hello
------ Generated JavaScript ------
(function() {
// Start Global Code
var x;
var b=false;
do {
x = "Hello";
}
while (b);
Console.WriteLine(x);
})();
------ Actual Output ------
Hello
Test passed!
------ Prefix ------
extern dynamic Console;
string x;
bool t = true;
if (t)
{
x = "true";
}
else
{
x = "false";
}
Console.WriteLine(x);
------ Expected Output ------
true
------ Generated JavaScript ------
(function() {
// Start Global Code
var x;
var t=true;
if (t)
{
x = "true";
}
else
{
x = "false";
}
Console.WriteLine(x);
})();
------ Actual Output ------
true
Test passed!
------ Prefix ------
extern dynamic Console;
string x;
if (false)
{
//x = "true"; // not initialized
}
else
{
x = "false";
}
Console.WriteLine(x);
------ Expected Output ------
false
------ Generated JavaScript ------
(function() {
// Start Global Code
var x;
if (false)
{
}
else
{
x = "false";
}
Console.WriteLine(x);
})();
------ Actual Output ------
false
Test passed!
------ Prefix ------
extern dynamic Console;
string x;
if (true)
{
x = "true";
}
else
{
//x = "false";
}
Console.WriteLine(x);
------ Expected Output ------
true
------ Generated JavaScript ------
(function() {
// Start Global Code
var x;
if (true)
{
x = "true";
}
else
{
}
Console.WriteLine(x);
})();
------ Actual Output ------
true
Test passed!
------ Prefix ------
extern dynamic Console;
string x;
if (true)
{
x = "true";
}
Console.WriteLine(x);
------ Expected Output ------
true
------ Generated JavaScript ------
(function() {
// Start Global Code
var x;
if (true)
{
x = "true";
}
Console.WriteLine(x);
})();
------ Actual Output ------
true
Test passed!
------ Prefix ------
extern dynamic Console;
string x;
bool t = true;
if (t)
{
//x = "true"; // not initialized
}
else
{
x = "false";
}
Console.WriteLine(x);
------ Expected Output ------
// exception: unassigned local variable
------ Actual Exception ------
Tests.CodePathAnalysis.if_statement_false_path_initializes.txt(13,19): GlobalVariable x: use of unassigned local variable
Test passed!
------ Prefix ------
extern dynamic Console;
string x;
bool t = true;
if (t)
{
x = "true";
}
else
{
//x = "false";
}
Console.WriteLine(x);
------ Expected Output ------
// exception: unassigned local variable
------ Actual Exception ------
Tests.CodePathAnalysis.if_statement_true_path_initializes.txt(13,19): GlobalVariable x: use of unassigned local variable
Test passed!
------ Prefix ------
extern dynamic Console;
string x;
bool t = true;
if (t)
{
x = "true";
}
// no else statement
Console.WriteLine(x);
------ Expected Output ------
// exception: unassigned local variable
------ Actual Exception ------
Tests.CodePathAnalysis.if_statement_true_path_only.txt(12,19): GlobalVariable x: use of unassigned local variable
Test passed!
------ Prefix ------
// no warnings
extern dynamic Console;
string x;
bool t=true;
bool b = ((x="a")=="a" && t);
Console.WriteLine(x);
------ Expected Output ------
a
------ Generated JavaScript ------
(function() {
// Start Global Code
var x;
var t=true;
var b=(x = "a")==="a"&&t;
Console.WriteLine(x);
})();
------ Actual Output ------
a
Test passed!
------ Prefix ------ extern dynamic Console; string x; Console.WriteLine(x); ------ Expected Output ------ // exception: unassigned local variable ------ Actual Exception ------ Tests.CodePathAnalysis.simple_unassigned_variable.txt(3,19): GlobalVariable x: use of unassigned local variable Test passed!
------ Prefix ------
extern dynamic Console;
string x;
int i=2;
switch (i)
{
case 1:
x="1";
break;
case 2:
x="2";
break;
default:
x="def";
break;
}
Console.WriteLine(x);
------ Expected Output ------
2
------ Generated JavaScript ------
(function() {
// Start Global Code
var x;
var i=2;
switch (i)
{
case 1:
x = "1";
break;
case 2:
x = "2";
break;
default:
x = "def";
break;
}
Console.WriteLine(x);
})();
------ Actual Output ------
2
Test passed!
------ Prefix ------
// no warnings
extern dynamic Console;
string x;
switch (2)
{
case 1:
x="1";
break;
case 3:
x="def";
break;
}
Console.WriteLine(x);
------ Expected Output ------
// exception: unassigned local variable
------ Actual Exception ------
Tests.CodePathAnalysis.switch_statement_const_no_path_taken.txt(15,19): GlobalVariable x: use of unassigned local variable
Test passed!
------ Prefix ------
// no warnings
extern dynamic Console;
string x;
switch (2)
{
case 1:
x="1";
break;
case 2:
x="2";
break;
}
Console.WriteLine(x);
------ Expected Output ------
2
------ Generated JavaScript ------
(function() {
// Start Global Code
var x;
switch (2)
{
case 1:
x = "1";
break;
case 2:
x = "2";
break;
}
Console.WriteLine(x);
})();
------ Actual Output ------
2
Test passed!
------ Prefix ------
extern dynamic Console;
string x;
int i=2;
switch (i)
{
case 1:
x="1";
break;
case 2:
x="2";
break;
}
Console.WriteLine(x);
------ Expected Output ------
// exception: unassigned local variable
------ Actual Exception ------
Tests.CodePathAnalysis.switch_statement_single_path_initializes.txt(15,19): GlobalVariable x: use of unassigned local variable
Test passed!
------ Prefix ------
// no warnings
extern dynamic Console;
string x;
bool t = true;
var r = t ? (x="true") : (x="false");
Console.WriteLine(x);
------ Expected Output ------
true
------ Generated JavaScript ------
(function() {
// Start Global Code
var x;
var t=true;
var r=t ? (x = "true") : (x = "false");
Console.WriteLine(x);
})();
------ Actual Output ------
true
Test passed!
------ Prefix ------ extern dynamic Console; string x = false ? "true" : "false"; Console.WriteLine(x); ------ Expected Output ------ // exception: Unreachable code detected ------ Actual Exception ------ Tests.CodePathAnalysis.ternary_statement_const_false_unreachable.txt(3,20): Unreachable code detected Test passed!
------ Prefix ------ extern dynamic Console; string x = true ? "true" : "false"; Console.WriteLine(x); ------ Expected Output ------ // exception: Unreachable code detected ------ Actual Exception ------ Tests.CodePathAnalysis.ternary_statement_const_true_unreachable.txt(3,28): Unreachable code detected Test passed!
------ Prefix ------ extern dynamic Console; string x; bool t = false; var r = t ? "true" : (x="false"); Console.WriteLine(x); ------ Expected Output ------ // exception: unassigned local variable ------ Actual Exception ------ Tests.CodePathAnalysis.ternary_statement_false_path_initializes.txt(7,19): GlobalVariable x: use of unassigned local variable Test passed!
------ Prefix ------ extern dynamic Console; string x; bool t = false; var r = t ? (x="true") : "false"; Console.WriteLine(x); ------ Expected Output ------ // exception: unassigned local variable ------ Actual Exception ------ Tests.CodePathAnalysis.ternary_statement_true_path_initializes.txt(7,19): GlobalVariable x: use of unassigned local variable Test passed!
------ Prefix ------
extern dynamic Console;
string x;
bool b = true;
while (b)
{
x="Hello";
break;
}
Console.WriteLine(x);
------ Expected Output ------
// exception: unassigned local variable
------ Actual Exception ------
Tests.CodePathAnalysis.while_statement.txt(11,19): GlobalVariable x: use of unassigned local variable
Test passed!
------ Prefix ------
extern dynamic Console;
string x;
while (true)
{
x="Hello";
break;
}
Console.WriteLine(x);
------ Expected Output ------
Hello
------ Generated JavaScript ------
(function() {
// Start Global Code
var x;
while (true){
x = "Hello";
break;
}
Console.WriteLine(x);
})();
------ Actual Output ------
Hello
Test passed!
------ Prefix ------
extern dynamic Console;
string x;
while (true)
{
}
Console.WriteLine(x);
------ Expected Output ------
// exception: Unreachable code detected
------ Actual Exception ------
Tests.CodePathAnalysis.while_statement_infinite.txt(7,1): Unreachable code detected
Test passed!
------ Prefix ------
extern dynamic Console;
string x;
bool b = true;
while (true)
{
if (b)
{
x="Hello";
break;
}
else
{
x="Goodbye";
break;
}
}
Console.WriteLine(x);
------ Expected Output ------
Hello
------ Generated JavaScript ------
(function() {
// Start Global Code
var x;
var b=true;
while (true){
if (b)
{
x = "Hello";
break;
}
else
{
x = "Goodbye";
break;
}
}
Console.WriteLine(x);
})();
------ Actual Output ------
Hello
Test passed!
------ Prefix ------
// no warnings
extern dynamic Console;
class Fruit
{
public Fruit()
{
Console.WriteLine("Fruit Constructor");
}
}
class Apple : Fruit
{
public Apple()
{
Console.WriteLine("Apple Constructor");
}
}
var x = new Apple();
------ Expected Output ------
Fruit Constructor
Apple Constructor
------ Generated JavaScript ------
(function() {
// class Fruit
var Fruit = function() {};
Fruit.typeName = 'Fruit';
Fruit.prototype.ctor$1 = function()
{
Console.WriteLine("Fruit Constructor");
return this;
};
// class Apple
var Apple = function() {};
Apple.typeName = 'Apple';
Apple.prototype = new Fruit();
Apple.prototype.constructor = Apple;
Apple.prototype.ctor$1 = function()
{
Fruit.prototype.ctor$1();
Console.WriteLine("Apple Constructor");
return this;
};
// Start Global Code
var x=new Apple().ctor$1();
})();
------ Actual Output ------
Fruit Constructor
Apple Constructor
Test passed!
------ Prefix ------
// no warnings
extern dynamic Console;
class Fruit
{
public Fruit()
{
Console.WriteLine("Fruit Constructor");
}
}
class Apple : Fruit
{
public Apple() : base()
{
Console.WriteLine("Apple Constructor");
}
}
var x = new Apple();
------ Expected Output ------
Fruit Constructor
Apple Constructor
------ Generated JavaScript ------
(function() {
// class Fruit
var Fruit = function() {};
Fruit.typeName = 'Fruit';
Fruit.prototype.ctor$1 = function()
{
Console.WriteLine("Fruit Constructor");
return this;
};
// class Apple
var Apple = function() {};
Apple.typeName = 'Apple';
Apple.prototype = new Fruit();
Apple.prototype.constructor = Apple;
Apple.prototype.ctor$1 = function()
{
Fruit.prototype.ctor$1();
Console.WriteLine("Apple Constructor");
return this;
};
// Start Global Code
var x=new Apple().ctor$1();
})();
------ Actual Output ------
Fruit Constructor
Apple Constructor
Test passed!
------ Prefix ------
extern dynamic Console;
class Fruit
{
public Fruit(int param)
{
}
}
class Apple : Fruit
{
public Apple() : base()
{
}
}
------ Expected Output ------
// exception: expects 1 parameters, but 0 were supplied
------ Actual Exception ------
Tests.Constructors.explicit_call_to_base_constructor_must_match_args.txt(12,23): function 'Fruit..ctor(System.Integer)': expects 1 parameters, but 0 were supplied
Test passed!
------ Prefix ------
// no warnings
extern dynamic Console;
class Fruit
{
public Fruit(int param)
{
Console.WriteLine("Fruit Constructor " + param.toString());
}
}
class Apple : Fruit
{
public Apple() : base(99)
{
Console.WriteLine("Apple Constructor");
}
}
var x = new Apple();
------ Expected Output ------
Fruit Constructor 99
Apple Constructor
------ Generated JavaScript ------
(function() {
// class Fruit
var Fruit = function() {};
Fruit.typeName = 'Fruit';
Fruit.prototype.ctor$1 = function(param)
{
Console.WriteLine("Fruit Constructor " + param.toString());
return this;
};
// class Apple
var Apple = function() {};
Apple.typeName = 'Apple';
Apple.prototype = new Fruit();
Apple.prototype.constructor = Apple;
Apple.prototype.ctor$1 = function()
{
Fruit.prototype.ctor$1(99);
Console.WriteLine("Apple Constructor");
return this;
};
// Start Global Code
var x=new Apple().ctor$1();
})();
------ Actual Output ------
Fruit Constructor 99
Apple Constructor
Test passed!
------ Prefix ------
// no warnings
extern dynamic Console;
class Base
{
public Base()
{
Console.WriteLine("Base");
}
}
class Fruit : Base
{
public Fruit() : this("Apple")
{
Console.WriteLine("Fruit");
}
public Fruit(string name)
{
Console.WriteLine("Fruit " + name);
}
}
var x = new Fruit();
------ Expected Output ------
Base
Fruit Apple
Fruit
------ Generated JavaScript ------
(function() {
// class Base
var Base = function() {};
Base.typeName = 'Base';
Base.prototype.ctor$1 = function()
{
Console.WriteLine("Base");
return this;
};
// class Fruit
var Fruit = function() {};
Fruit.typeName = 'Fruit';
Fruit.prototype = new Base();
Fruit.prototype.constructor = Fruit;
Fruit.prototype.ctor$1 = function()
{
Fruit.prototype.ctor$2("Apple");
Console.WriteLine("Fruit");
return this;
};
Fruit.prototype.ctor$2 = function(name)
{
Base.prototype.ctor$1();
Console.WriteLine("Fruit " + name);
return this;
};
// Start Global Code
var x=new Fruit().ctor$1();
})();
------ Actual Output ------
Base
Fruit Apple
Fruit
Test passed!
------ Prefix ------
extern dynamic Console;
class Fruit
{
public Fruit(int param)
{
}
}
class Apple : Fruit
{
public Apple()
{
}
}
------ Expected Output ------
// exception: doesn't define a constructor with no parameters
------ Actual Exception ------
Tests.Constructors.implicit_call_to_base_constructor_requires_parameterless_base_constructor.txt(12,14): function 'Apple..ctor()': The base class 'Fruit' doesn't define a constructor with no parameters
Test passed!
------ Prefix ------
extern dynamic Console;
class Foo
{
public Foo()
{
Console.WriteLine("Constructor");
}
public void DoSomething()
{
Foo();
}
}
var x = new Foo();
------ Expected Output ------
// exception: is not a function
------ Actual Exception ------
Tests.Constructors.instance_method_cant_call_constructor.txt(12,7): class 'Foo' is not a function and cannot be called
Test passed!
------ Prefix ------
class Foo
{
public Foo()
{
}
public void Foo()
{
}
}
------ Expected Output ------
// exception: member names cannot be the same as their enclosing type
------ Actual Exception ------
Tests.Constructors.instance_method_cant_have_same_name_as_constructor.txt(7,9): function 'Foo.Foo()': member names cannot be the same as their enclosing type
Test passed!
------ Prefix ------
extern dynamic Console;
class Foo
{
public string fn()
{
return "OK";
}
}
var x = new Foo();
Console.WriteLine(x.fn());
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// class Foo
var Foo = function() {};
Foo.typeName = 'Foo';
Foo.prototype.fn = function()
{
return "OK";
};
// Start Global Code
var x=new Foo();
Console.WriteLine(x.fn());
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
// no warnings
extern dynamic Console;
class Foo
{
public Foo()
{
Console.WriteLine("Default");
}
public Foo(int x)
{
Console.WriteLine("Int - " + x.toString());
}
public Foo(string str)
{
Console.WriteLine("String - " + str);
}
}
var x = new Foo();
var y = new Foo(23);
var z = new Foo("OK");
------ Expected Output ------
Default
Int - 23
String - OK
------ Generated JavaScript ------
(function() {
// class Foo
var Foo = function() {};
Foo.typeName = 'Foo';
Foo.prototype.ctor$1 = function()
{
Console.WriteLine("Default");
return this;
};
Foo.prototype.ctor$2 = function(x)
{
Console.WriteLine("Int - " + x.toString());
return this;
};
Foo.prototype.ctor$3 = function(str)
{
Console.WriteLine("String - " + str);
return this;
};
// Start Global Code
var x=new Foo().ctor$1();
var y=new Foo().ctor$2(23);
var z=new Foo().ctor$3("OK");
})();
------ Actual Output ------
Default
Int - 23
String - OK
Test passed!
------ Prefix ------
// no warnings
extern dynamic Console;
class Foo
{
// This looks like a constructor in that the return type is the same
// name as the class (like a constructor), but it's actually a return type
public static Foo fn()
{
return new Foo();
}
public void DoSomething()
{
Console.WriteLine("OK");
}
}
Foo.fn().DoSomething();
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// class Foo
var Foo = function() {};
Foo.typeName = 'Foo';
Foo.prototype.DoSomething = function()
{
Console.WriteLine("OK");
};
Foo.fn = function()
{
return new Foo();
};
// Start Global Code
Foo.fn().DoSomething();
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
// no warnings
// should not generate: Apple$1
// should not generate: Fruit$1
extern dynamic Console;
class Fruit
{
public Fruit()
{
}
}
class Apple : Fruit
{
}
var x = new Apple();
------ Expected Output ------
------ Generated JavaScript ------
(function() {
// class Fruit
var Fruit = function() {};
Fruit.typeName = 'Fruit';
// class Apple
var Apple = function() {};
Apple.typeName = 'Apple';
Apple.prototype = new Fruit();
Apple.prototype.constructor = Apple;
// Start Global Code
var x=new Apple();
})();
------ Actual Output ------
Test passed!
------ Prefix ------
// no warnings
// should not generate: Fruit$1
extern dynamic Console;
class Fruit
{
public Fruit()
{
}
}
var x = new Fruit();
------ Expected Output ------
------ Generated JavaScript ------
(function() {
// class Fruit
var Fruit = function() {};
Fruit.typeName = 'Fruit';
// Start Global Code
var x=new Fruit();
})();
------ Actual Output ------
Test passed!
------ Prefix ------
// no warnings
// should not generate: Fruit$
// SHOULd not generate: Apple$
extern dynamic Console;
class Fruit
{
public Fruit()
{
}
}
class Apple : Fruit
{
public Apple()
{
}
}
var x = new Apple();
------ Expected Output ------
------ Generated JavaScript ------
(function() {
// class Fruit
var Fruit = function() {};
Fruit.typeName = 'Fruit';
// class Apple
var Apple = function() {};
Apple.typeName = 'Apple';
Apple.prototype = new Fruit();
Apple.prototype.constructor = Apple;
// Start Global Code
var x=new Apple();
})();
------ Actual Output ------
Test passed!
------ Prefix ------
// no warnings
extern dynamic Console;
class Foo
{
public Foo()
{
Console.WriteLine("Constructor");
}
}
var x = new Foo();
------ Expected Output ------
Constructor
------ Generated JavaScript ------
(function() {
// class Foo
var Foo = function() {};
Foo.typeName = 'Foo';
Foo.prototype.ctor$1 = function()
{
Console.WriteLine("Constructor");
return this;
};
// Start Global Code
var x=new Foo().ctor$1();
})();
------ Actual Output ------
Constructor
Test passed!
------ Prefix ------
// no warnings
extern dynamic Console;
namespace ns1.ns2
{
class Foo
{
static Foo()
{
Console.WriteLine("Static Constructor");
}
}
}
Console.WriteLine("OK");
------ Expected Output ------
Static Constructor
OK
------ Generated JavaScript ------
(function() {
// namespace ns1
var ns1 = new function()
{
// namespace ns1.ns2
ns2 = new function()
{
// class ns1.ns2.Foo
var Foo = function() {};
Foo.typeName = 'ns1.ns2.Foo';
Foo.$cctor = function()
{
Console.WriteLine("Static Constructor");
};
this.Foo = Foo;
}();
this.ns2 = ns2
}();
// Call static constructors
ns1.ns2.Foo.$cctor();
// Start Global Code
Console.WriteLine("OK");
})();
------ Actual Output ------
Static Constructor
OK
Test passed!
------ Prefix ------
// no warnings
extern dynamic Console;
// This test is to check the ordering of static constructors.
// Because class `Foo` is coupled to class `Bar` through it's `_coupled`
// property, Bar's static constructor should be invoked first.
class Foo
{
static Foo()
{
Console.WriteLine("Foo");
}
Bar _coupled;
}
class Bar
{
static Bar()
{
Console.WriteLine("Bar");
}
}
Console.WriteLine("OK");
------ Expected Output ------
Bar
Foo
OK
------ Generated JavaScript ------
(function() {
// class Foo
var Foo = function() {};
Foo.typeName = 'Foo';
Foo.prototype._coupled = null;
Foo.$cctor = function()
{
Console.WriteLine("Foo");
};
// class Bar
var Bar = function() {};
Bar.typeName = 'Bar';
Bar.$cctor = function()
{
Console.WriteLine("Bar");
};
// Call static constructors
Bar.$cctor();
Foo.$cctor();
// Start Global Code
Console.WriteLine("OK");
})();
------ Actual Output ------
Bar
Foo
OK
Test passed!
------ Prefix ------
// no warnings
extern dynamic Console;
// This test is to check the ordering of static constructors.
// `Foo` and `Bar` are both coupled to each other, static constructors
// should be invoked in declaration order
// `Other` has no coupled dependencies and should be first of all
class Foo
{
static Foo()
{
Console.WriteLine("Foo");
}
Bar _coupled;
}
class Bar
{
static Bar()
{
Console.WriteLine("Bar");
}
Foo _coupled;
}
class Other
{
static Other()
{
Console.WriteLine("Other");
}
}
Console.WriteLine("OK");
------ Expected Output ------
Other
Foo
Bar
OK
------ Generated JavaScript ------
(function() {
// class Foo
var Foo = function() {};
Foo.typeName = 'Foo';
Foo.prototype._coupled = null;
Foo.$cctor = function()
{
Console.WriteLine("Foo");
};
// class Bar
var Bar = function() {};
Bar.typeName = 'Bar';
Bar.prototype._coupled = null;
Bar.$cctor = function()
{
Console.WriteLine("Bar");
};
// class Other
var Other = function() {};
Other.typeName = 'Other';
Other.$cctor = function()
{
Console.WriteLine("Other");
};
// Call static constructors
Other.$cctor();
Foo.$cctor();
Bar.$cctor();
// Start Global Code
Console.WriteLine("OK");
})();
------ Actual Output ------
Other
Foo
Bar
OK
Test passed!
------ Prefix ------
// no warnings
extern dynamic Console;
void writeem(int a, int b)
{
Console.WriteLine(a.toString() + " * " + b.toString() + " = " + (a*b).toString());
}
Action<int, int> op = writeem;
op(10,20);
void write_something()
{
Console.WriteLine("Hello World");
}
Action op2 = write_something;
op2();
------ Expected Output ------
10 * 20 = 200
Hello World
------ Generated JavaScript ------
(function() {
function writeem(a, b)
{
Console.WriteLine(a.toString() + " * " + b.toString() + " = " + (a*b).toString());
};
function write_something()
{
Console.WriteLine("Hello World");
};
// Start Global Code
var op=writeem;
op(10, 20);
var op2=write_something;
op2();
})();
------ Actual Output ------
10 * 20 = 200
Hello World
Test passed!
------ Prefix ------
// no warnings
extern dynamic Console;
class MyClass
{
public int Value;
public void DoSomething()
{
Console.WriteLine("MyClass.DoSomething - " + Value.toString());
}
}
delegate void del();
var inst = new MyClass();
inst.Value=23;
del fn = inst.DoSomething;
fn();
------ Expected Output ------
MyClass.DoSomething - 23
------ Generated JavaScript ------
(function() {
// Prefix runtime library
var $dex = {};
$dex.bind=function(a,b){var c=a[b];return function(){c.apply(a,arguments)}}
// class MyClass
var MyClass = function() {};
MyClass.typeName = 'MyClass';
MyClass.prototype.Value = 0;
MyClass.prototype.DoSomething = function()
{
Console.WriteLine("MyClass.DoSomething - " + this.Value.toString());
};
// Start Global Code
var inst=new MyClass();
inst.Value = 23;
var fn=$dex.bind(inst, "DoSomething");
fn();
})();
------ Actual Output ------
MyClass.DoSomething - 23
Test passed!
------ Prefix ------
// no warnings
extern dynamic Console;
int addem(int a, int b)
{
return a+b;
}
Func<int, int, int> op = addem;
Console.WriteLine(op(10, 20).toString());
------ Expected Output ------
30
------ Generated JavaScript ------
(function() {
function addem(a, b)
{
return a + b;
};
// Start Global Code
var op=addem;
Console.WriteLine(op(10, 20).toString());
})();
------ Actual Output ------
30
Test passed!
------ Prefix ------
// no warnings
extern dynamic Console;
class MyClass
{
public int Value;
public void DoSomething(int param)
{
Console.WriteLine("MyClass.DoSomething - " + Value.toString() + " - " + param.toString());
}
}
delegate void del<T>(T a);
var inst = new MyClass();
inst.Value=23;
del<int> fn = inst.DoSomething;
fn(5);
------ Expected Output ------
MyClass.DoSomething - 23 - 5
------ Generated JavaScript ------
(function() {
// Prefix runtime library
var $dex = {};
$dex.bind=function(a,b){var c=a[b];return function(){c.apply(a,arguments)}}
// class MyClass
var MyClass = function() {};
MyClass.typeName = 'MyClass';
MyClass.prototype.Value = 0;
MyClass.prototype.DoSomething = function(param)
{
Console.WriteLine("MyClass.DoSomething - " + this.Value.toString() + " - " + param.toString());
};
// Start Global Code
var inst=new MyClass();
inst.Value = 23;
var fn=$dex.bind(inst, "DoSomething");
fn(5);
})();
------ Actual Output ------
MyClass.DoSomething - 23 - 5
Test passed!
------ Prefix ------
// no warnings
extern dynamic Console;
TOut fn<TIn, TOut>(Func<TIn,TOut> cb, TIn input)
{
return cb(input);
}
string convert(int val)
{
return val.toString();
}
//Func<int, string> myfn = convert;
Console.WriteLine(fn(convert, 23));
------ Expected Output ------
23
------ Generated JavaScript ------
(function() {
function fn$2(cb, input)
{
return cb(input);
};
function convert(val)
{
return val.toString();
};
// Start Global Code
Console.WriteLine(fn$2(convert, 23));
})();
------ Actual Output ------
23
Test passed!
------ Prefix ------
// no warnings
extern dynamic Console;
TOut fn<TIn, TOut>(Func<TIn,TOut> cb, TIn input)
{
return cb(input);
}
string convert(int val)
{
return val.toString();
}
string convert(bool val)
{
return val.toString();
}
//Func<int, string> myfn = convert;
Console.WriteLine(fn(convert, 23));
Console.WriteLine(fn(convert, true));
------ Expected Output ------
23
true
------ Generated JavaScript ------
(function() {
function fn$2(cb, input)
{
return cb(input);
};
function convert$1(val)
{
return val.toString();
};
function convert$2(val)
{
return val.toString();
};
// Start Global Code
Console.WriteLine(fn$2(convert$1, 23));
Console.WriteLine(fn$2(convert$2, true));
})();
------ Actual Output ------
23
true
Test passed!
------ Prefix ------
// no warnings
extern dynamic Console;
class Base
{
}
class Derived
{
}
delegate void del(Derived b);
void fn(Base b)
{
Console.WriteLine("Base");
}
void fn(Derived b)
{
Console.WriteLine("Derived");
}
del myfn = fn;
myfn(null);
------ Expected Output ------
Derived
------ Generated JavaScript ------
(function() {
// class Base
var Base = function() {};
Base.typeName = 'Base';
// class Derived
var Derived = function() {};
Derived.typeName = 'Derived';
function fn$1(b)
{
Console.WriteLine("Base");
};
function fn$2(b)
{
Console.WriteLine("Derived");
};
// Start Global Code
var myfn=fn$2;
myfn(null);
})();
------ Actual Output ------
Derived
Test passed!
------ Prefix ------
// no warnings
extern dynamic Console;
delegate void delDoSomethingWithInt(int a);
void PrintInt(int x)
{
Console.WriteLine(x.toString());
}
delDoSomethingWithInt fn = PrintInt;
fn(5);
------ Expected Output ------
5
------ Generated JavaScript ------
(function() {
function PrintInt(x)
{
Console.WriteLine(x.toString());
};
// Start Global Code
var fn=PrintInt;
fn(5);
})();
------ Actual Output ------
5
Test passed!
------ Prefix ------
extern dynamic Console;
public enum MyEnum
{
a = 0x01,
b = 0x02,
c = 0x04,
d = 0x08,
}
MyEnum x = MyEnum.a | MyEnum.b;
x &= ~MyEnum.a;
Console.WriteLine((int)x);
------ Expected Output ------
2
------ Generated JavaScript ------
// Exported entities
var MyEnum;
(function() {
// enum MyEnum
MyEnum =
{
a: 1,
b: 2,
c: 4,
d: 8
};
// Start Global Code
var x=MyEnum.a|MyEnum.b;
x &= ~MyEnum.a;
Console.WriteLine(x);
})();
------ Actual Output ------
2
Test passed!
------ Prefix ------
extern dynamic Console;
public enum MyEnum
{
a,
b,
c,
d,
}
Console.WriteLine(MyEnum.b > MyEnum.a);
------ Expected Output ------
True
------ Generated JavaScript ------
// Exported entities
var MyEnum;
(function() {
// enum MyEnum
MyEnum =
{
a: 0,
b: 1,
c: 2,
d: 3
};
// Start Global Code
Console.WriteLine(MyEnum.b>MyEnum.a);
})();
------ Actual Output ------
True
Test passed!
------ Prefix ------
extern dynamic Console;
internal enum MyEnum
{
a,
b,
c,
}
int x = (int)MyEnum.b;
Console.WriteLine((int)x);
------ Expected Output ------
1
------ Generated JavaScript ------
(function() {
// enum MyEnum
var MyEnum =
{
a: 0,
b: 1,
c: 2
};
// Start Global Code
var x=MyEnum.b;
Console.WriteLine(x);
})();
------ Actual Output ------
1
Test passed!
------ Prefix ------
extern dynamic Console;
public enum MyEnum
{
a,
b,
c,
}
MyEnum x = (MyEnum)2;
Console.WriteLine((int)x);
------ Expected Output ------
2
------ Generated JavaScript ------
// Exported entities
var MyEnum;
(function() {
// enum MyEnum
MyEnum =
{
a: 0,
b: 1,
c: 2
};
// Start Global Code
var x=2;
Console.WriteLine(x);
})();
------ Actual Output ------
2
Test passed!
------ Prefix ------
extern dynamic Console;
public enum MyEnum
{
a,
b,
c,
}
MyEnum x = 0;
Console.WriteLine((int)x);
x=0;
Console.WriteLine((int)x);
------ Expected Output ------
0
0
------ Generated JavaScript ------
// Exported entities
var MyEnum;
(function() {
// enum MyEnum
MyEnum =
{
a: 0,
b: 1,
c: 2
};
// Start Global Code
var x=0;
Console.WriteLine(x);
x = 0;
Console.WriteLine(x);
})();
------ Actual Output ------
0
0
Test passed!
------ Prefix ------
extern dynamic Console;
public enum MyEnum
{
a,
b,
c,
}
MyEnum.a=12;
------ Expected Output ------
// exception: The left hand side of an assignment must be a variable, property or indexer
------ Actual Exception ------
Tests.Enums.cant_assign_to_enum_member.txt(10,8): The left hand side of an assignment must be a variable, property or indexer
Test passed!
------ Prefix ------
public enum MyEnum
{
a,
b,
c,
}
MyEnum x = MyEnum.a + MyEnum.b;
------ Expected Output ------
// exception: cannot be applied to operands of type
------ Actual Exception ------
Tests.Enums.cant_enum_add_enum.txt(8,21): Operator '+' cannot be applied to operands of type enum 'MyEnum' and enum 'MyEnum'
Test passed!
------ Prefix ------
public enum MyEnum
{
a,
b,
c,
}
MyEnum x = MyEnum.a & 1;
------ Expected Output ------
// exception: cannot be applied to operands of type
------ Actual Exception ------
Tests.Enums.cant_enum_and_int.txt(8,21): Operator '&' cannot be applied to operands of type enum 'MyEnum' and class 'System.Integer'
Test passed!
------ Prefix ------
public enum MyEnum
{
a,
b,
c,
}
MyEnum x = MyEnum.a;
x += MyEnum.b;
------ Expected Output ------
// exception: cannot be applied to operands of type
------ Actual Exception ------
Tests.Enums.cant_enum_compound_add_enum.txt(9,3): Operator '+=' cannot be applied to operands of type enum 'MyEnum' and enum 'MyEnum'
Test passed!
------ Prefix ------
public enum MyEnum
{
a,
b,
c,
}
MyEnum x = MyEnum.a;
x &= 1;
------ Expected Output ------
// exception: cannot be applied to operands of type
------ Actual Exception ------
Tests.Enums.cant_enum_compound_and_int.txt(9,3): Operator '&=' cannot be applied to operands of type enum 'MyEnum' and class 'System.Integer'
Test passed!
------ Prefix ------
public enum MyEnum
{
a,
b,
c,
}
MyEnum x = MyEnum.a;
x |= 1;
------ Expected Output ------
// exception: cannot be applied to operands of type
------ Actual Exception ------
Tests.Enums.cant_enum_compound_or_int.txt(9,3): Operator '|=' cannot be applied to operands of type enum 'MyEnum' and class 'System.Integer'
Test passed!
------ Prefix ------
public enum MyEnum
{
a,
b,
c,
}
MyEnum x = MyEnum.a;
x -= MyEnum.b;
------ Expected Output ------
// exception: cannot be applied to operands of type
------ Actual Exception ------
Tests.Enums.cant_enum_compound_sub_enum.txt(9,3): Operator '-=' cannot be applied to operands of type enum 'MyEnum' and enum 'MyEnum'
Test passed!
------ Prefix ------
public enum MyEnum
{
a,
b,
c,
}
MyEnum x = MyEnum.a | 1;
------ Expected Output ------
// exception: cannot be applied to operands of type
------ Actual Exception ------
Tests.Enums.cant_enum_or_int.txt(8,21): Operator '|' cannot be applied to operands of type enum 'MyEnum' and class 'System.Integer'
Test passed!
------ Prefix ------
extern dynamic Console;
public enum MyEnum
{
a = b,
b = a,
}
------ Expected Output ------
// exception: involves a circular definition
------ Actual Exception ------
Tests.Enums.cant_have_circular_constant_expressions.txt(5,2): The evaluation of the constant value for 'MyEnum.a' involves a circular definition
Test passed!
------ Prefix ------
extern dynamic Console;
enum MyEnum
{
a,
b,
a,
}
------ Expected Output ------
// exception: already contains a definition
------ Actual Exception ------
Tests.Enums.cant_have_duplicate_members.txt(3,1): enum 'MyEnum': already contains a definition for 'a'
Test passed!
------ Prefix ------
extern dynamic Console;
public enum MyEnum
{
a,
b,
c,
}
int x = MyEnum.b;
Console.WriteLine((int)x);
------ Expected Output ------
// exception: cannot implicitly convert
------ Actual Exception ------
Tests.Enums.cant_implicitly_convert_enum_to_int.txt(10,16): cannot implicitly convert enum 'MyEnum' to class 'System.Integer'
Test passed!
------ Prefix ------
extern dynamic Console;
public enum MyEnum
{
a,
b,
c,
}
MyEnum x = 23;
Console.WriteLine((int)x);
------ Expected Output ------
// exception: cannot implicitly convert
------ Actual Exception ------
Tests.Enums.cant_implicitly_convert_int_to_enum.txt(10,12): cannot implicitly convert class 'System.Integer' to enum 'MyEnum'
Test passed!
------ Prefix ------
public enum MyEnum
{
a,
b,
c,
}
MyEnum x = 1 & MyEnum.a;
------ Expected Output ------
// exception: cannot be applied to operands of type
------ Actual Exception ------
Tests.Enums.cant_int_and_enum.txt(8,14): Operator '&' cannot be applied to operands of type class 'System.Integer' and enum 'MyEnum'
Test passed!
------ Prefix ------
public enum MyEnum
{
a,
b,
c,
}
int x = 2;
x += MyEnum.b;
------ Expected Output ------
// exception: cannot be applied to operands of type
------ Actual Exception ------
Tests.Enums.cant_int_compound_add_enum.txt(9,3): Operator '+=' cannot be applied to operands of type class 'System.Integer' and enum 'MyEnum'
Test passed!
------ Prefix ------
public enum MyEnum
{
a,
b,
c,
}
int x = 2;
x &= MyEnum.b;
------ Expected Output ------
// exception: cannot be applied to operands of type
------ Actual Exception ------
Tests.Enums.cant_int_compound_and_enum.txt(9,3): Operator '&=' cannot be applied to operands of type class 'System.Integer' and enum 'MyEnum'
Test passed!
------ Prefix ------
public enum MyEnum
{
a,
b,
c,
}
int x = 2;
x |= MyEnum.b;
------ Expected Output ------
// exception: cannot be applied to operands of type
------ Actual Exception ------
Tests.Enums.cant_int_compound_or_enum.txt(9,3): Operator '|=' cannot be applied to operands of type class 'System.Integer' and enum 'MyEnum'
Test passed!
------ Prefix ------
public enum MyEnum
{
a,
b,
c,
}
int x = 2;
x -= MyEnum.b;
------ Expected Output ------
// exception: cannot be applied to operands of type
------ Actual Exception ------
Tests.Enums.cant_int_compound_sub_enum.txt(9,3): Operator '-=' cannot be applied to operands of type class 'System.Integer' and enum 'MyEnum'
Test passed!
------ Prefix ------
public enum MyEnum
{
a,
b,
c,
}
MyEnum x = 1 | MyEnum.a;
------ Expected Output ------
// exception: cannot be applied to operands of type
------ Actual Exception ------
Tests.Enums.cant_int_or_enum.txt(8,14): Operator '|' cannot be applied to operands of type class 'System.Integer' and enum 'MyEnum'
Test passed!
------ Prefix ------
extern dynamic Console;
public enum MyEnum
{
a,
b,
c,
d,
}
MyEnum x = MyEnum.b;
// enum + integer = enum
x+=1;
Console.WriteLine((int)x);
// enum - integer = enum
x-=1;
Console.WriteLine((int)x);
// enum | enum
x = MyEnum.b;
x |= MyEnum.c;
Console.WriteLine((int)x);
// enum & enum
x = MyEnum.d;
x &= MyEnum.b;
Console.WriteLine((int)x);
------ Expected Output ------
2
1
3
1
------ Generated JavaScript ------
// Exported entities
var MyEnum;
(function() {
// enum MyEnum
MyEnum =
{
a: 0,
b: 1,
c: 2,
d: 3
};
// Start Global Code
var x=MyEnum.b;
x += 1;
Console.WriteLine(x);
x -= 1;
Console.WriteLine(x);
x = MyEnum.b;
x |= MyEnum.c;
Console.WriteLine(x);
x = MyEnum.d;
x &= MyEnum.b;
Console.WriteLine(x);
})();
------ Actual Output ------
2
1
3
1
Test passed!
------ Prefix ------
extern dynamic Console;
public enum MyEnum
{
a,
b,
c,
d,
}
MyEnum x;
// enum + integer = enum
x=MyEnum.b+1;
Console.WriteLine((int)x);
// integer + enum = enum
x=1+MyEnum.b;
Console.WriteLine((int)x);
// enum + enum = error
// enum - enum = integer
int y = MyEnum.c - MyEnum.a;
Console.WriteLine(y);
// enum - integer = enum
x=MyEnum.c-1;
Console.WriteLine((int)x);
// integer - enum = enum
x=3-MyEnum.b;
Console.WriteLine((int)x);
// enum | enum
x = MyEnum.b | MyEnum.c;
Console.WriteLine((int)x);
// enum & enum
x = MyEnum.d & MyEnum.b;
Console.WriteLine((int)x);
------ Expected Output ------
2
2
2
1
2
3
1
------ Generated JavaScript ------
// Exported entities
var MyEnum;
(function() {
// enum MyEnum
MyEnum =
{
a: 0,
b: 1,
c: 2,
d: 3
};
// Start Global Code
var x;
x = MyEnum.b + 1;
Console.WriteLine(x);
x = 1 + MyEnum.b;
Console.WriteLine(x);
var y=MyEnum.c - MyEnum.a;
Console.WriteLine(y);
x = MyEnum.c - 1;
Console.WriteLine(x);
x = 3 - MyEnum.b;
Console.WriteLine(x);
x = MyEnum.b|MyEnum.c;
Console.WriteLine(x);
x = MyEnum.d&MyEnum.b;
Console.WriteLine(x);
})();
------ Actual Output ------
2
2
2
1
2
3
1
Test passed!
------ Prefix ------
extern dynamic Console;
public enum MyEnum
{
a = 10,
b = a+10,
c,
d = MyOtherEnum.a
}
public enum MyOtherEnum
{
a = 100
}
Console.WriteLine((int)MyEnum.a);
Console.WriteLine((int)MyEnum.b);
Console.WriteLine((int)MyEnum.c);
Console.WriteLine((int)MyEnum.d);
------ Expected Output ------
10
20
21
100
------ Generated JavaScript ------
// Exported entities
var MyEnum, MyOtherEnum;
(function() {
// enum MyEnum
MyEnum =
{
a: 10,
b: 20,
c: 21,
d: 100
};
// enum MyOtherEnum
MyOtherEnum =
{
a: 100
};
// Start Global Code
Console.WriteLine(MyEnum.a);
Console.WriteLine(MyEnum.b);
Console.WriteLine(MyEnum.c);
Console.WriteLine(MyEnum.d);
})();
------ Actual Output ------
10
20
21
100
Test passed!
------ Prefix ------
extern dynamic Console;
public enum MyEnum
{
a,
b,
c,
}
Console.WriteLine((int)MyEnum.a);
Console.WriteLine((int)MyEnum.b);
Console.WriteLine((int)MyEnum.c);
------ Expected Output ------
0
1
2
------ Generated JavaScript ------
// Exported entities
var MyEnum;
(function() {
// enum MyEnum
MyEnum =
{
a: 0,
b: 1,
c: 2
};
// Start Global Code
Console.WriteLine(MyEnum.a);
Console.WriteLine(MyEnum.b);
Console.WriteLine(MyEnum.c);
})();
------ Actual Output ------
0
1
2
Test passed!
------ Prefix ------
extern dynamic Console;
public enum MyEnum
{
a,
b,
c,
}
MyEnum x = MyEnum.b;
Console.WriteLine((int)x);
------ Expected Output ------
1
------ Generated JavaScript ------
// Exported entities
var MyEnum;
(function() {
// enum MyEnum
MyEnum =
{
a: 0,
b: 1,
c: 2
};
// Start Global Code
var x=MyEnum.b;
Console.WriteLine(x);
})();
------ Actual Output ------
1
Test passed!
------ Prefix ------
extern dynamic Console;
// Typical assignment
string x;
x="OK";
// Math assignment operators
int y=10;
y+=20;
y/=2;
y%=6;
Console.WriteLine(x);
Console.WriteLine(y.toString());
------ Expected Output ------
OK
3
------ Generated JavaScript ------
(function() {
// Start Global Code
var x;
x = "OK";
var y=10;
y += 20;
y = ((y/2)|0);
y %= 6;
Console.WriteLine(x);
Console.WriteLine(y.toString());
})();
------ Actual Output ------
OK
3
Test passed!
------ Prefix ------
extern dynamic Console;
Console.WriteLine((1==1).toString());
Console.WriteLine((1==2).toString());
Console.WriteLine((1!=1).toString());
Console.WriteLine((1!=2).toString());
Console.WriteLine(">");
Console.WriteLine((1>2).toString());
Console.WriteLine((2>1).toString());
Console.WriteLine((1>1).toString());
Console.WriteLine(">=");
Console.WriteLine((1>=2).toString());
Console.WriteLine((2>=1).toString());
Console.WriteLine((1>=1).toString());
Console.WriteLine("<");
Console.WriteLine((1<2).toString());
Console.WriteLine((2<1).toString());
Console.WriteLine((1<1).toString());
Console.WriteLine("<=");
Console.WriteLine((1<=2).toString());
Console.WriteLine((2<=1).toString());
Console.WriteLine((1<=1).toString());
------ Expected Output ------
true
false
false
true
>
false
true
false
>=
false
true
true
<
true
false
false
<=
true
false
true
------ Generated JavaScript ------
(function() {
// Start Global Code
Console.WriteLine((1===1).toString());
Console.WriteLine((1===2).toString());
Console.WriteLine((1!==1).toString());
Console.WriteLine((1!==2).toString());
Console.WriteLine(">");
Console.WriteLine((1>2).toString());
Console.WriteLine((2>1).toString());
Console.WriteLine((1>1).toString());
Console.WriteLine(">=");
Console.WriteLine((1>=2).toString());
Console.WriteLine((2>=1).toString());
Console.WriteLine((1>=1).toString());
Console.WriteLine("<");
Console.WriteLine((1<2).toString());
Console.WriteLine((2<1).toString());
Console.WriteLine((1<1).toString());
Console.WriteLine("<=");
Console.WriteLine((1<=2).toString());
Console.WriteLine((2<=1).toString());
Console.WriteLine((1<=1).toString());
})();
------ Actual Output ------
true
false
false
true
>
false
true
false
>=
false
true
true
<
true
false
false
<=
true
false
true
Test passed!
------ Prefix ------
extern dynamic Console;
Console.WriteLine((10.5+20.4).toString());
Console.WriteLine((20.5-10.4).toString());
Console.WriteLine((10.5*20.5).toString());
Console.WriteLine((20.5/0.5).toString());
Console.WriteLine((22.5%10.5).toString());
------ Expected Output ------
30.9
10.1
215.25
41
1.5
------ Generated JavaScript ------
(function() {
// Start Global Code
Console.WriteLine((10.5 + 20.4).toString());
Console.WriteLine((20.5 - 10.4).toString());
Console.WriteLine((10.5*20.5).toString());
Console.WriteLine((20.5/0.5).toString());
Console.WriteLine((22.5%10.5).toString());
})();
------ Actual Output ------
30.9
10.1
215.25
41
1.5
Test passed!
------ Prefix ------
extern dynamic Console;
Console.WriteLine("Math");
Console.WriteLine((10+20).toString());
Console.WriteLine((10-20).toString());
Console.WriteLine((10*20).toString());
Console.WriteLine((20/10).toString());
Console.WriteLine((22%10).toString());
Console.WriteLine("Bitwise");
Console.WriteLine((0x10 | 0x01).toString());
Console.WriteLine((0xFF & 0x0F).toString());
Console.WriteLine((0xFF ^ 0xF0).toString());
Console.WriteLine("Logical AND");
Console.WriteLine((true && true).toString());
Console.WriteLine((true && false).toString());
Console.WriteLine((false && true).toString());
Console.WriteLine((false && false).toString());
Console.WriteLine("Logical OR");
Console.WriteLine((true || true).toString());
Console.WriteLine((true || false).toString());
Console.WriteLine((false || true).toString());
Console.WriteLine((false || false).toString());
------ Expected Output ------
Math
30
-10
200
2
2
Bitwise
17
15
15
Logical AND
true
false
false
false
Logical OR
true
true
true
false
------ Generated JavaScript ------
(function() {
// Start Global Code
Console.WriteLine("Math");
Console.WriteLine((10 + 20).toString());
Console.WriteLine((10 - 20).toString());
Console.WriteLine((10*20).toString());
Console.WriteLine(((20/10)|0).toString());
Console.WriteLine((22%10).toString());
Console.WriteLine("Bitwise");
Console.WriteLine((16|1).toString());
Console.WriteLine((255&15).toString());
Console.WriteLine((255^240).toString());
Console.WriteLine("Logical AND");
Console.WriteLine((true&&true).toString());
Console.WriteLine((true&&false).toString());
Console.WriteLine((false&&true).toString());
Console.WriteLine((false&&false).toString());
Console.WriteLine("Logical OR");
Console.WriteLine((true||true).toString());
Console.WriteLine((true||false).toString());
Console.WriteLine((false||true).toString());
Console.WriteLine((false||false).toString());
})();
------ Actual Output ------
Math
30
-10
200
2
2
Bitwise
17
15
15
Logical AND
true
false
false
false
Logical OR
true
true
true
false
Test passed!
------ Prefix ------
extern dynamic Console;
Console.WriteLine("Hello" + " " + "World");
------ Expected Output ------
Hello World
------ Generated JavaScript ------
(function() {
// Start Global Code
Console.WriteLine("Hello" + " " + "World");
})();
------ Actual Output ------
Hello World
Test passed!
------ Prefix ------
// no warnings
extern dynamic Console;
string s = null;
Console.WriteLine("OK");
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// Start Global Code
var s=null;
Console.WriteLine("OK");
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------ extern dynamic Console; int x; x=null; ------ Expected Output ------ // exception: cannot implicitly convert ------ Actual Exception ------ Tests.Expressions.cant_assign_null_to_numeric.txt(3,3): cannot implicitly convert 'null' to class 'System.Integer' Test passed!
------ Prefix ------
extern dynamic Console;
class x
{
}
x="OK";
------ Expected Output ------
// exception: The left hand side of an assignment must be a
------ Actual Exception ------
Tests.Expressions.cant_assign_string_to_class.txt(5,1): The left hand side of an assignment must be a variable, property or indexer
Test passed!
------ Prefix ------
extern dynamic Console;
string x()
{
}
x="OK";
------ Expected Output ------
// exception: The left hand side of an assignment must be a
------ Actual Exception ------
Tests.Expressions.cant_assign_to_function.txt(5,1): The left hand side of an assignment must be a variable, property or indexer
Test passed!
------ Prefix ------ extern dynamic Console; int x; x="OK"; ------ Expected Output ------ // exception: cannot implicitly convert ------ Actual Exception ------ Tests.Expressions.cant_assign_to_wrong_type.txt(3,3): cannot implicitly convert class 'System.String' to class 'System.Integer' Test passed!
------ Prefix ------
extern dynamic Console;
class x
{
}
x++;
------ Expected Output ------
// exception: The left hand side of an assignment must be a
------ Actual Exception ------
Tests.Expressions.cant_increment_class.txt(5,1): The left hand side of an assignment must be a variable, property or indexer
Test passed!
------ Prefix ------
extern dynamic Console;
string x()
{
}
x++;
------ Expected Output ------
// exception: The left hand side of an assignment must be a
------ Actual Exception ------
Tests.Expressions.cant_increment_function.txt(5,1): The left hand side of an assignment must be a variable, property or indexer
Test passed!
------ Prefix ------ extern dynamic Console; string a="Hello"; a++; ------ Expected Output ------ // exception: cannot be applied to operand ------ Actual Exception ------ Tests.Expressions.cant_increment_string.txt(4,2): Operator '++' cannot be applied to operand of type class 'System.String' Test passed!
------ Prefix ------ extern dynamic Console; int x="OK"; ------ Expected Output ------ // exception: cannot implicitly convert class ------ Actual Exception ------ Tests.Expressions.cant_init_with_wrong_type.txt(2,7): cannot implicitly convert class 'System.String' to class 'System.Integer' Test passed!
------ Prefix ------
extern dynamic Console;
object x=null;
Console.WriteLine((x==null).toString());
Console.WriteLine((x!=null).toString());
Console.WriteLine((null==x).toString());
Console.WriteLine((null!=x).toString());
------ Expected Output ------
true
false
true
false
------ Generated JavaScript ------
(function() {
// Start Global Code
var x=null;
Console.WriteLine((x===null).toString());
Console.WriteLine((x!==null).toString());
Console.WriteLine((null===x).toString());
Console.WriteLine((null!==x).toString());
})();
------ Actual Output ------
true
false
true
false
Test passed!
------ Prefix ------
// no warnings
// should generate: var strVal=null;
// should generate: var iVal=0;
// should generate: var dblVal=0.0;
// should generate: var bVal=false;
// should generate: var clsVal=null;
// should generate: var itfVal=null;
// should generate: var enumVal=0;
extern dynamic Console;
class MyClass
{
}
interface IItf
{
}
enum MyEnum
{
}
var strVal = default(string);
var iVal = default(int);
var dblVal = default(double);
var bVal = default(bool);
var clsVal = default(MyClass);
var itfVal = default(IItf);
var enumVal = default(MyEnum);
Console.WriteLine("OK");
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// Prefix runtime library
var $dex = {};
$dex.indexOf=Array.prototype.indexOf||function(a){for(var b=0;b<this.length;b++){if(this[b]===a)return b}return-1}
$dex.queryInterface=function(a,b){return a!=null&&a.$interfaces&&$dex.indexOf.call(a.$interfaces,b)>=0?a:null}
// class MyClass
var MyClass = function() {};
MyClass.typeName = 'MyClass';
// interface IItf
var IItf = {};
// enum MyEnum
var MyEnum =
{
};
// Start Global Code
var strVal=null;
var iVal=0;
var dblVal=0.0;
var bVal=false;
var clsVal=null;
var itfVal=null;
var enumVal=0;
Console.WriteLine("OK");
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
// verbose
extern dynamic Console;
// Typical assignment
string x="OK";
Console.WriteLine(((dynamic)x).length.toString());
------ Expected Output ------
2
------ Generated JavaScript ------
(function() {
// Start Global Code
var x="OK";
Console.WriteLine((x).length.toString());
})();
------ Actual Output ------
2
Test passed!
------ Prefix ------
extern dynamic Console;
int a,b;
// Postfix increment
a = 10;
b = a++;
Console.WriteLine(a.toString());
Console.WriteLine(b.toString());
// Postfix decrement
a = 10;
b = a--;
Console.WriteLine(a.toString());
Console.WriteLine(b.toString());
// Prefix increment
a = 10;
b = ++a;
Console.WriteLine(a.toString());
Console.WriteLine(b.toString());
// Prefix decrement
a = 10;
b = --a;
Console.WriteLine(a.toString());
Console.WriteLine(b.toString());
------ Expected Output ------
11
10
9
10
11
11
9
9
------ Generated JavaScript ------
(function() {
// Start Global Code
var a, b;
a = 10;
b = a++;
Console.WriteLine(a.toString());
Console.WriteLine(b.toString());
a = 10;
b = a--;
Console.WriteLine(a.toString());
Console.WriteLine(b.toString());
a = 10;
b = ++a;
Console.WriteLine(a.toString());
Console.WriteLine(b.toString());
a = 10;
b = --a;
Console.WriteLine(a.toString());
Console.WriteLine(b.toString());
})();
------ Actual Output ------
11
10
9
10
11
11
9
9
Test passed!
------ Prefix ------
extern dynamic Console;
dynamic arr = `[1, 2, 3]`;
Console.WriteLine(arr.length);
Console.WriteLine(arr[1]);
arr[1]=23;
Console.WriteLine(arr[1]);
------ Expected Output ------
3
2
23
------ Generated JavaScript ------
(function() {
// Start Global Code
var arr=[1, 2, 3];
Console.WriteLine(arr.length);
Console.WriteLine(arr[1]);
arr[1] = 23;
Console.WriteLine(arr[1]);
})();
------ Actual Output ------
3
2
23
Test passed!
------ Prefix ------ extern dynamic Console; var x=null; ------ Expected Output ------ // exception: cannot assign 'null' ------ Actual Exception ------ Tests.Expressions.inferred_variable_cant_be_null.txt(3,1): cannot assign 'null' to an implicitly-typed local variable Test passed!
------ Prefix ------
extern dynamic Console;
var x="OK";
var y=1.000000;
var a=true, b=false;
Console.WriteLine(x);
Console.WriteLine(y.toString());
Console.WriteLine(a.toString());
Console.WriteLine(b.toString());
------ Expected Output ------
OK
1
true
false
------ Generated JavaScript ------
(function() {
// Start Global Code
var x="OK";
var y=1;
var a=true, b=false;
Console.WriteLine(x);
Console.WriteLine(y.toString());
Console.WriteLine(a.toString());
Console.WriteLine(b.toString());
})();
------ Actual Output ------
OK
1
true
false
Test passed!
------ Prefix ------
// should not generate: |0)|0
extern dynamic Console;
class ClassA
{
public int val=13;
}
ClassA inst = new ClassA();
ClassA GetInstance()
{
// This should only be output once
Console.WriteLine("In GetInstance()");
return inst;
}
// This should compile to:
//
// (temp=GetInstance()).val = (temp.val / b)|0
//
// Not:
//
// GetInstance().val = (GetInstance().val / b)|0
GetInstance().val/=10;
Console.WriteLine(inst.val.toString());
------ Expected Output ------
In GetInstance()
1
------ Generated JavaScript ------
(function() {
// class ClassA
var ClassA = function() {};
ClassA.typeName = 'ClassA';
ClassA.prototype.val = 13;
function GetInstance()
{
Console.WriteLine("In GetInstance()");
return inst;
};
// Start Global Code
var $temp;
var inst=new ClassA();
($temp=GetInstance()).val = (($temp.val/10)|0);
Console.WriteLine(inst.val.toString());
})();
------ Actual Output ------
In GetInstance()
1
Test passed!
------ Prefix ------
// should not generate: |0)|0
extern dynamic Console;
class ClassB
{
public int val=13;
}
// Divide assign where LHS of the assignment count have side effects
class ClassA
{
public ClassB B = new ClassB();
}
ClassA inst = new ClassA();
inst.B.val /= 10;
Console.WriteLine(inst.B.val.toString());
------ Expected Output ------
1
------ Generated JavaScript ------
(function() {
// class ClassB
var ClassB = function() {};
ClassB.typeName = 'ClassB';
ClassB.prototype.val = 13;
// class ClassA
var ClassA = function()
{
this.B = new ClassB();
};
ClassA.typeName = 'ClassA';
ClassA.prototype.B = null;
// Start Global Code
var $temp;
var inst=new ClassA();
($temp=inst.B).val = (($temp.val/10)|0);
Console.WriteLine(inst.B.val.toString());
})();
------ Actual Output ------
1
Test passed!
------ Prefix ------
// should not generate: |0)|0
extern dynamic Console;
// Integer division should result in integer result. To achieve this
// we bitwise or the result of any integer division with 0.
// Divide assign
int a=13;
a/=10;
Console.WriteLine(a.toString());
------ Expected Output ------
1
------ Generated JavaScript ------
(function() {
// Start Global Code
var a=13;
a = ((a/10)|0);
Console.WriteLine(a.toString());
})();
------ Actual Output ------
1
Test passed!
------ Prefix ------
extern dynamic Console;
// Integer division should result in integer result. To achieve this
// we bitwise or the result of any integer division with 0.
int a=13;
int b=10;
// Inline division
Console.WriteLine((a/b).toString());
Console.WriteLine((-a/b).toString());
------ Expected Output ------
1
-1
------ Generated JavaScript ------
(function() {
// Start Global Code
var a=13;
var b=10;
Console.WriteLine(((a/b)|0).toString());
Console.WriteLine(((-a/b)|0).toString());
})();
------ Actual Output ------
1
-1
Test passed!
------ Prefix ------
// no warnings
extern dynamic Console;
Console.WriteLine(true ? "yes" : "no");
Console.WriteLine(false ? "yes" : "no");
------ Expected Output ------
yes
no
------ Generated JavaScript ------
(function() {
// Start Global Code
Console.WriteLine(true ? "yes" : "no");
Console.WriteLine(false ? "yes" : "no");
})();
------ Actual Output ------
yes
no
Test passed!
------ Prefix ------
extern dynamic Console;
Console.WriteLine("this should be a bool" ? "yes" : "no");
------ Expected Output ------
// exception: cannot implicitly convert
------ Actual Exception ------
Tests.Expressions.ternary_condition_must_be_boolean.txt(3,19): cannot implicitly convert class 'System.String' to class 'System.Boolean'
Test passed!
------ Prefix ------ // no warnings extern dynamic Console; Console.WriteLine(true ? 23 : "this should also be an integer"); ------ Expected Output ------ // exception: cannot implicitly convert class 'System.String' to class 'System.Integer' ------ Actual Exception ------ Tests.Expressions.ternary_results_must_be_the_same_type.txt(4,31): cannot implicitly convert class 'System.String' to class 'System.Integer' Test passed!
------ Prefix ------ // no warnings extern dynamic Console; Console.WriteLine(true ? "other result should also be string" : 23); ------ Expected Output ------ // exception: cannot implicitly convert class 'System.Integer' to class 'System.String' ------ Actual Exception ------ Tests.Expressions.ternary_results_must_be_the_same_type_2.txt(4,65): cannot implicitly convert class 'System.Integer' to class 'System.String' Test passed!
------ Prefix ------
extern dynamic Console;
// Negate integer
int a = 10;
a=-a;
Console.WriteLine(a.toString());
// Negate double
double b = 20.5;
b=-b;
Console.WriteLine(b.toString());
// Bitwise not
int c = 0x0F;
c=~c;
Console.WriteLine(c.toString());
// Logical not
bool d = true;
d=!d;
Console.WriteLine(d.toString());
------ Expected Output ------
-10
-20.5
-16
false
------ Generated JavaScript ------
(function() {
// Start Global Code
var a=10;
a = -a;
Console.WriteLine(a.toString());
var b=20.5;
b = -b;
Console.WriteLine(b.toString());
var c=15;
c = ~c;
Console.WriteLine(c.toString());
var d=true;
d = !d;
Console.WriteLine(d.toString());
})();
------ Actual Output ------
-10
-20.5
-16
false
Test passed!
------ Prefix ------
extern dynamic Console;
void test(string str, int i)
{
}
test(10);
------ Expected Output ------
// exception: expects 2 parameters, but 1 were supplied
------ Actual Exception ------
Tests.Functions.argcount_must_match.txt(5,1): function 'test(System.String,System.Integer)': expects 2 parameters, but 1 were supplied
Test passed!
------ Prefix ------
extern dynamic Console;
void test(int x, int y)
{
}
test("X", "Y");
------ Expected Output ------
// exception: some invalid arguments
------ Actual Exception ------
Tests.Functions.argtypes_must_match.txt(5,1): function 'test(System.Integer,System.Integer)': has some invalid arguments
Test passed!
------ Prefix ------
extern dynamic Console;
void test(int x, int y)
{
}
test(23, "Y");
------ Expected Output ------
// exception: some invalid arguments
------ Actual Exception ------
Tests.Functions.argtypes_must_match_2.txt(5,1): function 'test(System.Integer,System.Integer)': has some invalid arguments
Test passed!
------ Prefix ------ myvar(); ------ Expected Output ------ // exception: The name 'myvar' doesn't exist ------ Actual Exception ------ Tests.Functions.doesnt_exist.txt(1,1): The name 'myvar' doesn't exist in the current context Test passed!
------ Prefix ------
extern dynamic Console;
string fn1()
{
return "OK";
}
Console.WriteLine(fn1());
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
function fn1()
{
return "OK";
};
// Start Global Code
Console.WriteLine(fn1());
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
extern dynamic Console;
string message()
{
return "OK";
}
Console.WriteLine(message().length);
------ Expected Output ------
2
------ Generated JavaScript ------
(function() {
function message()
{
return "OK";
};
// Start Global Code
Console.WriteLine(message().length);
})();
------ Actual Output ------
2
Test passed!
------ Prefix ------
extern dynamic Console;
string fn1()
{
return 12;
}
------ Expected Output ------
// exception: cannot implicitly convert
------ Actual Exception ------
Tests.Functions.return_value_must_be_of_correct_type.txt(4,9): cannot implicitly convert class 'System.Integer' to class 'System.String'
Test passed!
------ Prefix ------
extern dynamic Console;
string fn1()
{
return;
}
------ Expected Output ------
// exception: must return a value
------ Actual Exception ------
Tests.Functions.return_value_must_have_value.txt(4,2): The function 'fn1()' must return a value of class 'System.String'
Test passed!
------ Prefix ------
extern dynamic Console;
void fn1()
{
Console.WriteLine("Before");
return;
Console.WriteLine("After");
}
fn1();
------ Expected Output ------
Before
------ Generated JavaScript ------
(function() {
function fn1()
{
Console.WriteLine("Before");
return;
Console.WriteLine("After");
};
// Start Global Code
fn1();
})();
------ Actual Output ------
Before
Test passed!
------ Prefix ------
extern dynamic Console;
void fn1()
{
return "OK";
}
------ Expected Output ------
// exception: the return keyword must not be followed by an expression
------ Actual Exception ------
Tests.Functions.return_void_mustnt_have_value.txt(4,2): Since the function 'fn1()' returns void, the return keyword must not be followed by an expression
Test passed!
------ Prefix ------
extern dynamic Console;
string message()
{
return "OK";
}
Console.WriteLine(message());
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
function message()
{
return "OK";
};
// Start Global Code
Console.WriteLine(message());
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
extern dynamic Console;
string GetMessage()
{
return "OK";
}
Console.WriteLine(GetMessage());
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
function GetMessage()
{
return "OK";
};
// Start Global Code
Console.WriteLine(GetMessage());
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
// no warnings
extern dynamic Console;
class Foo1
{
}
class Foo2
{
}
class Bar<T> where T:class
{
public void fn(T t)
{
Console.WriteLine(t is Foo1);
Console.WriteLine((t as Foo1)!=null);
Console.WriteLine(t is Foo2);
Console.WriteLine((t as Foo2)!=null);
}
}
new Bar<Foo1>().fn(new Foo1());
new Bar<Foo2>().fn(new Foo2());
Console.WriteLine("OK");
------ Expected Output ------
True
True
False
False
False
False
True
True
OK
------ Generated JavaScript ------
(function() {
// Prefix runtime library
var $dex = {};
$dex.indexOf=Array.prototype.indexOf||function(a){for(var b=0;b<this.length;b++){if(this[b]===a)return b}return-1}
$dex.queryInterface=function(a,b){return a!=null&&a.$interfaces&&$dex.indexOf.call(a.$interfaces,b)>=0?a:null}
$dex.dynamicCast=function(a,b){if(b instanceof Function)return a instanceof b?a:null;else return $dex.queryInterface(a,b)}
$dex.dynamicIs=function(a,b){return typeof(b)==="string"?typeof(a)===b:$dex.dynamicCast(a,b)!==null}
// class Foo1
var Foo1 = function() {};
Foo1.typeName = 'Foo1';
// class Foo2
var Foo2 = function() {};
Foo2.typeName = 'Foo2';
// class Bar<>
var Bar$1 = function() {};
Bar$1.typeName = 'Bar<>';
Bar$1.prototype.fn = function(t)
{
Console.WriteLine($dex.dynamicIs(t, Foo1));
Console.WriteLine(($dex.dynamicCast(t, Foo1))!==null);
Console.WriteLine($dex.dynamicIs(t, Foo2));
Console.WriteLine(($dex.dynamicCast(t, Foo2))!==null);
};
// Start Global Code
(new Bar$1()).fn(new Foo1());
(new Bar$1()).fn(new Foo2());
Console.WriteLine("OK");
})();
------ Actual Output ------
True
True
False
False
False
False
True
True
OK
Test passed!
------ Prefix ------
// no warnings
extern dynamic Console;
class Foo1
{
}
class Foo2
{
}
class Bar<T>
{
public void fn(T t)
{
Console.WriteLine(t is Foo1);
Console.WriteLine((t as Foo1)!=null);
Console.WriteLine(t is Foo2);
Console.WriteLine((t as Foo2)!=null);
}
}
new Bar<Foo1>().fn(new Foo1());
new Bar<Foo2>().fn(new Foo2());
Console.WriteLine("OK");
------ Expected Output ------
True
True
False
False
False
False
True
True
OK
------ Generated JavaScript ------
(function() {
// Prefix runtime library
var $dex = {};
$dex.indexOf=Array.prototype.indexOf||function(a){for(var b=0;b<this.length;b++){if(this[b]===a)return b}return-1}
$dex.queryInterface=function(a,b){return a!=null&&a.$interfaces&&$dex.indexOf.call(a.$interfaces,b)>=0?a:null}
$dex.dynamicCast=function(a,b){if(b instanceof Function)return a instanceof b?a:null;else return $dex.queryInterface(a,b)}
$dex.dynamicIs=function(a,b){return typeof(b)==="string"?typeof(a)===b:$dex.dynamicCast(a,b)!==null}
// class Foo1
var Foo1 = function() {};
Foo1.typeName = 'Foo1';
// class Foo2
var Foo2 = function() {};
Foo2.typeName = 'Foo2';
// class Bar<>
var Bar$1 = function() {};
Bar$1.typeName = 'Bar<>';
Bar$1.prototype.fn = function(t)
{
Console.WriteLine($dex.dynamicIs(t, Foo1));
Console.WriteLine(($dex.dynamicCast(t, Foo1))!==null);
Console.WriteLine($dex.dynamicIs(t, Foo2));
Console.WriteLine(($dex.dynamicCast(t, Foo2))!==null);
};
// Start Global Code
(new Bar$1()).fn(new Foo1());
(new Bar$1()).fn(new Foo2());
Console.WriteLine("OK");
})();
------ Actual Output ------
True
True
False
False
False
False
True
True
OK
Test passed!
------ Prefix ------
// no warnings
extern dynamic Console;
class Foo
{
}
class Bar<T> where T:class
{
public void fn(Foo foo)
{
Console.WriteLine((foo as T)!=null);
}
}
new Bar<Foo>().fn(new Foo());
------ Expected Output ------
True
------ Generated JavaScript ------
(function() {
// Prefix runtime library
var $dex = {};
$dex.indexOf=Array.prototype.indexOf||function(a){for(var b=0;b<this.length;b++){if(this[b]===a)return b}return-1}
$dex.queryInterface=function(a,b){return a!=null&&a.$interfaces&&$dex.indexOf.call(a.$interfaces,b)>=0?a:null}
$dex.dynamicCast=function(a,b){if(b instanceof Function)return a instanceof b?a:null;else return $dex.queryInterface(a,b)}
$dex.makeCachedGeneric=function(a,b,c){var d=[];for(var e=0;e<b.length;e++)d.push(b[e]instanceof Function?b[e].typeName:b[e]);f=d.join(',');if(!a.closed)a.closed={};var g=a.closed[f];if(!g){g=c(f);a.closed[f]=g};return g}
$dex.resolveGenericArg=function(a,b){if(typeof(a)=='number')return b?b[a]:a;return a}
$dex.resolveGenericArgs=function(a,b){for(var c=0,d=[];c<a.length;c++)d.push($dex.resolveGenericArg(a[c],b));return d}
$dex.setupGenericClass=function(a,b,c,d){d.makeGeneric=function(e){return $dex.makeCachedGeneric(d,e,function(f){var g=function(){d.apply(this,arguments)};if(b==null){g.prototype=new d()}else{var h=$dex.resolveGenericArgs(c,e);g.prototype=new(b.makeGeneric(h))();for(var i in d.prototype)g.prototype[i]=d.prototype[i]}for(var s in d.static)g[s]=d.static[s];g.typeName=d.typeName+"["+f+"]";g.prototype.constructor=g;g.prototype['closedClass$'+a.toString()]=g;g.genericArgs=e;var j=d.prototype.$interfaces,k=j;if(j){for(var i=0,len=j.length;i<len;i++){if(typeof(j[i]instanceof Array)){if(k===j)k=j.slice(0);k[i]=j[i][0].makeGeneric($dex.resolveGenericArgs(j[i][1],e))}}g.prototype.$interfaces=k}if(g.$cctor)g.$cctor();return g})};return d}
// class Foo
var Foo = function() {};
Foo.typeName = 'Foo';
// class Bar<>
var Bar$1 = $dex.setupGenericClass(1, null, null, function() {});
Bar$1.typeName = 'Bar<>';
Bar$1.prototype.fn = function(foo)
{
var T = this.closedClass$1.genericArgs[0];
Console.WriteLine(($dex.dynamicCast(foo, T))!==null);
};
// Start Global Code
(new (Bar$1.makeGeneric([Foo]))()).fn(new Foo());
})();
------ Actual Output ------
True
Test passed!
------ Prefix ------
// no warnings
extern dynamic Console;
class Foo1
{
}
class Foo2
{
}
class Bar<T> where T:class
{
public void fn(T t)
{
Console.WriteLine(t is Foo1);
Console.WriteLine(t is Foo2);
}
}
new Bar<Foo1>().fn(new Foo1());
new Bar<Foo2>().fn(new Foo2());
Console.WriteLine("OK");
------ Expected Output ------
True
False
False
True
OK
------ Generated JavaScript ------
(function() {
// Prefix runtime library
var $dex = {};
$dex.indexOf=Array.prototype.indexOf||function(a){for(var b=0;b<this.length;b++){if(this[b]===a)return b}return-1}
$dex.queryInterface=function(a,b){return a!=null&&a.$interfaces&&$dex.indexOf.call(a.$interfaces,b)>=0?a:null}
$dex.dynamicCast=function(a,b){if(b instanceof Function)return a instanceof b?a:null;else return $dex.queryInterface(a,b)}
$dex.dynamicIs=function(a,b){return typeof(b)==="string"?typeof(a)===b:$dex.dynamicCast(a,b)!==null}
// class Foo1
var Foo1 = function() {};
Foo1.typeName = 'Foo1';
// class Foo2
var Foo2 = function() {};
Foo2.typeName = 'Foo2';
// class Bar<>
var Bar$1 = function() {};
Bar$1.typeName = 'Bar<>';
Bar$1.prototype.fn = function(t)
{
Console.WriteLine($dex.dynamicIs(t, Foo1));
Console.WriteLine($dex.dynamicIs(t, Foo2));
};
// Start Global Code
(new Bar$1()).fn(new Foo1());
(new Bar$1()).fn(new Foo2());
Console.WriteLine("OK");
})();
------ Actual Output ------
True
False
False
True
OK
Test passed!
------ Prefix ------
// no warnings
extern dynamic Console;
class Foo1
{
}
class Foo2
{
}
class Bar<T>
{
public void fn(T t)
{
Console.WriteLine(t is Foo1);
Console.WriteLine(t is Foo2);
}
}
new Bar<Foo1>().fn(new Foo1());
new Bar<Foo2>().fn(new Foo2());
Console.WriteLine("OK");
------ Expected Output ------
True
False
False
True
OK
------ Generated JavaScript ------
(function() {
// Prefix runtime library
var $dex = {};
$dex.indexOf=Array.prototype.indexOf||function(a){for(var b=0;b<this.length;b++){if(this[b]===a)return b}return-1}
$dex.queryInterface=function(a,b){return a!=null&&a.$interfaces&&$dex.indexOf.call(a.$interfaces,b)>=0?a:null}
$dex.dynamicCast=function(a,b){if(b instanceof Function)return a instanceof b?a:null;else return $dex.queryInterface(a,b)}
$dex.dynamicIs=function(a,b){return typeof(b)==="string"?typeof(a)===b:$dex.dynamicCast(a,b)!==null}
// class Foo1
var Foo1 = function() {};
Foo1.typeName = 'Foo1';
// class Foo2
var Foo2 = function() {};
Foo2.typeName = 'Foo2';
// class Bar<>
var Bar$1 = function() {};
Bar$1.typeName = 'Bar<>';
Bar$1.prototype.fn = function(t)
{
Console.WriteLine($dex.dynamicIs(t, Foo1));
Console.WriteLine($dex.dynamicIs(t, Foo2));
};
// Start Global Code
(new Bar$1()).fn(new Foo1());
(new Bar$1()).fn(new Foo2());
Console.WriteLine("OK");
})();
------ Actual Output ------
True
False
False
True
OK
Test passed!
------ Prefix ------
// no warnings
extern dynamic Console;
class Foo
{
}
class Bar<T> where T:class
{
public void fn(Foo foo)
{
Console.WriteLine(foo is T);
}
}
new Bar<Foo>().fn(new Foo());
------ Expected Output ------
True
------ Generated JavaScript ------
(function() {
// Prefix runtime library
var $dex = {};
$dex.indexOf=Array.prototype.indexOf||function(a){for(var b=0;b<this.length;b++){if(this[b]===a)return b}return-1}
$dex.queryInterface=function(a,b){return a!=null&&a.$interfaces&&$dex.indexOf.call(a.$interfaces,b)>=0?a:null}
$dex.dynamicCast=function(a,b){if(b instanceof Function)return a instanceof b?a:null;else return $dex.queryInterface(a,b)}
$dex.dynamicIs=function(a,b){return typeof(b)==="string"?typeof(a)===b:$dex.dynamicCast(a,b)!==null}
$dex.makeCachedGeneric=function(a,b,c){var d=[];for(var e=0;e<b.length;e++)d.push(b[e]instanceof Function?b[e].typeName:b[e]);f=d.join(',');if(!a.closed)a.closed={};var g=a.closed[f];if(!g){g=c(f);a.closed[f]=g};return g}
$dex.resolveGenericArg=function(a,b){if(typeof(a)=='number')return b?b[a]:a;return a}
$dex.resolveGenericArgs=function(a,b){for(var c=0,d=[];c<a.length;c++)d.push($dex.resolveGenericArg(a[c],b));return d}
$dex.setupGenericClass=function(a,b,c,d){d.makeGeneric=function(e){return $dex.makeCachedGeneric(d,e,function(f){var g=function(){d.apply(this,arguments)};if(b==null){g.prototype=new d()}else{var h=$dex.resolveGenericArgs(c,e);g.prototype=new(b.makeGeneric(h))();for(var i in d.prototype)g.prototype[i]=d.prototype[i]}for(var s in d.static)g[s]=d.static[s];g.typeName=d.typeName+"["+f+"]";g.prototype.constructor=g;g.prototype['closedClass$'+a.toString()]=g;g.genericArgs=e;var j=d.prototype.$interfaces,k=j;if(j){for(var i=0,len=j.length;i<len;i++){if(typeof(j[i]instanceof Array)){if(k===j)k=j.slice(0);k[i]=j[i][0].makeGeneric($dex.resolveGenericArgs(j[i][1],e))}}g.prototype.$interfaces=k}if(g.$cctor)g.$cctor();return g})};return d}
// class Foo
var Foo = function() {};
Foo.typeName = 'Foo';
// class Bar<>
var Bar$1 = $dex.setupGenericClass(1, null, null, function() {});
Bar$1.typeName = 'Bar<>';
Bar$1.prototype.fn = function(foo)
{
var T = this.closedClass$1.genericArgs[0];
Console.WriteLine($dex.dynamicIs(foo, T));
};
// Start Global Code
(new (Bar$1.makeGeneric([Foo]))()).fn(new Foo());
})();
------ Actual Output ------
True
Test passed!
------ Prefix ------
// no warnings
extern dynamic Console;
class Foo
{
}
class Bar<T>
{
public void fn(Foo foo)
{
Console.WriteLine(foo is T);
}
}
new Bar<Foo>().fn(new Foo());
------ Expected Output ------
True
------ Generated JavaScript ------
(function() {
// Prefix runtime library
var $dex = {};
$dex.indexOf=Array.prototype.indexOf||function(a){for(var b=0;b<this.length;b++){if(this[b]===a)return b}return-1}
$dex.queryInterface=function(a,b){return a!=null&&a.$interfaces&&$dex.indexOf.call(a.$interfaces,b)>=0?a:null}
$dex.dynamicCast=function(a,b){if(b instanceof Function)return a instanceof b?a:null;else return $dex.queryInterface(a,b)}
$dex.dynamicIs=function(a,b){return typeof(b)==="string"?typeof(a)===b:$dex.dynamicCast(a,b)!==null}
$dex.makeCachedGeneric=function(a,b,c){var d=[];for(var e=0;e<b.length;e++)d.push(b[e]instanceof Function?b[e].typeName:b[e]);f=d.join(',');if(!a.closed)a.closed={};var g=a.closed[f];if(!g){g=c(f);a.closed[f]=g};return g}
$dex.resolveGenericArg=function(a,b){if(typeof(a)=='number')return b?b[a]:a;return a}
$dex.resolveGenericArgs=function(a,b){for(var c=0,d=[];c<a.length;c++)d.push($dex.resolveGenericArg(a[c],b));return d}
$dex.setupGenericClass=function(a,b,c,d){d.makeGeneric=function(e){return $dex.makeCachedGeneric(d,e,function(f){var g=function(){d.apply(this,arguments)};if(b==null){g.prototype=new d()}else{var h=$dex.resolveGenericArgs(c,e);g.prototype=new(b.makeGeneric(h))();for(var i in d.prototype)g.prototype[i]=d.prototype[i]}for(var s in d.static)g[s]=d.static[s];g.typeName=d.typeName+"["+f+"]";g.prototype.constructor=g;g.prototype['closedClass$'+a.toString()]=g;g.genericArgs=e;var j=d.prototype.$interfaces,k=j;if(j){for(var i=0,len=j.length;i<len;i++){if(typeof(j[i]instanceof Array)){if(k===j)k=j.slice(0);k[i]=j[i][0].makeGeneric($dex.resolveGenericArgs(j[i][1],e))}}g.prototype.$interfaces=k}if(g.$cctor)g.$cctor();return g})};return d}
// class Foo
var Foo = function() {};
Foo.typeName = 'Foo';
// class Bar<>
var Bar$1 = $dex.setupGenericClass(1, null, null, function() {});
Bar$1.typeName = 'Bar<>';
Bar$1.prototype.fn = function(foo)
{
var T = this.closedClass$1.genericArgs[0];
Console.WriteLine($dex.dynamicIs(foo, T));
};
// Start Global Code
(new (Bar$1.makeGeneric([Foo]))()).fn(new Foo());
})();
------ Actual Output ------
True
Test passed!
------ Prefix ------
extern dynamic Console;
class Foo<T>
{
}
class Bar<T> : Foo<string>
{
}
Console.WriteLine("OK");
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// class Foo<>
var Foo$1 = function() {};
Foo$1.typeName = 'Foo<>';
// class Bar<>
var Bar$1 = function() {};
Bar$1.typeName = 'Bar<>';
Bar$1.prototype = new Foo$1();
Bar$1.prototype.constructor = Bar$1;
// Start Global Code
Console.WriteLine("OK");
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
extern dynamic Console;
interface Foo<T>
{
}
class Bar<T> : Foo<string>
{
}
Console.WriteLine("OK");
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// Prefix runtime library
var $dex = {};
$dex.indexOf=Array.prototype.indexOf||function(a){for(var b=0;b<this.length;b++){if(this[b]===a)return b}return-1}
$dex.queryInterface=function(a,b){return a!=null&&a.$interfaces&&$dex.indexOf.call(a.$interfaces,b)>=0?a:null}
$dex.makeCachedGeneric=function(a,b,c){var d=[];for(var e=0;e<b.length;e++)d.push(b[e]instanceof Function?b[e].typeName:b[e]);f=d.join(',');if(!a.closed)a.closed={};var g=a.closed[f];if(!g){g=c(f);a.closed[f]=g};return g}
$dex.makeGenericInterface=function(a){return $dex.makeCachedGeneric(this,a,function(){return{}})}
// interface Foo<>
var Foo$1 = {};
Foo$1.makeGeneric = $dex.makeGenericInterface;
// class Bar<>
var Bar$1 = function() {};
Bar$1.typeName = 'Bar<>';
Bar$1.prototype.$interfaces = [Foo$1.makeGeneric(['string'])];
// Start Global Code
Console.WriteLine("OK");
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
extern dynamic Console;
class Foo<T>
{
}
class Bar<T> : Foo<T>
{
}
Console.WriteLine("OK");
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// class Foo<>
var Foo$1 = function() {};
Foo$1.typeName = 'Foo<>';
// class Bar<>
var Bar$1 = function() {};
Bar$1.typeName = 'Bar<>';
Bar$1.prototype = new Foo$1();
Bar$1.prototype.constructor = Bar$1;
// Start Global Code
Console.WriteLine("OK");
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
extern dynamic Console;
interface Foo<T>
{
}
class Bar<T> : Foo<T>
{
}
var t= new Bar<string>();
t=t;
Console.WriteLine("OK");
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// Prefix runtime library
var $dex = {};
$dex.indexOf=Array.prototype.indexOf||function(a){for(var b=0;b<this.length;b++){if(this[b]===a)return b}return-1}
$dex.queryInterface=function(a,b){return a!=null&&a.$interfaces&&$dex.indexOf.call(a.$interfaces,b)>=0?a:null}
$dex.makeCachedGeneric=function(a,b,c){var d=[];for(var e=0;e<b.length;e++)d.push(b[e]instanceof Function?b[e].typeName:b[e]);f=d.join(',');if(!a.closed)a.closed={};var g=a.closed[f];if(!g){g=c(f);a.closed[f]=g};return g}
$dex.makeGenericInterface=function(a){return $dex.makeCachedGeneric(this,a,function(){return{}})}
// interface Foo<>
var Foo$1 = {};
Foo$1.makeGeneric = $dex.makeGenericInterface;
// class Bar<>
var Bar$1 = function() {};
Bar$1.typeName = 'Bar<>';
Bar$1.prototype.$interfaces = [[Foo$1,[0]]];
// Start Global Code
var t=new Bar$1();
t = t;
Console.WriteLine("OK");
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
extern dynamic Console;
class Obj<T>
{
}
class Obj<T,U>
{
}
class Obj<T,U,V>
{
}
Console.WriteLine("OK");
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// class Obj<>
var Obj$1 = function() {};
Obj$1.typeName = 'Obj<>';
// class Obj<,>
var Obj$2 = function() {};
Obj$2.typeName = 'Obj<,>';
// class Obj<,,>
var Obj$3 = function() {};
Obj$3.typeName = 'Obj<,,>';
// Start Global Code
Console.WriteLine("OK");
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
// no warnings
extern dynamic Console;
class Foo
{
}
class Bar<T> where T:Foo
{
void fn(T t)
{
Foo foo = t;
}
}
Console.WriteLine("OK");
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// class Foo
var Foo = function() {};
Foo.typeName = 'Foo';
// class Bar<>
var Bar$1 = function() {};
Bar$1.typeName = 'Bar<>';
Bar$1.prototype.fn = function(t)
{
var foo=t;
};
// Start Global Code
Console.WriteLine("OK");
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
// no warnings
extern dynamic Console;
class Foo
{
}
class Bar
{
}
T fn<T>(T a) where T:new()
{
return new T();
}
Console.WriteLine(fn(new Foo()) is Foo);
Console.WriteLine(fn(new Bar()) is Bar);
------ Expected Output ------
True
True
------ Generated JavaScript ------
(function() {
// class Foo
var Foo = function() {};
Foo.typeName = 'Foo';
// class Bar
var Bar = function() {};
Bar.typeName = 'Bar';
function fn$1($gargs, a)
{
var T = $gargs[0];
return new T();
};
// Start Global Code
Console.WriteLine((fn$1([Foo], new Foo()))!==null);
Console.WriteLine((fn$1([Bar], new Bar()))!==null);
})();
------ Actual Output ------
True
True
Test passed!
------ Prefix ------
// should generate: Foo$1
// should generate: Foo$2
extern dynamic Console;
class Foo<T>
{
}
class Foo<T,U>
{
}
Console.WriteLine("OK");
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// class Foo<>
var Foo$1 = function() {};
Foo$1.typeName = 'Foo<>';
// class Foo<,>
var Foo$2 = function() {};
Foo$2.typeName = 'Foo<,>';
// Start Global Code
Console.WriteLine("OK");
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
// should generate: fn$1$1
// should generate: fn$1$2
// should generate: fn$2
// should not generate: fn$2$1
extern dynamic Console;
class Foo
{
public void fn<T>()
{
}
public void fn<T>(string p)
{
}
public void fn<T,U>()
{
}
}
new Foo().fn<bool>();
Console.WriteLine("OK");
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// class Foo
var Foo = function() {};
Foo.typeName = 'Foo';
Foo.prototype.fn$1$1 = function()
{
};
Foo.prototype.fn$1$2 = function(p)
{
};
Foo.prototype.fn$2 = function()
{
};
// Start Global Code
(new Foo()).fn$1$1();
Console.WriteLine("OK");
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
// should generate: Foo$1
// should generate: Foo$2
extern dynamic Console;
interface Foo<T>
{
}
interface Foo<T,U>
{
}
Console.WriteLine("OK");
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// Prefix runtime library
var $dex = {};
$dex.indexOf=Array.prototype.indexOf||function(a){for(var b=0;b<this.length;b++){if(this[b]===a)return b}return-1}
$dex.queryInterface=function(a,b){return a!=null&&a.$interfaces&&$dex.indexOf.call(a.$interfaces,b)>=0?a:null}
$dex.makeCachedGeneric=function(a,b,c){var d=[];for(var e=0;e<b.length;e++)d.push(b[e]instanceof Function?b[e].typeName:b[e]);f=d.join(',');if(!a.closed)a.closed={};var g=a.closed[f];if(!g){g=c(f);a.closed[f]=g};return g}
$dex.makeGenericInterface=function(a){return $dex.makeCachedGeneric(this,a,function(){return{}})}
// interface Foo<>
var Foo$1 = {};
Foo$1.makeGeneric = $dex.makeGenericInterface;
// interface Foo<,>
var Foo$2 = {};
Foo$2.makeGeneric = $dex.makeGenericInterface;
// Start Global Code
Console.WriteLine("OK");
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
// should generate: $gargs
extern dynamic Console;
class Foo
{
public void fn()
{
Console.WriteLine("OK");
}
}
T make<T>() where T:new()
{
return new T();
}
make<Foo>().fn();
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// class Foo
var Foo = function() {};
Foo.typeName = 'Foo';
Foo.prototype.fn = function()
{
Console.WriteLine("OK");
};
function make$1($gargs)
{
var T = $gargs[0];
return new T();
};
// Start Global Code
make$1([Foo]).fn();
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
// no warnings
extern dynamic Console;
class Foo
{
}
class Bar<T>
{
public void fn(Foo foo)
{
Console.WriteLine((foo as T)!=null);
}
}
------ Expected Output ------
// exception: cannot be used with the 'as' operator
------ Actual Exception ------
Tests.Generics.cant_dynamically_cast_to_unconstrained_generic_arg.txt(13,29): 'generic type argument 'T'' cannot be used with the 'as' operator because it does not have a class type constraint nor a 'class' constraint
Test passed!
------ Prefix ------
// no warnings
class C
{
}
var x = new C<int>();
------ Expected Output ------
// exception: non-generic types cannot be used with type arguments
------ Actual Exception ------
Tests.Generics.cant_have_typeargs_with_non_generic_type.txt(6,13): class 'C': non-generic types cannot be used with type arguments
Test passed!
------ Prefix ------
extern dynamic Console;
class Foo<T>
{
}
class Bar<T> : Foo<Bar<string>>
{
}
Console.WriteLine("OK");
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// class Foo<>
var Foo$1 = function() {};
Foo$1.typeName = 'Foo<>';
// class Bar<>
var Bar$1 = function() {};
Bar$1.typeName = 'Bar<>';
Bar$1.prototype = new Foo$1();
Bar$1.prototype.constructor = Bar$1;
// Start Global Code
Console.WriteLine("OK");
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
extern dynamic Console;
interface Foo<T>
{
}
class Bar<T> : Foo<Bar<string>>
{
}
Console.WriteLine("OK");
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// Prefix runtime library
var $dex = {};
$dex.indexOf=Array.prototype.indexOf||function(a){for(var b=0;b<this.length;b++){if(this[b]===a)return b}return-1}
$dex.queryInterface=function(a,b){return a!=null&&a.$interfaces&&$dex.indexOf.call(a.$interfaces,b)>=0?a:null}
$dex.makeCachedGeneric=function(a,b,c){var d=[];for(var e=0;e<b.length;e++)d.push(b[e]instanceof Function?b[e].typeName:b[e]);f=d.join(',');if(!a.closed)a.closed={};var g=a.closed[f];if(!g){g=c(f);a.closed[f]=g};return g}
$dex.makeGenericInterface=function(a){return $dex.makeCachedGeneric(this,a,function(){return{}})}
// interface Foo<>
var Foo$1 = {};
Foo$1.makeGeneric = $dex.makeGenericInterface;
// class Bar<>
var Bar$1 = function() {};
Bar$1.typeName = 'Bar<>';
Bar$1.prototype.$interfaces = [Foo$1.makeGeneric([Bar$1])];
// Start Global Code
Console.WriteLine("OK");
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
// no warnings
extern dynamic Console;
class Foo<T>
{
class Bar<U> where U:Foo<int>
{
}
}
------ Expected Output ------
------ Generated JavaScript ------
(function() {
// class Foo<>
var Foo$1 = function() {};
Foo$1.typeName = 'Foo<>';
// class Foo<>.Bar<>
Foo$1.Bar$1 = function() {};
Foo$1.Bar$1.typeName = 'Foo<>.Bar<>';
// Start Global Code
})();
------ Actual Output ------
Test passed!
------ Prefix ------
// no warnings
extern dynamic Console;
class Bar<T>
{
public Bar<int> fld;
}
------ Expected Output ------
------ Generated JavaScript ------
(function() {
// class Bar<>
var Bar$1 = function() {};
Bar$1.typeName = 'Bar<>';
Bar$1.prototype.fld = null;
// Start Global Code
})();
------ Actual Output ------
Test passed!
------ Prefix ------
// no warnings
extern dynamic Console;
class Bar<T>
{
public void fn(Bar<int> fn)
{
}
}
------ Expected Output ------
------ Generated JavaScript ------
(function() {
// class Bar<>
var Bar$1 = function() {};
Bar$1.typeName = 'Bar<>';
Bar$1.prototype.fn = function(fn)
{
};
// Start Global Code
})();
------ Actual Output ------
Test passed!
------ Prefix ------
// no warnings
extern dynamic Console;
class Bar<T>
{
public Bar<int> prop
{
get
{
return new Bar<int>();
}
}
}
------ Expected Output ------
------ Generated JavaScript ------
(function() {
// class Bar<>
var Bar$1 = function() {};
Bar$1.typeName = 'Bar<>';
Bar$1.prototype.get_prop = function()
{
return new Bar$1();
};
// Start Global Code
})();
------ Actual Output ------
Test passed!
------ Prefix ------
// no warnings
extern dynamic Console;
class Bar<T>
{
public Bar<int> fn()
{
return null;
}
}
------ Expected Output ------
------ Generated JavaScript ------
(function() {
// class Bar<>
var Bar$1 = function() {};
Bar$1.typeName = 'Bar<>';
Bar$1.prototype.fn = function()
{
return null;
};
// Start Global Code
})();
------ Actual Output ------
Test passed!
------ Prefix ------
extern dynamic Console;
class Bar
{
}
class Foo<T> where T : Bar
{
}
Console.WriteLine("OK");
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// class Bar
var Bar = function() {};
Bar.typeName = 'Bar';
// class Foo<>
var Foo$1 = function() {};
Foo$1.typeName = 'Foo<>';
// Start Global Code
Console.WriteLine("OK");
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
extern dynamic Console;
class Foo<T> where T : class
{
}
Console.WriteLine("OK");
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// class Foo<>
var Foo$1 = function() {};
Foo$1.typeName = 'Foo<>';
// Start Global Code
Console.WriteLine("OK");
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
extern dynamic Console;
class Bar
{
}
class Foo<T> where T : class, Bar, new()
{
}
Console.WriteLine("OK");
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// class Bar
var Bar = function() {};
Bar.typeName = 'Bar';
// class Foo<>
var Foo$1 = function() {};
Foo$1.typeName = 'Foo<>';
// Start Global Code
Console.WriteLine("OK");
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
extern dynamic Console;
class Foo<T> where T : new()
{
}
Console.WriteLine("OK");
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// class Foo<>
var Foo$1 = function() {};
Foo$1.typeName = 'Foo<>';
// Start Global Code
Console.WriteLine("OK");
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
extern dynamic Console;
class Bar
{
}
class Foo<T> where T : class, new(), Bar
{
}
Console.WriteLine("OK");
------ Expected Output ------
// exception: must be at the end of the constraint list
------ Actual Exception ------
Tests.Generics.constraint_new_must_be_last.txt(7,36): class 'Foo<>': constraint 'new()' on generic type argument 'T' must be at the end of the constraint list
Test passed!
------ Prefix ------
extern dynamic Console;
interface IEnumerable<T>
{
}
class Foo<T> where T : IEnumerable<T>
{
}
Console.WriteLine("OK");
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// Prefix runtime library
var $dex = {};
$dex.indexOf=Array.prototype.indexOf||function(a){for(var b=0;b<this.length;b++){if(this[b]===a)return b}return-1}
$dex.queryInterface=function(a,b){return a!=null&&a.$interfaces&&$dex.indexOf.call(a.$interfaces,b)>=0?a:null}
$dex.makeCachedGeneric=function(a,b,c){var d=[];for(var e=0;e<b.length;e++)d.push(b[e]instanceof Function?b[e].typeName:b[e]);f=d.join(',');if(!a.closed)a.closed={};var g=a.closed[f];if(!g){g=c(f);a.closed[f]=g};return g}
$dex.makeGenericInterface=function(a){return $dex.makeCachedGeneric(this,a,function(){return{}})}
// interface IEnumerable<>
var IEnumerable$1 = {};
IEnumerable$1.makeGeneric = $dex.makeGenericInterface;
// class Foo<>
var Foo$1 = function() {};
Foo$1.typeName = 'Foo<>';
// Start Global Code
Console.WriteLine("OK");
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
class Foo<T>
where T : class
where T: new()
{
}
------ Expected Output ------
// exception: a constraint clause has already been specified
------ Actual Exception ------
Tests.Generics.constraints_must_be_in_a_single_where_clause.txt(3,9): class 'Foo<>': a constraint clause has already been specified for generic type argument 'T'. All of the constraints for a type parameter must be specified in a single where clause.
Test passed!
------ Prefix ------
extern dynamic Console;
class Foo<T,U,V>
{
}
Console.WriteLine("OK");
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// class Foo<,,>
var Foo$3 = function() {};
Foo$3.typeName = 'Foo<,,>';
// Start Global Code
Console.WriteLine("OK");
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
extern dynamic Console;
class Foo<T>
{
}
Console.WriteLine("OK");
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// class Foo<>
var Foo$1 = function() {};
Foo$1.typeName = 'Foo<>';
// Start Global Code
Console.WriteLine("OK");
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
// no warnings
// should generate: var refVal=null;
// should not generate: setupGenericClass
// should not generate: $dex.getDefaultValue
extern dynamic Console;
class MyClass<T> where T:class
{
void fn()
{
var refVal = default(T);
}
}
Console.WriteLine("OK");
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// class MyClass<>
var MyClass$1 = function() {};
MyClass$1.typeName = 'MyClass<>';
MyClass$1.prototype.fn = function()
{
var refVal=null;
};
// Start Global Code
Console.WriteLine("OK");
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
// no warnings
// should generate: $dex.getDefaultValue(T)
// should generate: setupGenericClass
// should generate: $dex.getDefaultValue
extern dynamic Console;
enum MyEnum
{
}
class MyClass<T>
{
public void fn()
{
Console.WriteLine(default(T));
}
}
new MyClass<bool>().fn();
new MyClass<int>().fn();
new MyClass<double>().fn();
new MyClass<MyEnum>().fn();
------ Expected Output ------
False
0
0
0
------ Generated JavaScript ------
(function() {
// Prefix runtime library
var $dex = {};
$dex.getDefaultValue=function(a){switch(a){case'number':return 0;case'boolean':return false}return null}
$dex.makeCachedGeneric=function(a,b,c){var d=[];for(var e=0;e<b.length;e++)d.push(b[e]instanceof Function?b[e].typeName:b[e]);f=d.join(',');if(!a.closed)a.closed={};var g=a.closed[f];if(!g){g=c(f);a.closed[f]=g};return g}
$dex.resolveGenericArg=function(a,b){if(typeof(a)=='number')return b?b[a]:a;return a}
$dex.resolveGenericArgs=function(a,b){for(var c=0,d=[];c<a.length;c++)d.push($dex.resolveGenericArg(a[c],b));return d}
$dex.setupGenericClass=function(a,b,c,d){d.makeGeneric=function(e){return $dex.makeCachedGeneric(d,e,function(f){var g=function(){d.apply(this,arguments)};if(b==null){g.prototype=new d()}else{var h=$dex.resolveGenericArgs(c,e);g.prototype=new(b.makeGeneric(h))();for(var i in d.prototype)g.prototype[i]=d.prototype[i]}for(var s in d.static)g[s]=d.static[s];g.typeName=d.typeName+"["+f+"]";g.prototype.constructor=g;g.prototype['closedClass$'+a.toString()]=g;g.genericArgs=e;var j=d.prototype.$interfaces,k=j;if(j){for(var i=0,len=j.length;i<len;i++){if(typeof(j[i]instanceof Array)){if(k===j)k=j.slice(0);k[i]=j[i][0].makeGeneric($dex.resolveGenericArgs(j[i][1],e))}}g.prototype.$interfaces=k}if(g.$cctor)g.$cctor();return g})};return d}
// enum MyEnum
var MyEnum =
{
};
// class MyClass<>
var MyClass$1 = $dex.setupGenericClass(1, null, null, function() {});
MyClass$1.typeName = 'MyClass<>';
MyClass$1.prototype.fn = function()
{
var T = this.closedClass$1.genericArgs[0];
Console.WriteLine($dex.getDefaultValue(T));
};
// Start Global Code
(new (MyClass$1.makeGeneric(['boolean']))()).fn();
(new (MyClass$1.makeGeneric(['number']))()).fn();
(new (MyClass$1.makeGeneric(['number']))()).fn();
(new (MyClass$1.makeGeneric(['number']))()).fn();
})();
------ Actual Output ------
False
0
0
0
Test passed!
------ Prefix ------
// no warnings
extern dynamic Console;
class MyList<T>
{
public MyList()
{
}
public void Add(T t)
{
_data.push(t);
}
public T GetAt(int index)
{
return (T)(`this._data[index]`);
}
public int Count
{
get
{
return _data.length;
}
}
T[] _data = (T[])(`[]`);
}
var l = new MyList<int>();
Console.WriteLine(l.Count);
l.Add(10);
l.Add(20);
l.Add(30);
Console.WriteLine(l.Count);
for (int i=0; i<l.Count; i++)
{
Console.WriteLine(l.GetAt(i));
}
------ Expected Output ------
0
3
10
20
30
------ Generated JavaScript ------
(function() {
// class MyList<>
var MyList$1 = function()
{
this._data = [];
};
MyList$1.typeName = 'MyList<>';
MyList$1.prototype._data = null;
MyList$1.prototype.Add = function(t)
{
this._data.push(t);
};
MyList$1.prototype.GetAt = function(index)
{
return this._data[index];
};
MyList$1.prototype.get_Count = function()
{
return this._data.length;
};
// Start Global Code
var l=new MyList$1();
Console.WriteLine(l.get_Count());
l.Add(10);
l.Add(20);
l.Add(30);
Console.WriteLine(l.get_Count());
for (var i=0; i<l.get_Count(); i++)
{
Console.WriteLine(l.GetAt(i));
}
})();
------ Actual Output ------
0
3
10
20
30
Test passed!
------ Prefix ------
// no warnings
extern dynamic Console;
class Foo
{
}
class MyFactory<T> where T:new()
{
public T CreateInstance()
{
return new T();
}
}
var foo = new MyFactory<Foo>().CreateInstance();
Console.WriteLine(foo is Foo);
------ Expected Output ------
True
------ Generated JavaScript ------
(function() {
// Prefix runtime library
var $dex = {};
$dex.makeCachedGeneric=function(a,b,c){var d=[];for(var e=0;e<b.length;e++)d.push(b[e]instanceof Function?b[e].typeName:b[e]);f=d.join(',');if(!a.closed)a.closed={};var g=a.closed[f];if(!g){g=c(f);a.closed[f]=g};return g}
$dex.resolveGenericArg=function(a,b){if(typeof(a)=='number')return b?b[a]:a;return a}
$dex.resolveGenericArgs=function(a,b){for(var c=0,d=[];c<a.length;c++)d.push($dex.resolveGenericArg(a[c],b));return d}
$dex.setupGenericClass=function(a,b,c,d){d.makeGeneric=function(e){return $dex.makeCachedGeneric(d,e,function(f){var g=function(){d.apply(this,arguments)};if(b==null){g.prototype=new d()}else{var h=$dex.resolveGenericArgs(c,e);g.prototype=new(b.makeGeneric(h))();for(var i in d.prototype)g.prototype[i]=d.prototype[i]}for(var s in d.static)g[s]=d.static[s];g.typeName=d.typeName+"["+f+"]";g.prototype.constructor=g;g.prototype['closedClass$'+a.toString()]=g;g.genericArgs=e;var j=d.prototype.$interfaces,k=j;if(j){for(var i=0,len=j.length;i<len;i++){if(typeof(j[i]instanceof Array)){if(k===j)k=j.slice(0);k[i]=j[i][0].makeGeneric($dex.resolveGenericArgs(j[i][1],e))}}g.prototype.$interfaces=k}if(g.$cctor)g.$cctor();return g})};return d}
// class Foo
var Foo = function() {};
Foo.typeName = 'Foo';
// class MyFactory<>
var MyFactory$1 = $dex.setupGenericClass(1, null, null, function() {});
MyFactory$1.typeName = 'MyFactory<>';
MyFactory$1.prototype.CreateInstance = function()
{
var T = this.closedClass$1.genericArgs[0];
return new T();
};
// Start Global Code
var foo=(new (MyFactory$1.makeGeneric([Foo]))()).CreateInstance();
Console.WriteLine((foo)!==null);
})();
------ Actual Output ------
True
Test passed!
------ Prefix ------
extern dynamic Console;
void CreateInstance<T, U>() where T:new() where U:class
{
}
Console.WriteLine("OK");
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
function CreateInstance$2()
{
};
// Start Global Code
Console.WriteLine("OK");
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
class C<T,T>
{
}
------ Expected Output ------
// exception: duplicate type parameter
------ Actual Exception ------
Tests.Generics.gparam_cant_be_duplicate.txt(1,9): class 'C<,>': duplicate type parameter 'T'
Test passed!
------ Prefix ------
class C<C>
{
}
------ Expected Output ------
// exception: has the same name as the containing type, or method
------ Actual Exception ------
Tests.Generics.gparam_cant_have_same_name_as_declaring_entity.txt(1,9): class 'C<>': generic type argument 'C' has the same name as the containing type, or method
Test passed!
------ Prefix ------
class C<T>
{
void fn<T>()
{
}
}
------ Expected Output ------
// exception: has the same name as the type parameter from outer type
------ Actual Exception ------
Tests.Generics.gparam_cant_have_same_name_as_outer_gparam.txt(3,10): function 'C<>.fn<>()': 'T' has the same name as the type parameter from outer type
Test passed!
------ Prefix ------
extern dynamic Console;
interface IBaseInterface
{
}
// A generic interface declaration with constraint
interface IMyInterface<Foo> : IBaseInterface where Foo:class
{
}
Console.WriteLine("OK");
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// Prefix runtime library
var $dex = {};
$dex.indexOf=Array.prototype.indexOf||function(a){for(var b=0;b<this.length;b++){if(this[b]===a)return b}return-1}
$dex.queryInterface=function(a,b){return a!=null&&a.$interfaces&&$dex.indexOf.call(a.$interfaces,b)>=0?a:null}
$dex.makeCachedGeneric=function(a,b,c){var d=[];for(var e=0;e<b.length;e++)d.push(b[e]instanceof Function?b[e].typeName:b[e]);f=d.join(',');if(!a.closed)a.closed={};var g=a.closed[f];if(!g){g=c(f);a.closed[f]=g};return g}
$dex.makeGenericInterface=function(a){return $dex.makeCachedGeneric(this,a,function(){return{}})}
// interface IBaseInterface
var IBaseInterface = {};
// interface IMyInterface<>
var IMyInterface$1 = {};
IMyInterface$1.makeGeneric = $dex.makeGenericInterface;
// Start Global Code
Console.WriteLine("OK");
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
extern dynamic Console;
class Bar
{
public void fn1()
{
}
}
interface Itf
{
void fn2();
}
class Foo<T> where T : Bar, Itf
{
void test(T x)
{
x.fn1();
}
}
Console.WriteLine("OK");
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// Prefix runtime library
var $dex = {};
$dex.indexOf=Array.prototype.indexOf||function(a){for(var b=0;b<this.length;b++){if(this[b]===a)return b}return-1}
$dex.queryInterface=function(a,b){return a!=null&&a.$interfaces&&$dex.indexOf.call(a.$interfaces,b)>=0?a:null}
// class Bar
var Bar = function() {};
Bar.typeName = 'Bar';
Bar.prototype.fn1 = function()
{
};
// interface Itf
var Itf = {};
// class Foo<>
var Foo$1 = function() {};
Foo$1.typeName = 'Foo<>';
Foo$1.prototype.test = function(x)
{
x.fn1();
};
// Start Global Code
Console.WriteLine("OK");
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
// no warnings
class Foo<T>
{
}
class Bar : Foo
{
}
------ Expected Output ------
// exception: requires type arguments
------ Actual Exception ------
Tests.Generics.must_specify_generic_args_in_base_class.txt(8,13): class 'Foo<>': requires type arguments
Test passed!
------ Prefix ------
class Foo<T>
{
}
class Bar<T> where T:Foo
{
}
------ Expected Output ------
// exception: requires type arguments
------ Actual Exception ------
Tests.Generics.must_specify_generic_args_in_constraints.txt(5,22): class 'Foo<>': requires type arguments
Test passed!
------ Prefix ------
// no warnings
class Foo<T>
{
}
void fn(Foo x)
{
}
------ Expected Output ------
// exception: requires type arguments
------ Actual Exception ------
Tests.Generics.must_specify_generic_args_in_parameter.txt(8,9): class 'Foo<>': requires type arguments
Test passed!
------ Prefix ------
// no warnings
class Foo<T>
{
}
class Bar
{
Foo prop { get; set; }
}
------ Expected Output ------
// exception: requires type arguments
------ Actual Exception ------
Tests.Generics.must_specify_generic_args_in_property.txt(10,2): class 'Foo<>': requires type arguments
Test passed!
------ Prefix ------
// no warnings
class Foo<T>
{
}
Foo fn()
{
return null;
}
------ Expected Output ------
// exception: requires type arguments
------ Actual Exception ------
Tests.Generics.must_specify_generic_args_in_return_type.txt(8,1): class 'Foo<>': requires type arguments
Test passed!
------ Prefix ------
// no warnings
class Foo<T>
{
}
Foo x;
------ Expected Output ------
// exception: requires type arguments
------ Actual Exception ------
Tests.Generics.must_specify_generic_args_in_variable.txt(8,1): class 'Foo<>': requires type arguments
Test passed!
------ Prefix ------
extern dynamic Console;
class Outer<T>
{
public class Inner<U>
{
public void fn()
{
Console.WriteLine(typename(this));
}
}
}
var i = new Outer<string>.Inner<bool>();
i.fn();
------ Expected Output ------
Outer<>.Inner<>[string,boolean]
------ Generated JavaScript ------
(function() {
// Prefix runtime library
var $dex = {};
$dex.makeCachedGeneric=function(a,b,c){var d=[];for(var e=0;e<b.length;e++)d.push(b[e]instanceof Function?b[e].typeName:b[e]);f=d.join(',');if(!a.closed)a.closed={};var g=a.closed[f];if(!g){g=c(f);a.closed[f]=g};return g}
$dex.resolveGenericArg=function(a,b){if(typeof(a)=='number')return b?b[a]:a;return a}
$dex.resolveGenericArgs=function(a,b){for(var c=0,d=[];c<a.length;c++)d.push($dex.resolveGenericArg(a[c],b));return d}
$dex.setupGenericClass=function(a,b,c,d){d.makeGeneric=function(e){return $dex.makeCachedGeneric(d,e,function(f){var g=function(){d.apply(this,arguments)};if(b==null){g.prototype=new d()}else{var h=$dex.resolveGenericArgs(c,e);g.prototype=new(b.makeGeneric(h))();for(var i in d.prototype)g.prototype[i]=d.prototype[i]}for(var s in d.static)g[s]=d.static[s];g.typeName=d.typeName+"["+f+"]";g.prototype.constructor=g;g.prototype['closedClass$'+a.toString()]=g;g.genericArgs=e;var j=d.prototype.$interfaces,k=j;if(j){for(var i=0,len=j.length;i<len;i++){if(typeof(j[i]instanceof Array)){if(k===j)k=j.slice(0);k[i]=j[i][0].makeGeneric($dex.resolveGenericArgs(j[i][1],e))}}g.prototype.$interfaces=k}if(g.$cctor)g.$cctor();return g})};return d}
$dex.typeNameOfInstance=function(a){return a===null?null:((a.constructor&&a.constructor.typeName)?a.constructor.typeName:(typeof a))}
// class Outer<>
var Outer$1 = $dex.setupGenericClass(1, null, null, function() {});
Outer$1.typeName = 'Outer<>';
// class Outer<>.Inner<>
Outer$1.Inner$1 = $dex.setupGenericClass(1, null, null, function() {});
Outer$1.Inner$1.typeName = 'Outer<>.Inner<>';
Outer$1.Inner$1.prototype.fn = function()
{
Console.WriteLine($dex.typeNameOfInstance(this));
};
// Start Global Code
var i=new (Outer$1.Inner$1.makeGeneric(['string', 'boolean']))();
i.fn();
})();
------ Actual Output ------
Outer<>.Inner<>[string,boolean]
Test passed!
------ Prefix ------
extern dynamic Console;
class Outer<T>
{
public class Inner<U>
{
public void fn()
{
Console.WriteLine(typename(this));
}
}
}
var i = new Outer<string>.Inner<bool>();
i.fn();
------ Expected Output ------
Outer<>.Inner<>[string,boolean]
------ Generated JavaScript ------
(function() {
// Prefix runtime library
var $dex = {};
$dex.makeCachedGeneric=function(a,b,c){var d=[];for(var e=0;e<b.length;e++)d.push(b[e]instanceof Function?b[e].typeName:b[e]);f=d.join(',');if(!a.closed)a.closed={};var g=a.closed[f];if(!g){g=c(f);a.closed[f]=g};return g}
$dex.resolveGenericArg=function(a,b){if(typeof(a)=='number')return b?b[a]:a;return a}
$dex.resolveGenericArgs=function(a,b){for(var c=0,d=[];c<a.length;c++)d.push($dex.resolveGenericArg(a[c],b));return d}
$dex.setupGenericClass=function(a,b,c,d){d.makeGeneric=function(e){return $dex.makeCachedGeneric(d,e,function(f){var g=function(){d.apply(this,arguments)};if(b==null){g.prototype=new d()}else{var h=$dex.resolveGenericArgs(c,e);g.prototype=new(b.makeGeneric(h))();for(var i in d.prototype)g.prototype[i]=d.prototype[i]}for(var s in d.static)g[s]=d.static[s];g.typeName=d.typeName+"["+f+"]";g.prototype.constructor=g;g.prototype['closedClass$'+a.toString()]=g;g.genericArgs=e;var j=d.prototype.$interfaces,k=j;if(j){for(var i=0,len=j.length;i<len;i++){if(typeof(j[i]instanceof Array)){if(k===j)k=j.slice(0);k[i]=j[i][0].makeGeneric($dex.resolveGenericArgs(j[i][1],e))}}g.prototype.$interfaces=k}if(g.$cctor)g.$cctor();return g})};return d}
$dex.typeNameOfInstance=function(a){return a===null?null:((a.constructor&&a.constructor.typeName)?a.constructor.typeName:(typeof a))}
// class Outer<>
var Outer$1 = $dex.setupGenericClass(1, null, null, function() {});
Outer$1.typeName = 'Outer<>';
// class Outer<>.Inner<>
Outer$1.Inner$1 = $dex.setupGenericClass(1, null, null, function() {});
Outer$1.Inner$1.typeName = 'Outer<>.Inner<>';
Outer$1.Inner$1.prototype.fn = function()
{
Console.WriteLine($dex.typeNameOfInstance(this));
};
// Start Global Code
var i=new (Outer$1.Inner$1.makeGeneric(['string', 'boolean']))();
i.fn();
})();
------ Actual Output ------
Outer<>.Inner<>[string,boolean]
Test passed!
------ Prefix ------
extern dynamic Console;
class Outer
{
public class Inner<U>
{
public void fn()
{
Console.WriteLine(typename(this));
}
}
}
var i = new Outer.Inner<bool>();
i.fn();
------ Expected Output ------
Outer.Inner<>[boolean]
------ Generated JavaScript ------
(function() {
// Prefix runtime library
var $dex = {};
$dex.makeCachedGeneric=function(a,b,c){var d=[];for(var e=0;e<b.length;e++)d.push(b[e]instanceof Function?b[e].typeName:b[e]);f=d.join(',');if(!a.closed)a.closed={};var g=a.closed[f];if(!g){g=c(f);a.closed[f]=g};return g}
$dex.resolveGenericArg=function(a,b){if(typeof(a)=='number')return b?b[a]:a;return a}
$dex.resolveGenericArgs=function(a,b){for(var c=0,d=[];c<a.length;c++)d.push($dex.resolveGenericArg(a[c],b));return d}
$dex.setupGenericClass=function(a,b,c,d){d.makeGeneric=function(e){return $dex.makeCachedGeneric(d,e,function(f){var g=function(){d.apply(this,arguments)};if(b==null){g.prototype=new d()}else{var h=$dex.resolveGenericArgs(c,e);g.prototype=new(b.makeGeneric(h))();for(var i in d.prototype)g.prototype[i]=d.prototype[i]}for(var s in d.static)g[s]=d.static[s];g.typeName=d.typeName+"["+f+"]";g.prototype.constructor=g;g.prototype['closedClass$'+a.toString()]=g;g.genericArgs=e;var j=d.prototype.$interfaces,k=j;if(j){for(var i=0,len=j.length;i<len;i++){if(typeof(j[i]instanceof Array)){if(k===j)k=j.slice(0);k[i]=j[i][0].makeGeneric($dex.resolveGenericArgs(j[i][1],e))}}g.prototype.$interfaces=k}if(g.$cctor)g.$cctor();return g})};return d}
$dex.typeNameOfInstance=function(a){return a===null?null:((a.constructor&&a.constructor.typeName)?a.constructor.typeName:(typeof a))}
// class Outer
var Outer = function() {};
Outer.typeName = 'Outer';
// class Outer.Inner<>
Outer.Inner$1 = $dex.setupGenericClass(1, null, null, function() {});
Outer.Inner$1.typeName = 'Outer.Inner<>';
Outer.Inner$1.prototype.fn = function()
{
Console.WriteLine($dex.typeNameOfInstance(this));
};
// Start Global Code
var i=new (Outer.Inner$1.makeGeneric(['boolean']))();
i.fn();
})();
------ Actual Output ------
Outer.Inner<>[boolean]
Test passed!
------ Prefix ------
extern dynamic Console;
class Outer<T>
{
public class Inner
{
public void fn()
{
Console.WriteLine(typename(this));
}
}
}
var i = new Outer<string>.Inner();
i.fn();
------ Expected Output ------
Outer<>.Inner[string]
------ Generated JavaScript ------
(function() {
// Prefix runtime library
var $dex = {};
$dex.makeCachedGeneric=function(a,b,c){var d=[];for(var e=0;e<b.length;e++)d.push(b[e]instanceof Function?b[e].typeName:b[e]);f=d.join(',');if(!a.closed)a.closed={};var g=a.closed[f];if(!g){g=c(f);a.closed[f]=g};return g}
$dex.resolveGenericArg=function(a,b){if(typeof(a)=='number')return b?b[a]:a;return a}
$dex.resolveGenericArgs=function(a,b){for(var c=0,d=[];c<a.length;c++)d.push($dex.resolveGenericArg(a[c],b));return d}
$dex.setupGenericClass=function(a,b,c,d){d.makeGeneric=function(e){return $dex.makeCachedGeneric(d,e,function(f){var g=function(){d.apply(this,arguments)};if(b==null){g.prototype=new d()}else{var h=$dex.resolveGenericArgs(c,e);g.prototype=new(b.makeGeneric(h))();for(var i in d.prototype)g.prototype[i]=d.prototype[i]}for(var s in d.static)g[s]=d.static[s];g.typeName=d.typeName+"["+f+"]";g.prototype.constructor=g;g.prototype['closedClass$'+a.toString()]=g;g.genericArgs=e;var j=d.prototype.$interfaces,k=j;if(j){for(var i=0,len=j.length;i<len;i++){if(typeof(j[i]instanceof Array)){if(k===j)k=j.slice(0);k[i]=j[i][0].makeGeneric($dex.resolveGenericArgs(j[i][1],e))}}g.prototype.$interfaces=k}if(g.$cctor)g.$cctor();return g})};return d}
$dex.typeNameOfInstance=function(a){return a===null?null:((a.constructor&&a.constructor.typeName)?a.constructor.typeName:(typeof a))}
// class Outer<>
var Outer$1 = $dex.setupGenericClass(1, null, null, function() {});
Outer$1.typeName = 'Outer<>';
// class Outer<>.Inner<>
Outer$1.Inner$0 = $dex.setupGenericClass(1, null, null, function() {});
Outer$1.Inner$0.typeName = 'Outer<>.Inner';
Outer$1.Inner$0.prototype.fn = function()
{
Console.WriteLine($dex.typeNameOfInstance(this));
};
// Start Global Code
var i=new (Outer$1.Inner$0.makeGeneric(['string']))();
i.fn();
})();
------ Actual Output ------
Outer<>.Inner[string]
Test passed!
------ Prefix ------
extern dynamic Console;
class Base
{
public class InnerBase
{
public void fn()
{
Console.WriteLine("OK");
}
}
}
class Outer<T> : Base
{
}
var i = new Outer<int>.InnerBase();
i.fn();
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// class Base
var Base = function() {};
Base.typeName = 'Base';
// class Base.InnerBase
Base.InnerBase = function() {};
Base.InnerBase.typeName = 'Base.InnerBase';
Base.InnerBase.prototype.fn = function()
{
Console.WriteLine("OK");
};
// class Outer<>
var Outer$1 = function() {};
Outer$1.typeName = 'Outer<>';
Outer$1.prototype = new Base();
Outer$1.prototype.constructor = Outer$1;
// Start Global Code
var i=new Base.InnerBase();
i.fn();
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
class Foo<T> where T:new()
{
T fn()
{
return new T(23);
}
}
------ Expected Output ------
// exception: cannot provide arguments when creating an instance
------ Actual Exception ------
Tests.Generics.new_operator_cant_have_arguments.txt(5,10): 'T': cannot provide arguments when creating an instance of a variable type
Test passed!
------ Prefix ------
class Foo
{
dynamic fn<T>() where T:new()
{
var x=new T();
return x;
}
}
------ Expected Output ------
------ Generated JavaScript ------
(function() {
// Prefix runtime library
var $dex = {};
$dex.makeCachedGeneric=function(a,b,c){var d=[];for(var e=0;e<b.length;e++)d.push(b[e]instanceof Function?b[e].typeName:b[e]);f=d.join(',');if(!a.closed)a.closed={};var g=a.closed[f];if(!g){g=c(f);a.closed[f]=g};return g}
$dex.resolveGenericArg=function(a,b){if(typeof(a)=='number')return b?b[a]:a;return a}
$dex.resolveGenericArgs=function(a,b){for(var c=0,d=[];c<a.length;c++)d.push($dex.resolveGenericArg(a[c],b));return d}
$dex.setupGenericClass=function(a,b,c,d){d.makeGeneric=function(e){return $dex.makeCachedGeneric(d,e,function(f){var g=function(){d.apply(this,arguments)};if(b==null){g.prototype=new d()}else{var h=$dex.resolveGenericArgs(c,e);g.prototype=new(b.makeGeneric(h))();for(var i in d.prototype)g.prototype[i]=d.prototype[i]}for(var s in d.static)g[s]=d.static[s];g.typeName=d.typeName+"["+f+"]";g.prototype.constructor=g;g.prototype['closedClass$'+a.toString()]=g;g.genericArgs=e;var j=d.prototype.$interfaces,k=j;if(j){for(var i=0,len=j.length;i<len;i++){if(typeof(j[i]instanceof Array)){if(k===j)k=j.slice(0);k[i]=j[i][0].makeGeneric($dex.resolveGenericArgs(j[i][1],e))}}g.prototype.$interfaces=k}if(g.$cctor)g.$cctor();return g})};return d}
// class Foo
var Foo = function() {};
Foo.typeName = 'Foo';
Foo.prototype.fn$1 = function($gargs)
{
var T = $gargs[0];
var x=new T();
return x;
};
})();
------ Actual Output ------
Test passed!
------ Prefix ------
class Foo<T>
{
T fn()
{
return new T();
}
}
------ Expected Output ------
// exception: because it does not have the new() constraint
------ Actual Exception ------
Tests.Generics.new_operator_requires_new_constraint.txt(5,10): cannot create an instance of the variable type 'T' because it does not have the new() constraint
Test passed!
------ Prefix ------
// should generate: $dex.setupGenericClass=function
// should generate: $dex.setupGenericClass(1,
extern dynamic Console;
interface IDoSomething
{
void DoSomething();
}
class Foo<T> where T:IDoSomething, new()
{
public T fn()
{
return new T();
}
}
class Bar : IDoSomething
{
public void DoSomething()
{
Console.WriteLine("Something");
}
}
var x = new Foo<Bar>();
x.fn().DoSomething();
//`var x = new (Foo$1.makeGeneric([Bar]))();
//x.fn().DoSomething();`;
------ Expected Output ------
Something
------ Generated JavaScript ------
(function() {
// Prefix runtime library
var $dex = {};
$dex.indexOf=Array.prototype.indexOf||function(a){for(var b=0;b<this.length;b++){if(this[b]===a)return b}return-1}
$dex.queryInterface=function(a,b){return a!=null&&a.$interfaces&&$dex.indexOf.call(a.$interfaces,b)>=0?a:null}
$dex.makeCachedGeneric=function(a,b,c){var d=[];for(var e=0;e<b.length;e++)d.push(b[e]instanceof Function?b[e].typeName:b[e]);f=d.join(',');if(!a.closed)a.closed={};var g=a.closed[f];if(!g){g=c(f);a.closed[f]=g};return g}
$dex.resolveGenericArg=function(a,b){if(typeof(a)=='number')return b?b[a]:a;return a}
$dex.resolveGenericArgs=function(a,b){for(var c=0,d=[];c<a.length;c++)d.push($dex.resolveGenericArg(a[c],b));return d}
$dex.setupGenericClass=function(a,b,c,d){d.makeGeneric=function(e){return $dex.makeCachedGeneric(d,e,function(f){var g=function(){d.apply(this,arguments)};if(b==null){g.prototype=new d()}else{var h=$dex.resolveGenericArgs(c,e);g.prototype=new(b.makeGeneric(h))();for(var i in d.prototype)g.prototype[i]=d.prototype[i]}for(var s in d.static)g[s]=d.static[s];g.typeName=d.typeName+"["+f+"]";g.prototype.constructor=g;g.prototype['closedClass$'+a.toString()]=g;g.genericArgs=e;var j=d.prototype.$interfaces,k=j;if(j){for(var i=0,len=j.length;i<len;i++){if(typeof(j[i]instanceof Array)){if(k===j)k=j.slice(0);k[i]=j[i][0].makeGeneric($dex.resolveGenericArgs(j[i][1],e))}}g.prototype.$interfaces=k}if(g.$cctor)g.$cctor();return g})};return d}
// interface IDoSomething
var IDoSomething = {};
// class Foo<>
var Foo$1 = $dex.setupGenericClass(1, null, null, function() {});
Foo$1.typeName = 'Foo<>';
Foo$1.prototype.fn = function()
{
var T = this.closedClass$1.genericArgs[0];
return new T();
};
// class Bar
var Bar = function() {};
Bar.typeName = 'Bar';
Bar.prototype.$interfaces = [IDoSomething];
Bar.prototype.DoSomething = function()
{
Console.WriteLine("Something");
};
// Start Global Code
var x=new (Foo$1.makeGeneric([Bar]))();
x.fn().DoSomething();
})();
------ Actual Output ------
Something
Test passed!
------ Prefix ------
// no warnings
extern dynamic Console;
class Bar<T>
{
public Bar<bool>.Nested fn()
{
return null;
}
public class Nested : Bar<bool>.Nested2
{
public Nested2 fn()
{
return null;
}
}
public class Nested2
{
}
}
------ Expected Output ------
------ Generated JavaScript ------
(function() {
// class Bar<>
var Bar$1 = function() {};
Bar$1.typeName = 'Bar<>';
Bar$1.prototype.fn = function()
{
return null;
};
// class Bar<>.Nested2<>
Bar$1.Nested2$0 = function() {};
Bar$1.Nested2$0.typeName = 'Bar<>.Nested2';
// class Bar<>.Nested<>
Bar$1.Nested$0 = function() {};
Bar$1.Nested$0.typeName = 'Bar<>.Nested';
Bar$1.Nested$0.prototype = new Bar$1.Nested2$0();
Bar$1.Nested$0.prototype.constructor = Bar$1.Nested$0;
Bar$1.Nested$0.prototype.fn = function()
{
return null;
};
// Start Global Code
})();
------ Actual Output ------
Test passed!
------ Prefix ------
extern dynamic Console;
// no warnings
class Foo<T>
{
public Foo<T> fn()
{
return null;
}
}
var f = new Foo<int>();
------ Expected Output ------
------ Generated JavaScript ------
(function() {
// class Foo<>
var Foo$1 = function() {};
Foo$1.typeName = 'Foo<>';
Foo$1.prototype.fn = function()
{
return null;
};
// Start Global Code
var f=new Foo$1();
})();
------ Actual Output ------
Test passed!
------ Prefix ------
// no warnings
// should not generate: dynamicCast
extern dynamic Console;
class Foo
{
}
class Bar<T> where T : Foo
{
public void fn(T t)
{
Console.WriteLine((t as Foo)!=null);
}
}
new Bar<Foo>().fn(new Foo());
------ Expected Output ------
True
------ Generated JavaScript ------
(function() {
// class Foo
var Foo = function() {};
Foo.typeName = 'Foo';
// class Bar<>
var Bar$1 = function() {};
Bar$1.typeName = 'Bar<>';
Bar$1.prototype.fn = function(t)
{
Console.WriteLine((t)!==null);
};
// Start Global Code
(new Bar$1()).fn(new Foo());
})();
------ Actual Output ------
True
Test passed!
------ Prefix ------
// no warnings
// should not generate: dynamicCast
extern dynamic Console;
class Foo
{
}
class Bar<T> where T : Foo
{
public void fn(T t)
{
Console.WriteLine(t is Foo);
}
}
new Bar<Foo>().fn(new Foo());
------ Expected Output ------
True
------ Generated JavaScript ------
(function() {
// class Foo
var Foo = function() {};
Foo.typeName = 'Foo';
// class Bar<>
var Bar$1 = function() {};
Bar$1.typeName = 'Bar<>';
Bar$1.prototype.fn = function(t)
{
Console.WriteLine((t)!==null);
};
// Start Global Code
(new Bar$1()).fn(new Foo());
})();
------ Actual Output ------
True
Test passed!
------ Prefix ------
// should not generate: $dex.setupGenericFunction
// should not generate: $gargs
extern dynamic Console;
class Foo
{
public void fn()
{
Console.WriteLine("OK");
}
}
T make<T>() where T:class
{
Console.WriteLine("OK");
return null;
}
make<Foo>();
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// class Foo
var Foo = function() {};
Foo.typeName = 'Foo';
Foo.prototype.fn = function()
{
Console.WriteLine("OK");
};
function make$1()
{
Console.WriteLine("OK");
return null;
};
// Start Global Code
make$1();
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
extern dynamic Console;
class MyClass<T>
{
public MyClass<T>.Inner fn()
{
Console.WriteLine(typename(this));
return new Inner();
}
public class Inner
{
public void fn()
{
Console.WriteLine(typename(this));
}
}
}
var x = new MyClass<string>();
x.fn().fn();
------ Expected Output ------
MyClass<>[string]
MyClass<>.Inner[string]
------ Generated JavaScript ------
(function() {
// Prefix runtime library
var $dex = {};
$dex.makeCachedGeneric=function(a,b,c){var d=[];for(var e=0;e<b.length;e++)d.push(b[e]instanceof Function?b[e].typeName:b[e]);f=d.join(',');if(!a.closed)a.closed={};var g=a.closed[f];if(!g){g=c(f);a.closed[f]=g};return g}
$dex.resolveGenericArg=function(a,b){if(typeof(a)=='number')return b?b[a]:a;return a}
$dex.resolveGenericArgs=function(a,b){for(var c=0,d=[];c<a.length;c++)d.push($dex.resolveGenericArg(a[c],b));return d}
$dex.setupGenericClass=function(a,b,c,d){d.makeGeneric=function(e){return $dex.makeCachedGeneric(d,e,function(f){var g=function(){d.apply(this,arguments)};if(b==null){g.prototype=new d()}else{var h=$dex.resolveGenericArgs(c,e);g.prototype=new(b.makeGeneric(h))();for(var i in d.prototype)g.prototype[i]=d.prototype[i]}for(var s in d.static)g[s]=d.static[s];g.typeName=d.typeName+"["+f+"]";g.prototype.constructor=g;g.prototype['closedClass$'+a.toString()]=g;g.genericArgs=e;var j=d.prototype.$interfaces,k=j;if(j){for(var i=0,len=j.length;i<len;i++){if(typeof(j[i]instanceof Array)){if(k===j)k=j.slice(0);k[i]=j[i][0].makeGeneric($dex.resolveGenericArgs(j[i][1],e))}}g.prototype.$interfaces=k}if(g.$cctor)g.$cctor();return g})};return d}
$dex.typeNameOfInstance=function(a){return a===null?null:((a.constructor&&a.constructor.typeName)?a.constructor.typeName:(typeof a))}
// class MyClass<>
var MyClass$1 = $dex.setupGenericClass(1, null, null, function() {});
MyClass$1.typeName = 'MyClass<>';
MyClass$1.prototype.fn = function()
{
var T = this.closedClass$1.genericArgs[0];
Console.WriteLine($dex.typeNameOfInstance(this));
return new (MyClass$1.Inner$0.makeGeneric([T]))();
};
// class MyClass<>.Inner<>
MyClass$1.Inner$0 = $dex.setupGenericClass(1, null, null, function() {});
MyClass$1.Inner$0.typeName = 'MyClass<>.Inner';
MyClass$1.Inner$0.prototype.fn = function()
{
Console.WriteLine($dex.typeNameOfInstance(this));
};
// Start Global Code
var x=new (MyClass$1.makeGeneric(['string']))();
x.fn().fn();
})();
------ Actual Output ------
MyClass<>[string]
MyClass<>.Inner[string]
Test passed!
------ Prefix ------
extern dynamic Console;
// no warnings
class Foo<T>
{
static Foo()
{
Console.WriteLine("In static constructor");
x=99;
}
public static int x;
}
Foo<string>.x = 2;
Console.WriteLine(Foo<int>.x);
Console.WriteLine(Foo<string>.x);
Console.WriteLine(Foo<string>.x);
------ Expected Output ------
In static constructor
In static constructor
99
2
2
------ Generated JavaScript ------
(function() {
// Prefix runtime library
var $dex = {};
$dex.makeCachedGeneric=function(a,b,c){var d=[];for(var e=0;e<b.length;e++)d.push(b[e]instanceof Function?b[e].typeName:b[e]);f=d.join(',');if(!a.closed)a.closed={};var g=a.closed[f];if(!g){g=c(f);a.closed[f]=g};return g}
$dex.resolveGenericArg=function(a,b){if(typeof(a)=='number')return b?b[a]:a;return a}
$dex.resolveGenericArgs=function(a,b){for(var c=0,d=[];c<a.length;c++)d.push($dex.resolveGenericArg(a[c],b));return d}
$dex.setupGenericClass=function(a,b,c,d){d.makeGeneric=function(e){return $dex.makeCachedGeneric(d,e,function(f){var g=function(){d.apply(this,arguments)};if(b==null){g.prototype=new d()}else{var h=$dex.resolveGenericArgs(c,e);g.prototype=new(b.makeGeneric(h))();for(var i in d.prototype)g.prototype[i]=d.prototype[i]}for(var s in d.static)g[s]=d.static[s];g.typeName=d.typeName+"["+f+"]";g.prototype.constructor=g;g.prototype['closedClass$'+a.toString()]=g;g.genericArgs=e;var j=d.prototype.$interfaces,k=j;if(j){for(var i=0,len=j.length;i<len;i++){if(typeof(j[i]instanceof Array)){if(k===j)k=j.slice(0);k[i]=j[i][0].makeGeneric($dex.resolveGenericArgs(j[i][1],e))}}g.prototype.$interfaces=k}if(g.$cctor)g.$cctor();return g})};return d}
// class Foo<>
var Foo$1 = $dex.setupGenericClass(1, null, null, function() {});
Foo$1.typeName = 'Foo<>';
Foo$1.static = {};
Foo$1.static.$cctor = function()
{
Console.WriteLine("In static constructor");
this.x = 99;
};
// Start Global Code
Foo$1.makeGeneric(['string']).x = 2;
Console.WriteLine(Foo$1.makeGeneric(['number']).x);
Console.WriteLine(Foo$1.makeGeneric(['string']).x);
Console.WriteLine(Foo$1.makeGeneric(['string']).x);
})();
------ Actual Output ------
In static constructor
In static constructor
99
2
2
Test passed!
------ Prefix ------
extern dynamic Console;
// no warnings
class Foo<T>
{
public static int x;
public static void DoSomething()
{
Console.WriteLine(x);
}
}
Foo<int>.x = 1;
Foo<string>.x = 2;
Foo<int>.DoSomething();
Foo<string>.DoSomething();
------ Expected Output ------
1
2
------ Generated JavaScript ------
(function() {
// Prefix runtime library
var $dex = {};
$dex.makeCachedGeneric=function(a,b,c){var d=[];for(var e=0;e<b.length;e++)d.push(b[e]instanceof Function?b[e].typeName:b[e]);f=d.join(',');if(!a.closed)a.closed={};var g=a.closed[f];if(!g){g=c(f);a.closed[f]=g};return g}
$dex.resolveGenericArg=function(a,b){if(typeof(a)=='number')return b?b[a]:a;return a}
$dex.resolveGenericArgs=function(a,b){for(var c=0,d=[];c<a.length;c++)d.push($dex.resolveGenericArg(a[c],b));return d}
$dex.setupGenericClass=function(a,b,c,d){d.makeGeneric=function(e){return $dex.makeCachedGeneric(d,e,function(f){var g=function(){d.apply(this,arguments)};if(b==null){g.prototype=new d()}else{var h=$dex.resolveGenericArgs(c,e);g.prototype=new(b.makeGeneric(h))();for(var i in d.prototype)g.prototype[i]=d.prototype[i]}for(var s in d.static)g[s]=d.static[s];g.typeName=d.typeName+"["+f+"]";g.prototype.constructor=g;g.prototype['closedClass$'+a.toString()]=g;g.genericArgs=e;var j=d.prototype.$interfaces,k=j;if(j){for(var i=0,len=j.length;i<len;i++){if(typeof(j[i]instanceof Array)){if(k===j)k=j.slice(0);k[i]=j[i][0].makeGeneric($dex.resolveGenericArgs(j[i][1],e))}}g.prototype.$interfaces=k}if(g.$cctor)g.$cctor();return g})};return d}
// class Foo<>
var Foo$1 = $dex.setupGenericClass(1, null, null, function() {});
Foo$1.typeName = 'Foo<>';
Foo$1.static = {};
Foo$1.static.DoSomething = function()
{
Console.WriteLine(this.x);
};
// Start Global Code
Foo$1.makeGeneric(['number']).x = 1;
Foo$1.makeGeneric(['string']).x = 2;
Foo$1.makeGeneric(['number']).DoSomething();
Foo$1.makeGeneric(['string']).DoSomething();
})();
------ Actual Output ------
1
2
Test passed!
------ Prefix ------
extern dynamic Console;
// no warnings
class Foo<T>
{
private static int _x;
public static int x
{
get
{
return _x;
}
set
{
_x = value;
}
}
}
Foo<int>.x = 1;
Foo<string>.x = 2;
Console.WriteLine(Foo<int>.x);
Console.WriteLine(Foo<string>.x);
------ Expected Output ------
1
2
------ Generated JavaScript ------
(function() {
// Prefix runtime library
var $dex = {};
$dex.makeCachedGeneric=function(a,b,c){var d=[];for(var e=0;e<b.length;e++)d.push(b[e]instanceof Function?b[e].typeName:b[e]);f=d.join(',');if(!a.closed)a.closed={};var g=a.closed[f];if(!g){g=c(f);a.closed[f]=g};return g}
$dex.resolveGenericArg=function(a,b){if(typeof(a)=='number')return b?b[a]:a;return a}
$dex.resolveGenericArgs=function(a,b){for(var c=0,d=[];c<a.length;c++)d.push($dex.resolveGenericArg(a[c],b));return d}
$dex.setupGenericClass=function(a,b,c,d){d.makeGeneric=function(e){return $dex.makeCachedGeneric(d,e,function(f){var g=function(){d.apply(this,arguments)};if(b==null){g.prototype=new d()}else{var h=$dex.resolveGenericArgs(c,e);g.prototype=new(b.makeGeneric(h))();for(var i in d.prototype)g.prototype[i]=d.prototype[i]}for(var s in d.static)g[s]=d.static[s];g.typeName=d.typeName+"["+f+"]";g.prototype.constructor=g;g.prototype['closedClass$'+a.toString()]=g;g.genericArgs=e;var j=d.prototype.$interfaces,k=j;if(j){for(var i=0,len=j.length;i<len;i++){if(typeof(j[i]instanceof Array)){if(k===j)k=j.slice(0);k[i]=j[i][0].makeGeneric($dex.resolveGenericArgs(j[i][1],e))}}g.prototype.$interfaces=k}if(g.$cctor)g.$cctor();return g})};return d}
// class Foo<>
var Foo$1 = $dex.setupGenericClass(1, null, null, function() {});
Foo$1.typeName = 'Foo<>';
Foo$1.static = {};
Foo$1.static.get_x = function()
{
return this._x;
};
Foo$1.static.set_x = function(value)
{
this._x = value;
return value;
};
// Start Global Code
Foo$1.makeGeneric(['number']).set_x(1);
Foo$1.makeGeneric(['string']).set_x(2);
Console.WriteLine(Foo$1.makeGeneric(['number']).get_x());
Console.WriteLine(Foo$1.makeGeneric(['string']).get_x());
})();
------ Actual Output ------
1
2
Test passed!
------ Prefix ------
extern dynamic Console;
// no warnings
class Foo<T>
{
public static int x;
}
Foo<int>.x = 1;
Foo<string>.x = 2;
Console.WriteLine(Foo<int>.x);
Console.WriteLine(Foo<string>.x);
------ Expected Output ------
1
2
------ Generated JavaScript ------
(function() {
// Prefix runtime library
var $dex = {};
$dex.makeCachedGeneric=function(a,b,c){var d=[];for(var e=0;e<b.length;e++)d.push(b[e]instanceof Function?b[e].typeName:b[e]);f=d.join(',');if(!a.closed)a.closed={};var g=a.closed[f];if(!g){g=c(f);a.closed[f]=g};return g}
$dex.resolveGenericArg=function(a,b){if(typeof(a)=='number')return b?b[a]:a;return a}
$dex.resolveGenericArgs=function(a,b){for(var c=0,d=[];c<a.length;c++)d.push($dex.resolveGenericArg(a[c],b));return d}
$dex.setupGenericClass=function(a,b,c,d){d.makeGeneric=function(e){return $dex.makeCachedGeneric(d,e,function(f){var g=function(){d.apply(this,arguments)};if(b==null){g.prototype=new d()}else{var h=$dex.resolveGenericArgs(c,e);g.prototype=new(b.makeGeneric(h))();for(var i in d.prototype)g.prototype[i]=d.prototype[i]}for(var s in d.static)g[s]=d.static[s];g.typeName=d.typeName+"["+f+"]";g.prototype.constructor=g;g.prototype['closedClass$'+a.toString()]=g;g.genericArgs=e;var j=d.prototype.$interfaces,k=j;if(j){for(var i=0,len=j.length;i<len;i++){if(typeof(j[i]instanceof Array)){if(k===j)k=j.slice(0);k[i]=j[i][0].makeGeneric($dex.resolveGenericArgs(j[i][1],e))}}g.prototype.$interfaces=k}if(g.$cctor)g.$cctor();return g})};return d}
// class Foo<>
var Foo$1 = $dex.setupGenericClass(1, null, null, function() {});
Foo$1.typeName = 'Foo<>';
// Start Global Code
Foo$1.makeGeneric(['number']).x = 1;
Foo$1.makeGeneric(['string']).x = 2;
Console.WriteLine(Foo$1.makeGeneric(['number']).x);
Console.WriteLine(Foo$1.makeGeneric(['string']).x);
})();
------ Actual Output ------
1
2
Test passed!
------ Prefix ------
// no warnings
class C<T,U>
{
}
class C<T,U,V,W>
{
}
var x = new C<int, int>();
var y = new C<int, int, int, int>();
------ Expected Output ------
------ Generated JavaScript ------
(function() {
// class C<,>
var C$2 = function() {};
C$2.typeName = 'C<,>';
// class C<,,,>
var C$4 = function() {};
C$4.typeName = 'C<,,,>';
// Start Global Code
var x=new C$2();
var y=new C$4();
})();
------ Actual Output ------
Test passed!
------ Prefix ------
// no warnings
class C<T,U>
{
}
var x = new C<int>();
------ Expected Output ------
// exception: requires 2 type argument(s)
------ Actual Exception ------
Tests.Generics.type_count_must_match.txt(6,13): class 'C<,>': requires 2 type argument(s)
Test passed!
------ Prefix ------
// no warnings
class C<T,U>
{
}
class C<T,U,V,W>
{
}
var x = new C<int, int>();
var y = new C<int, int, int>();
------ Expected Output ------
// exception: requires 2 or 4 type argument(s)
------ Actual Exception ------
Tests.Generics.type_count_must_match_one.txt(12,13): group 'C': requires 2 or 4 type argument(s) but 3 supplied
Test passed!
------ Prefix ------
extern dynamic Console;
class MyClass<T>
{
}
void fn<T>(MyClass<T> a)
{
Console.WriteLine(typename(a));
}
fn(new MyClass<int>());
------ Expected Output ------
MyClass<>[number]
------ Generated JavaScript ------
(function() {
// Prefix runtime library
var $dex = {};
$dex.makeCachedGeneric=function(a,b,c){var d=[];for(var e=0;e<b.length;e++)d.push(b[e]instanceof Function?b[e].typeName:b[e]);f=d.join(',');if(!a.closed)a.closed={};var g=a.closed[f];if(!g){g=c(f);a.closed[f]=g};return g}
$dex.resolveGenericArg=function(a,b){if(typeof(a)=='number')return b?b[a]:a;return a}
$dex.resolveGenericArgs=function(a,b){for(var c=0,d=[];c<a.length;c++)d.push($dex.resolveGenericArg(a[c],b));return d}
$dex.setupGenericClass=function(a,b,c,d){d.makeGeneric=function(e){return $dex.makeCachedGeneric(d,e,function(f){var g=function(){d.apply(this,arguments)};if(b==null){g.prototype=new d()}else{var h=$dex.resolveGenericArgs(c,e);g.prototype=new(b.makeGeneric(h))();for(var i in d.prototype)g.prototype[i]=d.prototype[i]}for(var s in d.static)g[s]=d.static[s];g.typeName=d.typeName+"["+f+"]";g.prototype.constructor=g;g.prototype['closedClass$'+a.toString()]=g;g.genericArgs=e;var j=d.prototype.$interfaces,k=j;if(j){for(var i=0,len=j.length;i<len;i++){if(typeof(j[i]instanceof Array)){if(k===j)k=j.slice(0);k[i]=j[i][0].makeGeneric($dex.resolveGenericArgs(j[i][1],e))}}g.prototype.$interfaces=k}if(g.$cctor)g.$cctor();return g})};return d}
$dex.typeNameOfInstance=function(a){return a===null?null:((a.constructor&&a.constructor.typeName)?a.constructor.typeName:(typeof a))}
// class MyClass<>
var MyClass$1 = $dex.setupGenericClass(1, null, null, function() {});
MyClass$1.typeName = 'MyClass<>';
function fn$1(a)
{
Console.WriteLine($dex.typeNameOfInstance(a));
};
// Start Global Code
fn$1(new (MyClass$1.makeGeneric(['number']))());
})();
------ Actual Output ------
MyClass<>[number]
Test passed!
------ Prefix ------
static void MyFunction()
{
}
------ Expected Output ------
// exception: cannot be marked static
------ Actual Exception ------
Tests.GlobalScope.cant_declare_static_global_function.txt(1,8): function 'MyFunction()': global function cannot be marked static
Test passed!
------ Prefix ------ static string MyString; ------ Expected Output ------ // exception: cannot be marked static ------ Actual Exception ------ Tests.GlobalScope.cant_declare_static_global_variable.txt(1,8): GlobalVariable MyString: global variable cannot be marked static Test passed!
------ Prefix ------
extern dynamic Console;
class MyClass
{
public string message()
{
return "OK";
}
}
Console.WriteLine(new MyClass().message());
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// class MyClass
var MyClass = function() {};
MyClass.typeName = 'MyClass';
MyClass.prototype.message = function()
{
return "OK";
};
// Start Global Code
Console.WriteLine((new MyClass()).message());
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
extern dynamic Console;
class MyClass
{
public string message()
{
return "OK";
}
public string message2()
{
return new MyClass().message();
}
}
Console.WriteLine(new MyClass().message2());
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// class MyClass
var MyClass = function() {};
MyClass.typeName = 'MyClass';
MyClass.prototype.message = function()
{
return "OK";
};
MyClass.prototype.message2 = function()
{
return (new MyClass()).message();
};
// Start Global Code
Console.WriteLine((new MyClass()).message2());
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
class MyClass
{
}
new MyClass().Something;
------ Expected Output ------
// exception: does not contain a definition for 'Something'
------ Actual Exception ------
Tests.GlobalScope.classmember_doesnt_exist.txt(4,15): instance of class 'MyClass' does not contain a definition for 'Something'
Test passed!
------ Prefix ------
extern dynamic Console;
string str="Hello World";
Console.WriteLine(str.substr(0, 5).toUpperCase());
------ Expected Output ------
HELLO
------ Generated JavaScript ------
(function() {
// Start Global Code
var str="Hello World";
Console.WriteLine(str.substr(0, 5).toUpperCase());
})();
------ Actual Output ------
HELLO
Test passed!
------ Prefix ------
extern dynamic Console;
string str = "OK";
Console.WriteLine(str.toString());
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// Start Global Code
var str="OK";
Console.WriteLine(str.toString());
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
extern dynamic Console;
// A function declared externally. (nb: No implementation)
extern string GetMessage();
// Backticked like that below is passed through as JavaScript. Can used anywhere
// an expression is expected and is assumed to be of type "dynamic".
// We're using it here to implement GetMessage() as declared just above as "extern".
`
// This is pure JavaScript!
// If necessary, you can escape a backtick `` with double backticks ````
function GetMessage()
{
return "OK";
}
`;
// Call it
Console.WriteLine(GetMessage());
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// Start Global Code
// This is pure JavaScript!
// If necessary, you can escape a backtick ` with double backticks ``
function GetMessage()
{
return "OK";
}
;
Console.WriteLine(GetMessage());
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
extern dynamic Console;
int i;
for (i=1; i<=3; i++)
{
Console.Write("X");
}
------ Expected Output ------
XXX
------ Generated JavaScript ------
(function() {
// Start Global Code
var i;
for (i = 1; i<=3; i++)
{
Console.Write("X");
}
})();
------ Actual Output ------
XXX
Test passed!
------ Prefix ------
extern dynamic Console;
for (int i=1; i<=3; i++)
{
Console.Write("X");
}
------ Expected Output ------
XXX
------ Generated JavaScript ------
(function() {
// Start Global Code
for (var i=1; i<=3; i++)
{
Console.Write("X");
}
})();
------ Actual Output ------
XXX
Test passed!
------ Prefix ------
extern dynamic Console;
string GetString()
{
return "OK";
}
Console.WriteLine(GetString());
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
function GetString()
{
return "OK";
};
// Start Global Code
Console.WriteLine(GetString());
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------ dynamic x = new MyClass(); ------ Expected Output ------ // exception: The name 'MyClass' doesn't exist ------ Actual Exception ------ Tests.GlobalScope.type_doesnt_exist.txt(1,17): The name 'MyClass' doesn't exist in the current context Test passed!
------ Prefix ------
extern dynamic Console;
string GetMessage(string x, string y)
{
return x + " " + y;
}
Console.WriteLine(GetMessage("Hello", "World"));
------ Expected Output ------
Hello World
------ Generated JavaScript ------
(function() {
function GetMessage(x, y)
{
return x + " " + y;
};
// Start Global Code
Console.WriteLine(GetMessage("Hello", "World"));
})();
------ Actual Output ------
Hello World
Test passed!
------ Prefix ------
extern dynamic Console;
string msg="OK";
Console.WriteLine(msg);
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// Start Global Code
var msg="OK";
Console.WriteLine(msg);
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------ myvar=23; ------ Expected Output ------ // exception: The name 'myvar' doesn't exist ------ Actual Exception ------ Tests.GlobalScope.variable.txt(1,1): The name 'myvar' doesn't exist in the current context Test passed!
------ Prefix ------ extern dynamic Console; void x; ------ Expected Output ------ // exception: cannot be void ------ Actual Exception ------ Tests.GlobalScope.variable_cant_be_void.txt(2,1): GlobalVariable x: a variable cannot be void Test passed!
------ Prefix ------ myvar=23; ------ Expected Output ------ // exception: The name 'myvar' doesn't exist ------ Actual Exception ------ Tests.GlobalScope.variable_doesnt_exist.txt(1,1): The name 'myvar' doesn't exist in the current context Test passed!
------ Prefix ------
extern dynamic Console;
string[] parts = "Hello|World".split("|");
Console.WriteLine(parts[1]);
------ Expected Output ------
World
------ Generated JavaScript ------
(function() {
// Start Global Code
var parts="Hello|World".split("|");
Console.WriteLine(parts[1]);
})();
------ Actual Output ------
World
Test passed!
------ Prefix ------
extern dynamic Console;
dynamic arr = `[1, 2, 3]`;
Console.WriteLine(arr.length);
Console.WriteLine(arr[1]);
arr[1]=23;
Console.WriteLine(arr[1]);
------ Expected Output ------
3
2
23
------ Generated JavaScript ------
(function() {
// Start Global Code
var arr=[1, 2, 3];
Console.WriteLine(arr.length);
Console.WriteLine(arr[1]);
arr[1] = 23;
Console.WriteLine(arr[1]);
})();
------ Actual Output ------
3
2
23
Test passed!
------ Prefix ------
extern dynamic Console;
class Foo
{
public string this[int index]
{
get
{
Console.WriteLine("int get[" + index.toString() + "]");
return index.toString();
}
set
{
Console.WriteLine("int set[" + index.toString() + "] = " + value);
}
}
public string this[string index]
{
get
{
Console.WriteLine("string get[" + index.toString() + "]");
return index.toString();
}
set
{
Console.WriteLine("string set[" + index.toString() + "] = " + value);
}
}
}
var f = new Foo();
Console.WriteLine(f[99]);
f[99]="newval";
Console.WriteLine(f["str"]);
f["str"]="newval";
------ Expected Output ------
int get[99]
99
int set[99] = newval
string get[str]
str
string set[str] = newval
------ Generated JavaScript ------
(function() {
// class Foo
var Foo = function() {};
Foo.typeName = 'Foo';
Foo.prototype.$get_at$1 = function(index)
{
Console.WriteLine("int get[" + index.toString() + "]");
return index.toString();
};
Foo.prototype.$set_at$1 = function(index, value)
{
Console.WriteLine("int set[" + index.toString() + "] = " + value);
return value;
};
Foo.prototype.$get_at$2 = function(index)
{
Console.WriteLine("string get[" + index.toString() + "]");
return index.toString();
};
Foo.prototype.$set_at$2 = function(index, value)
{
Console.WriteLine("string set[" + index.toString() + "] = " + value);
return value;
};
// Start Global Code
var f=new Foo();
Console.WriteLine(f.$get_at$1(99));
f.$set_at$1(99, "newval");
Console.WriteLine(f.$get_at$2("str"));
f.$set_at$2("str", "newval");
})();
------ Actual Output ------
int get[99]
99
int set[99] = newval
string get[str]
str
string set[str] = newval
Test passed!
------ Prefix ------
extern dynamic Console;
class Foo
{
public string this[int index]
{
get
{
Console.WriteLine("get[" + index.toString() + "]");
return index.toString();
}
set
{
Console.WriteLine("set[" + index.toString() + "] = " + value);
}
}
}
var f = new Foo();
Console.WriteLine(f[99]);
f[99]="newval";
------ Expected Output ------
get[99]
99
set[99] = newval
------ Generated JavaScript ------
(function() {
// class Foo
var Foo = function() {};
Foo.typeName = 'Foo';
Foo.prototype.$get_at = function(index)
{
Console.WriteLine("get[" + index.toString() + "]");
return index.toString();
};
Foo.prototype.$set_at = function(index, value)
{
Console.WriteLine("set[" + index.toString() + "] = " + value);
return value;
};
// Start Global Code
var f=new Foo();
Console.WriteLine(f.$get_at(99));
f.$set_at(99, "newval");
})();
------ Actual Output ------
get[99]
99
set[99] = newval
Test passed!
------ Prefix ------
extern dynamic Console;
string str = "Hello World";
Console.WriteLine(str[1]);
------ Expected Output ------
e
------ Generated JavaScript ------
(function() {
// Start Global Code
var str="Hello World";
Console.WriteLine(str[1]);
})();
------ Actual Output ------
e
Test passed!
------ Prefix ------
extern dynamic Console;
abstract class Base
{
public abstract void fn1();
public virtual void fn2()
{
Console.WriteLine("Base fn2");
}
}
class Derived : Base
{
public override void fn1()
{
Console.WriteLine("Derived fn1");
}
public override void fn2()
{
Console.WriteLine("Derived fn2");
}
}
Base b = new Derived();
b.fn1();
b.fn2();
------ Expected Output ------
Derived fn1
Derived fn2
------ Generated JavaScript ------
(function() {
// class Base
var Base = function() {};
Base.typeName = 'Base';
Base.prototype.fn2 = function()
{
Console.WriteLine("Base fn2");
};
// class Derived
var Derived = function() {};
Derived.typeName = 'Derived';
Derived.prototype = new Base();
Derived.prototype.constructor = Derived;
Derived.prototype.fn1 = function()
{
Console.WriteLine("Derived fn1");
};
Derived.prototype.fn2 = function()
{
Console.WriteLine("Derived fn2");
};
// Start Global Code
var b=new Derived();
b.fn1();
b.fn2();
})();
------ Actual Output ------
Derived fn1
Derived fn2
Test passed!
------ Prefix ------
extern dynamic Console;
abstract class MyBaseClass
{
abstract void Base();
}
------ Expected Output ------
// exception: virtual or abstract members cannot be private
------ Actual Exception ------
Tests.Inheritance.abstract_methods_cant_be_private.txt(5,11): function 'MyBaseClass.Base()': virtual or abstract members cannot be private
Test passed!
------ Prefix ------
extern dynamic Console;
class MyBaseClass
{
public abstract void Base();
}
------ Expected Output ------
// exception: is abstract but it is contained in non-abstract class
------ Actual Exception ------
Tests.Inheritance.abstract_methods_must_be_in_abstract_classes.txt(5,18): function 'MyBaseClass.Base()': is abstract but it is contained in non-abstract class
Test passed!
------ Prefix ------
extern dynamic Console;
abstract class MyBaseClass
{
public abstract void Base()
{
}
}
------ Expected Output ------
// exception: cannot declare a body because it is marked abstract
------ Actual Exception ------
Tests.Inheritance.abstract_methods_must_not_have_body.txt(5,18): function 'MyBaseClass.Base()': cannot declare a body because it is marked abstract
Test passed!
------ Prefix ------
extern dynamic Console;
class MyBaseClass
{
public void Base()
{
}
}
class MyClass : MyBaseClass
{
public void Base()
{
}
}
------ Expected Output ------
// exception: member hiding is not supported
------ Actual Exception ------
Tests.Inheritance.base_methods_cant_be_hidden.txt(12,9): function 'MyClass.Base()' hides inherited member function 'MyBaseClass.Base()' and member hiding is not supported
Test passed!
------ Prefix ------
extern dynamic Console;
abstract class BaseClass
{
public abstract void test();
}
class DerivedClass : BaseClass
{
public override void test()
{
base.test();
Console.WriteLine("Derived");
}
}
------ Expected Output ------
// exception: marked as abstract
------ Actual Exception ------
Tests.Inheritance.cant_call_abstract_base_method.txt(12,8): cannot call function 'BaseClass.test()' because it is marked as abstract
Test passed!
------ Prefix ------
extern dynamic Console;
abstract class BaseClass
{
}
new BaseClass();
------ Expected Output ------
// exception: Can't instantiate
------ Actual Exception ------
Tests.Inheritance.cant_instantiate_abstract_class.txt(7,1): Can't instantiate class 'BaseClass' as it is marked as abstract
Test passed!
------ Prefix ------
extern dynamic Console;
class class1
{
public void Class1()
{
Console.WriteLine("class1");
}
}
class class2 : class1
{
public void Class2()
{
Console.WriteLine("class2");
}
}
class class3 : class2
{
public void Class3()
{
Console.WriteLine("class3");
}
}
class class4 : class3
{
public void Class4()
{
Console.WriteLine("class4");
}
}
var x = new class4();
x.Class1();
x.Class2();
x.Class3();
x.Class4();
------ Expected Output ------
class1
class2
class3
class4
------ Generated JavaScript ------
(function() {
// class class1
var class1 = function() {};
class1.typeName = 'class1';
class1.prototype.Class1 = function()
{
Console.WriteLine("class1");
};
// class class2
var class2 = function() {};
class2.typeName = 'class2';
class2.prototype = new class1();
class2.prototype.constructor = class2;
class2.prototype.Class2 = function()
{
Console.WriteLine("class2");
};
class2.prototype.Class1 = function()
{
Console.WriteLine("class1");
};
// class class3
var class3 = function() {};
class3.typeName = 'class3';
class3.prototype = new class2();
class3.prototype.constructor = class3;
class3.prototype.Class3 = function()
{
Console.WriteLine("class3");
};
class3.prototype.Class2 = function()
{
Console.WriteLine("class2");
};
class3.prototype.Class1 = function()
{
Console.WriteLine("class1");
};
// class class4
var class4 = function() {};
class4.typeName = 'class4';
class4.prototype = new class3();
class4.prototype.constructor = class4;
class4.prototype.Class4 = function()
{
Console.WriteLine("class4");
};
class4.prototype.Class3 = function()
{
Console.WriteLine("class3");
};
class4.prototype.Class2 = function()
{
Console.WriteLine("class2");
};
class4.prototype.Class1 = function()
{
Console.WriteLine("class1");
};
// Start Global Code
var x=new class4();
x.Class1();
x.Class2();
x.Class3();
x.Class4();
})();
------ Actual Output ------
class1
class2
class3
class4
Test passed!
------ Prefix ------
extern dynamic Console;
abstract class BaseClass
{
public abstract void test();
}
class DerivedClass : BaseClass
{
}
------ Expected Output ------
// exception: does not implement abstract
------ Actual Exception ------
Tests.Inheritance.derived_concrete_class_must_implement_all_abstract_methods.txt(8,1): class 'DerivedClass' does not implement abstract function 'BaseClass.test()' and is not marked abstract itself
Test passed!
------ Prefix ------
extern dynamic Console;
class MyBaseClass
{
internal void Base()
{
Console.WriteLine("base");
}
}
class MyClass : MyBaseClass
{
internal void Super()
{
Base();
Console.WriteLine("super");
}
}
new MyClass().Super();
------ Expected Output ------
base
super
------ Generated JavaScript ------
(function() {
// class MyBaseClass
var MyBaseClass = function() {};
MyBaseClass.typeName = 'MyBaseClass';
MyBaseClass.prototype.Base = function()
{
Console.WriteLine("base");
};
// class MyClass
var MyClass = function() {};
MyClass.typeName = 'MyClass';
MyClass.prototype = new MyBaseClass();
MyClass.prototype.constructor = MyClass;
MyClass.prototype.Super = function()
{
this.Base();
Console.WriteLine("super");
};
MyClass.prototype.Base = function()
{
Console.WriteLine("base");
};
// Start Global Code
(new MyClass()).Super();
})();
------ Actual Output ------
base
super
Test passed!
------ Prefix ------
extern dynamic Console;
class MyBaseClass
{
internal void Base()
{
Console.WriteLine("base");
}
}
class MyClass : MyBaseClass
{
internal void Super()
{
Console.WriteLine("super");
}
}
var x = new MyClass();
x.Super();
x.Base();
------ Expected Output ------
super
base
------ Generated JavaScript ------
(function() {
// class MyBaseClass
var MyBaseClass = function() {};
MyBaseClass.typeName = 'MyBaseClass';
MyBaseClass.prototype.Base = function()
{
Console.WriteLine("base");
};
// class MyClass
var MyClass = function() {};
MyClass.typeName = 'MyClass';
MyClass.prototype = new MyBaseClass();
MyClass.prototype.constructor = MyClass;
MyClass.prototype.Super = function()
{
Console.WriteLine("super");
};
MyClass.prototype.Base = function()
{
Console.WriteLine("base");
};
// Start Global Code
var x=new MyClass();
x.Super();
x.Base();
})();
------ Actual Output ------
super
base
Test passed!
------ Prefix ------
extern dynamic Console;
abstract class MyBaseClass
{
public abstract void Base();
}
class MyClass : MyBaseClass
{
public void Base()
{
}
}
------ Expected Output ------
// exception: because it is not marked override
------ Actual Exception ------
Tests.Inheritance.overridden_abstract_methods_must_have_override_modifier.txt(10,9): function 'MyClass.Base()' cannot override function 'MyBaseClass.Base()' because it is not marked override
Test passed!
------ Prefix ------
extern dynamic Console;
class BaseClass
{
public virtual void test()
{
Console.WriteLine("Base");
}
}
class DerivedClass : BaseClass
{
public override void test()
{
Console.WriteLine("Derived");
}
}
BaseClass bc = new DerivedClass();
bc.test();
------ Expected Output ------
Derived
------ Generated JavaScript ------
(function() {
// class BaseClass
var BaseClass = function() {};
BaseClass.typeName = 'BaseClass';
BaseClass.prototype.test = function()
{
Console.WriteLine("Base");
};
// class DerivedClass
var DerivedClass = function() {};
DerivedClass.typeName = 'DerivedClass';
DerivedClass.prototype = new BaseClass();
DerivedClass.prototype.constructor = DerivedClass;
DerivedClass.prototype.test = function()
{
Console.WriteLine("Derived");
};
// Start Global Code
var bc=new DerivedClass();
bc.test();
})();
------ Actual Output ------
Derived
Test passed!
------ Prefix ------
extern dynamic Console;
class BaseClass
{
public virtual void test()
{
Console.WriteLine("Base");
}
}
class DerivedClass : BaseClass
{
public override void test()
{
base.test();
Console.WriteLine("Derived");
}
}
BaseClass bc = new DerivedClass();
bc.test();
------ Expected Output ------
Base
Derived
------ Generated JavaScript ------
(function() {
// class BaseClass
var BaseClass = function() {};
BaseClass.typeName = 'BaseClass';
BaseClass.prototype.test = function()
{
Console.WriteLine("Base");
};
// class DerivedClass
var DerivedClass = function() {};
DerivedClass.typeName = 'DerivedClass';
DerivedClass.prototype = new BaseClass();
DerivedClass.prototype.constructor = DerivedClass;
DerivedClass.prototype.test = function()
{
BaseClass.prototype.test();
Console.WriteLine("Derived");
};
// Start Global Code
var bc=new DerivedClass();
bc.test();
})();
------ Actual Output ------
Base
Derived
Test passed!
------ Prefix ------
extern dynamic Console;
class MyBaseClass
{
public void Base()
{
}
}
class MyClass : MyBaseClass
{
public override void Base()
{
}
}
------ Expected Output ------
// exception: not marked virtual, abstract or override
------ Actual Exception ------
Tests.Inheritance.overridden_methods_must_be_virtual_abstract_override.txt(12,18): cannot override inherited member function 'MyClass.Base()' because it is not marked virtual, abstract or override
Test passed!
------ Prefix ------
extern dynamic Console;
class MyClass
{
void method()
{
Console.WriteLine("base");
}
}
new MyClass().method();
------ Expected Output ------
// exception: inaccessible due to its protection level
------ Actual Exception ------
Tests.Inheritance.private_method_should_not_be_accessible_externally.txt(11,15): 'function 'MyClass.method()'' is inaccessible due to its protection level
Test passed!
------ Prefix ------
extern dynamic Console;
class MyBaseClass
{
private void Base()
{
Console.WriteLine("base");
}
}
class MyClass : MyBaseClass
{
public void Super()
{
Base();
Console.WriteLine("super");
}
}
------ Expected Output ------
// exception: inaccessible due to its protection level
------ Actual Exception ------
Tests.Inheritance.private_method_should_not_be_accessible_to_derived_classes.txt(15,3): 'function 'MyBaseClass.Base()'' is inaccessible due to its protection level
Test passed!
------ Prefix ------
extern dynamic Console;
class MyBaseClass
{
protected void Base()
{
Console.WriteLine("base");
}
}
class MyClass : MyBaseClass
{
public void Super()
{
Base();
Console.WriteLine("super");
}
}
new MyClass().Super();
------ Expected Output ------
base
super
------ Generated JavaScript ------
(function() {
// class MyBaseClass
var MyBaseClass = function() {};
MyBaseClass.typeName = 'MyBaseClass';
MyBaseClass.prototype.Base = function()
{
Console.WriteLine("base");
};
// class MyClass
var MyClass = function() {};
MyClass.typeName = 'MyClass';
MyClass.prototype = new MyBaseClass();
MyClass.prototype.constructor = MyClass;
MyClass.prototype.Super = function()
{
this.Base();
Console.WriteLine("super");
};
MyClass.prototype.Base = function()
{
Console.WriteLine("base");
};
// Start Global Code
(new MyClass()).Super();
})();
------ Actual Output ------
base
super
Test passed!
------ Prefix ------
extern dynamic Console;
class MyClass
{
protected void method()
{
Console.WriteLine("base");
}
}
new MyClass().method();
------ Expected Output ------
// exception: inaccessible due to its protection level
------ Actual Exception ------
Tests.Inheritance.protected_method_should_not_be_accessible_externally.txt(11,15): 'function 'MyClass.method()'' is inaccessible due to its protection level
Test passed!
------ Prefix ------
extern dynamic Console;
class MyBaseClass
{
public void Base()
{
Console.WriteLine("base");
}
}
class MyClass : MyBaseClass
{
public void Super()
{
Base();
Console.WriteLine("super");
}
}
new MyClass().Super();
------ Expected Output ------
base
super
------ Generated JavaScript ------
(function() {
// class MyBaseClass
var MyBaseClass = function() {};
MyBaseClass.typeName = 'MyBaseClass';
MyBaseClass.prototype.Base = function()
{
Console.WriteLine("base");
};
// class MyClass
var MyClass = function() {};
MyClass.typeName = 'MyClass';
MyClass.prototype = new MyBaseClass();
MyClass.prototype.constructor = MyClass;
MyClass.prototype.Super = function()
{
this.Base();
Console.WriteLine("super");
};
MyClass.prototype.Base = function()
{
Console.WriteLine("base");
};
// Start Global Code
(new MyClass()).Super();
})();
------ Actual Output ------
base
super
Test passed!
------ Prefix ------
extern dynamic Console;
class Base
{
public void fn1()
{
Console.WriteLine("base");
}
}
class Derived : Base
{
public void fn2()
{
Console.WriteLine("derived");
}
}
var x = new Derived();
x.fn1();
x.fn2();
------ Expected Output ------
base
derived
------ Generated JavaScript ------
(function() {
// class Base
var Base = function() {};
Base.typeName = 'Base';
Base.prototype.fn1 = function()
{
Console.WriteLine("base");
};
// class Derived
var Derived = function() {};
Derived.typeName = 'Derived';
Derived.prototype = new Base();
Derived.prototype.constructor = Derived;
Derived.prototype.fn2 = function()
{
Console.WriteLine("derived");
};
Derived.prototype.fn1 = function()
{
Console.WriteLine("base");
};
// Start Global Code
var x=new Derived();
x.fn1();
x.fn2();
})();
------ Actual Output ------
base
derived
Test passed!
------ Prefix ------
extern dynamic Console;
class MyBaseClass
{
virtual void Base()
{
}
}
------ Expected Output ------
// exception: virtual or abstract members cannot be private
------ Actual Exception ------
Tests.Inheritance.virtual_methods_cant_be_private.txt(5,10): function 'MyBaseClass.Base()': virtual or abstract members cannot be private
Test passed!
------ Prefix ------
interface I1
{
string prop { get; set; }
}
class MyObject : I1
{
public string prop
{
get; set;
}
}
------ Expected Output ------
------ Generated JavaScript ------
(function() {
// Prefix runtime library
var $dex = {};
$dex.indexOf=Array.prototype.indexOf||function(a){for(var b=0;b<this.length;b++){if(this[b]===a)return b}return-1}
$dex.queryInterface=function(a,b){return a!=null&&a.$interfaces&&$dex.indexOf.call(a.$interfaces,b)>=0?a:null}
// interface I1
var I1 = {};
// class MyObject
var MyObject = function() {};
MyObject.typeName = 'MyObject';
MyObject.prototype.$interfaces = [I1];
MyObject.prototype.prop = null;
MyObject.prototype.get_prop = function()
{
return this.prop;
};
MyObject.prototype.set_prop = function(value)
{
this.prop = value;
return value;
};
})();
------ Actual Output ------
Test passed!
------ Prefix ------
interface A : B
{
}
interface B : C
{
}
interface C : D
{
}
interface D : A
{
}
------ Expected Output ------
// exception: circular base interface dependency
------ Actual Exception ------
Tests.Interfaces.cant_have_circular_base_interface_dependency.txt(13,1): interface 'D': has a circular base interface dependency through base interface 'A'
Test passed!
------ Prefix ------
interface A : B
{
}
interface B : A
{
}
------ Expected Output ------
// exception: circular base interface dependency
------ Actual Exception ------
Tests.Interfaces.cant_have_circular_base_interface_dependency_2.txt(5,1): interface 'B': has a circular base interface dependency through base interface 'A'
Test passed!
------ Prefix ------
interface A : B1, B2
{
}
interface B : A
{
}
interface B1 : B
{
}
interface B2 : B
{
}
------ Expected Output ------
// exception: circular base interface dependency
------ Actual Exception ------
Tests.Interfaces.cant_have_circular_base_interface_dependency_3.txt(5,1): interface 'B': has a circular base interface dependency through base interface 'A'
Test passed!
------ Prefix ------
extern dynamic Console;
interface I1
{
}
interface I2
{
}
class Base
{
}
class Derived : Base, I1
{
}
Base b = new Derived();
Console.WriteLine((b as I1)!=null);
Console.WriteLine(b is I1);
Console.WriteLine((b as I2)!=null);
Console.WriteLine(b is I2);
------ Expected Output ------
True
True
False
False
------ Generated JavaScript ------
(function() {
// Prefix runtime library
var $dex = {};
$dex.indexOf=Array.prototype.indexOf||function(a){for(var b=0;b<this.length;b++){if(this[b]===a)return b}return-1}
$dex.queryInterface=function(a,b){return a!=null&&a.$interfaces&&$dex.indexOf.call(a.$interfaces,b)>=0?a:null}
// interface I1
var I1 = {};
// interface I2
var I2 = {};
// class Base
var Base = function() {};
Base.typeName = 'Base';
// class Derived
var Derived = function() {};
Derived.typeName = 'Derived';
Derived.prototype = new Base();
Derived.prototype.constructor = Derived;
Derived.prototype.$interfaces = [I1];
// Start Global Code
var b=new Derived();
Console.WriteLine(($dex.queryInterface(b, I1))!==null);
Console.WriteLine($dex.queryInterface(b, I1)!==null);
Console.WriteLine(($dex.queryInterface(b, I2))!==null);
Console.WriteLine($dex.queryInterface(b, I2)!==null);
})();
------ Actual Output ------
True
True
False
False
Test passed!
------ Prefix ------
extern dynamic Console;
interface I1
{
}
interface I2
{
}
class MyObject : I1, I2
{
}
I1 i1= new MyObject();
var c = i1 as MyObject;
Console.WriteLine(c!=null);
Console.WriteLine(c is MyObject);
------ Expected Output ------
True
True
------ Generated JavaScript ------
(function() {
// Prefix runtime library
var $dex = {};
$dex.indexOf=Array.prototype.indexOf||function(a){for(var b=0;b<this.length;b++){if(this[b]===a)return b}return-1}
$dex.queryInterface=function(a,b){return a!=null&&a.$interfaces&&$dex.indexOf.call(a.$interfaces,b)>=0?a:null}
// interface I1
var I1 = {};
// interface I2
var I2 = {};
// class MyObject
var MyObject = function() {};
MyObject.typeName = 'MyObject';
MyObject.prototype.$interfaces = [I1, I2];
// Start Global Code
var i1=new MyObject();
var c=(i1 instanceof MyObject) ? i1 : null;
Console.WriteLine(c!==null);
Console.WriteLine((c)!==null);
})();
------ Actual Output ------
True
True
Test passed!
------ Prefix ------
extern dynamic Console;
interface I1
{
void fn1();
}
interface I2
{
void fn2();
}
class MyObject : I1, I2
{
public void fn1()
{
Console.WriteLine("fn1");
}
public void fn2()
{
Console.WriteLine("fn2");
}
}
I1 i1= new MyObject();
I2 i2 = i1 as I2;
Console.WriteLine(i2!=null);
Console.WriteLine(i2 is I1);
i1.fn1();
i2.fn2();
------ Expected Output ------
True
True
fn1
fn2
------ Generated JavaScript ------
(function() {
// Prefix runtime library
var $dex = {};
$dex.indexOf=Array.prototype.indexOf||function(a){for(var b=0;b<this.length;b++){if(this[b]===a)return b}return-1}
$dex.queryInterface=function(a,b){return a!=null&&a.$interfaces&&$dex.indexOf.call(a.$interfaces,b)>=0?a:null}
// interface I1
var I1 = {};
// interface I2
var I2 = {};
// class MyObject
var MyObject = function() {};
MyObject.typeName = 'MyObject';
MyObject.prototype.$interfaces = [I1, I2];
MyObject.prototype.fn1 = function()
{
Console.WriteLine("fn1");
};
MyObject.prototype.fn2 = function()
{
Console.WriteLine("fn2");
};
// Start Global Code
var i1=new MyObject();
var i2=$dex.queryInterface(i1, I2);
Console.WriteLine(i2!==null);
Console.WriteLine($dex.queryInterface(i2, I1)!==null);
i1.fn1();
i2.fn2();
})();
------ Actual Output ------
True
True
fn1
fn2
Test passed!
------ Prefix ------
interface I1
{
void fn();
}
class MyObject : I1
{
public void fn()
{
}
}
------ Expected Output ------
------ Generated JavaScript ------
(function() {
// Prefix runtime library
var $dex = {};
$dex.indexOf=Array.prototype.indexOf||function(a){for(var b=0;b<this.length;b++){if(this[b]===a)return b}return-1}
$dex.queryInterface=function(a,b){return a!=null&&a.$interfaces&&$dex.indexOf.call(a.$interfaces,b)>=0?a:null}
// interface I1
var I1 = {};
// class MyObject
var MyObject = function() {};
MyObject.typeName = 'MyObject';
MyObject.prototype.$interfaces = [I1];
MyObject.prototype.fn = function()
{
};
})();
------ Actual Output ------
Test passed!
------ Prefix ------
// should generate: var IMyInterface =
class MyClass {}
interface IMyInterface : MyClass
{
}
------ Expected Output ------
// exception: is not an interface
------ Actual Exception ------
Tests.Interfaces.interface_cant_derive_from_class.txt(5,26): interface 'IMyInterface': type class 'MyClass' in interface list is not an interface
Test passed!
------ Prefix ------
// should generate: var IMyInterface =
abstract interface IMyInterface
{
}
------ Expected Output ------
// exception: cannot be marked abstract
------ Actual Exception ------
Tests.Interfaces.interface_cant_have_modifiers.txt(3,10): interface 'IMyInterface': interface cannot be marked abstract
Test passed!
------ Prefix ------
interface IMyInterface
{
void Method();
}
------ Expected Output ------
------ Generated JavaScript ------
(function() {
// Prefix runtime library
var $dex = {};
$dex.indexOf=Array.prototype.indexOf||function(a){for(var b=0;b<this.length;b++){if(this[b]===a)return b}return-1}
$dex.queryInterface=function(a,b){return a!=null&&a.$interfaces&&$dex.indexOf.call(a.$interfaces,b)>=0?a:null}
// interface IMyInterface
var IMyInterface = {};
})();
------ Actual Output ------
Test passed!
------ Prefix ------
interface IBase1
{
}
interface IBase2
{
}
interface IMyInterface : IBase1, IBase2
{
}
------ Expected Output ------
------ Generated JavaScript ------
(function() {
// Prefix runtime library
var $dex = {};
$dex.indexOf=Array.prototype.indexOf||function(a){for(var b=0;b<this.length;b++){if(this[b]===a)return b}return-1}
$dex.queryInterface=function(a,b){return a!=null&&a.$interfaces&&$dex.indexOf.call(a.$interfaces,b)>=0?a:null}
// interface IBase1
var IBase1 = {};
// interface IBase2
var IBase2 = {};
// interface IMyInterface
var IMyInterface = {};
})();
------ Actual Output ------
Test passed!
------ Prefix ------
interface IMyInterface
{
string prop { get; set; }
}
------ Expected Output ------
------ Generated JavaScript ------
(function() {
// Prefix runtime library
var $dex = {};
$dex.indexOf=Array.prototype.indexOf||function(a){for(var b=0;b<this.length;b++){if(this[b]===a)return b}return-1}
$dex.queryInterface=function(a,b){return a!=null&&a.$interfaces&&$dex.indexOf.call(a.$interfaces,b)>=0?a:null}
// interface IMyInterface
var IMyInterface = {};
})();
------ Actual Output ------
Test passed!
------ Prefix ------
interface I1
{
}
interface I2
{
}
class MyObject : I1, I2
{
}
------ Expected Output ------
------ Generated JavaScript ------
(function() {
// Prefix runtime library
var $dex = {};
$dex.indexOf=Array.prototype.indexOf||function(a){for(var b=0;b<this.length;b++){if(this[b]===a)return b}return-1}
$dex.queryInterface=function(a,b){return a!=null&&a.$interfaces&&$dex.indexOf.call(a.$interfaces,b)>=0?a:null}
// interface I1
var I1 = {};
// interface I2
var I2 = {};
// class MyObject
var MyObject = function() {};
MyObject.typeName = 'MyObject';
MyObject.prototype.$interfaces = [I1, I2];
})();
------ Actual Output ------
Test passed!
------ Prefix ------
// should generate: var IMyInterface =
interface IMyInterface
{
}
------ Expected Output ------
------ Generated JavaScript ------
(function() {
// Prefix runtime library
var $dex = {};
$dex.indexOf=Array.prototype.indexOf||function(a){for(var b=0;b<this.length;b++){if(this[b]===a)return b}return-1}
$dex.queryInterface=function(a,b){return a!=null&&a.$interfaces&&$dex.indexOf.call(a.$interfaces,b)>=0?a:null}
// interface IMyInterface
var IMyInterface = {};
})();
------ Actual Output ------
Test passed!
------ Prefix ------
interface I1
{
void fn();
}
class MyObject : I1
{
}
------ Expected Output ------
// exception: does not implement interface
------ Actual Exception ------
Tests.Interfaces.must_implement_all_methods.txt(6,1): class 'MyObject': does not implement interface member function 'fn()'
Test passed!
------ Prefix ------
interface I1
{
string prop { get; set; }
}
class MyObject : I1
{
}
------ Expected Output ------
// exception: does not implement interface
------ Actual Exception ------
Tests.Interfaces.must_implement_all_properties.txt(6,1): class 'MyObject': does not implement interface member function 'I1.prop.get()'
Test passed!
------ Prefix ------
interface I1
{
void fn1();
}
interface I2 : I1
{
}
class MyObject : I2
{
}
------ Expected Output ------
// exception: does not implement interface
------ Actual Exception ------
Tests.Interfaces.must_implement_base_interface_methods.txt(11,1): class 'MyObject': does not implement interface member function 'fn1()'
Test passed!
------ Prefix ------
interface I1
{
string prop { get; set; }
}
class MyObject : I1
{
string prop
{
get
{
return "val";
}
}
}
------ Expected Output ------
// exception: does not implement interface
------ Actual Exception ------
Tests.Interfaces.must_implement_both_property_accessor.txt(10,3): class 'MyObject': does not implement interface member function 'I1.prop.get()'. function 'MyObject.prop.get()' cannot implement an interface member because it is not public
Test passed!
------ Prefix ------
// should not generate: var IMyInterface =
// should generate: var IMyInterface;
public interface IMyInterface
{
}
------ Expected Output ------
------ Generated JavaScript ------
// Exported entities
var IMyInterface;
(function() {
// Prefix runtime library
var $dex = {};
$dex.indexOf=Array.prototype.indexOf||function(a){for(var b=0;b<this.length;b++){if(this[b]===a)return b}return-1}
$dex.queryInterface=function(a,b){return a!=null&&a.$interfaces&&$dex.indexOf.call(a.$interfaces,b)>=0?a:null}
// interface IMyInterface
IMyInterface = {};
})();
------ Actual Output ------
Test passed!
------ Prefix ------
extern dynamic Console;
class impl : itf
{
}
interface itf
{
}
Console.WriteLine("OK");
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// Prefix runtime library
var $dex = {};
$dex.indexOf=Array.prototype.indexOf||function(a){for(var b=0;b<this.length;b++){if(this[b]===a)return b}return-1}
$dex.queryInterface=function(a,b){return a!=null&&a.$interfaces&&$dex.indexOf.call(a.$interfaces,b)>=0?a:null}
// interface itf
var itf = {};
// class impl
var impl = function() {};
impl.typeName = 'impl';
impl.prototype.$interfaces = [itf];
// Start Global Code
Console.WriteLine("OK");
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
extern dynamic Console;
double x;
// Simple
x=10.5;
Console.WriteLine(x.toString());
// Negative
x=-10.5;
Console.WriteLine(x.toString());
// Exponent
x=1.5e1;
Console.WriteLine(x.toString());
x=1.5e+1;
Console.WriteLine(x.toString());
x=1.5e-1;
Console.WriteLine(x.toString());
x=-1.5e+1;
Console.WriteLine(x.toString());
x=-1.5e-1;
Console.WriteLine(x.toString());
------ Expected Output ------
10.5
-10.5
15
15
0.15
-15
-0.15
------ Generated JavaScript ------
(function() {
// Start Global Code
var x;
x = 10.5;
Console.WriteLine(x.toString());
x = -10.5;
Console.WriteLine(x.toString());
x = 15;
Console.WriteLine(x.toString());
x = 15;
Console.WriteLine(x.toString());
x = 0.15;
Console.WriteLine(x.toString());
x = -15;
Console.WriteLine(x.toString());
x = -0.15;
Console.WriteLine(x.toString());
})();
------ Actual Output ------
10.5
-10.5
15
15
0.15
-15
-0.15
Test passed!
------ Prefix ------
extern dynamic Console;
int x;
// Decimal Integer
x=10;
Console.WriteLine(x.toString());
// Negative
x=-10;
Console.WriteLine(x.toString());
// Hexadecimal integer
x=0xFF;
Console.WriteLine(x.toString());
x=0XFF;
Console.WriteLine(x.toString());
x=0XFf;
Console.WriteLine(x.toString());
------ Expected Output ------
10
-10
255
255
255
------ Generated JavaScript ------
(function() {
// Start Global Code
var x;
x = 10;
Console.WriteLine(x.toString());
x = -10;
Console.WriteLine(x.toString());
x = 255;
Console.WriteLine(x.toString());
x = 255;
Console.WriteLine(x.toString());
x = 255;
Console.WriteLine(x.toString());
})();
------ Actual Output ------
10
-10
255
255
255
Test passed!
------ Prefix ------
// no warnings
extern dynamic Console;
// Use `backticks` to embed Javascript expressions and statements directly into
// the generated output. Highly discouraged, and will be eventually removed
// but useful for testing and until we support more stuff natively.
// JavaScript array
dynamic x=`["Hello", "World"]`;
// JavaScript code
`
for (var i in x)
{
Console.WriteLine(x[i]);
}
`;
------ Expected Output ------
Hello
World
------ Generated JavaScript ------
(function() {
// Start Global Code
var x=["Hello", "World"];
for (var i in x)
{
Console.WriteLine(x[i]);
}
;
})();
------ Actual Output ------
Hello
World
Test passed!
------ Prefix ------
extern dynamic Console;
object x;
x=null;
Console.WriteLine("OK");
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// Start Global Code
var x;
x = null;
Console.WriteLine("OK");
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
extern dynamic Console;
// Simple string
Console.WriteLine(@"OK
This \is\ a test
To see if ""raw"" strings work ok");
------ Expected Output ------
OK
This \is\ a test
To see if "raw" strings work ok
------ Generated JavaScript ------
(function() {
// Start Global Code
Console.WriteLine("OK\nThis \\is\\ a test\nTo see if \"raw\" strings work ok");
})();
------ Actual Output ------
OK
This \is\ a test
To see if "raw" strings work ok
Test passed!
------ Prefix ------
extern dynamic Console;
// Simple string
Console.WriteLine("OK");
// Tabs
Console.WriteLine("Hello\tWorld");
// Carriage return
Console.WriteLine("Hello\nWorld");
// We can't test \r\n because the test harness converts them to \n - pretty sure it works!
// Backslash
Console.WriteLine("Hello\\World");
// Double Quotes
Console.WriteLine("\"OK\"");
// Single Quotes
Console.WriteLine("\'OK\'");
// Hex encoded
Console.WriteLine("Hello \x41 World"); // \x41 = "A"
// Unicode encoded
Console.WriteLine("Hello \u0041 World");
------ Expected Output ------
OK
Hello World
Hello
World
Hello\World
"OK"
'OK'
Hello A World
Hello A World
------ Generated JavaScript ------
(function() {
// Start Global Code
Console.WriteLine("OK");
Console.WriteLine("Hello\tWorld");
Console.WriteLine("Hello\nWorld");
Console.WriteLine("Hello\\World");
Console.WriteLine("\"OK\"");
Console.WriteLine("'OK'");
Console.WriteLine("Hello A World");
Console.WriteLine("Hello A World");
})();
------ Actual Output ------
OK
Hello World
Hello
World
Hello\World
"OK"
'OK'
Hello A World
Hello A World
Test passed!
------ Prefix ------
extern dynamic Console;
namespace ns
{
class MyClass
{
public string message()
{
return "OK";
}
}
}
Console.WriteLine(new ns.MyClass().message());
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// namespace ns
var ns = new function()
{
// class ns.MyClass
var MyClass = function() {};
MyClass.typeName = 'ns.MyClass';
MyClass.prototype.message = function()
{
return "OK";
};
this.MyClass = MyClass;
}();
// Start Global Code
Console.WriteLine((new ns.MyClass()).message());
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
extern dynamic Console;
namespace ns
{
class MyClass
{
public string message()
{
return "OK";
}
public string message2()
{
return new MyClass().message();
}
}
}
Console.WriteLine(new ns.MyClass().message2());
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// namespace ns
var ns = new function()
{
// class ns.MyClass
var MyClass = function() {};
MyClass.typeName = 'ns.MyClass';
MyClass.prototype.message = function()
{
return "OK";
};
MyClass.prototype.message2 = function()
{
return (new ns.MyClass()).message();
};
this.MyClass = MyClass;
}();
// Start Global Code
Console.WriteLine((new ns.MyClass()).message2());
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
extern dynamic Console;
class Outer
{
string prop = "OK";
class Inner
{
public void test()
{
Console.WriteLine(prop);
}
}
}
------ Expected Output ------
// exception: cannot access members from outer type
------ Actual Exception ------
Tests.NestedClasses.cant_access_outer_class.txt(5,2): MemberVariable prop: cannot access members from outer type
Test passed!
------ Prefix ------
// no warnings
extern dynamic Console;
class Bar
{
public Bar.Nested.Nested3 fn()
{
return null;
}
public class Nested : Nested2
{
}
public class Nested2
{
public class Nested3
{
}
}
}
------ Expected Output ------
------ Generated JavaScript ------
(function() {
// class Bar
var Bar = function() {};
Bar.typeName = 'Bar';
Bar.prototype.fn = function()
{
return null;
};
// class Bar.Nested2
Bar.Nested2 = function() {};
Bar.Nested2.typeName = 'Bar.Nested2';
// class Bar.Nested2.Nested3
Bar.Nested2.Nested3 = function() {};
Bar.Nested2.Nested3.typeName = 'Bar.Nested2.Nested3';
// class Bar.Nested
Bar.Nested = function() {};
Bar.Nested.typeName = 'Bar.Nested';
Bar.Nested.prototype = new Bar.Nested2();
Bar.Nested.prototype.constructor = Bar.Nested;
// Start Global Code
})();
------ Actual Output ------
Test passed!
------ Prefix ------
extern dynamic Console;
class Outer
{
public static Outer.Inner makeInner()
{
return new Outer.Inner();
}
public class Inner
{
public void test()
{
Console.WriteLine("OK");
}
}
}
var x = Outer.makeInner();
x.test();
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// class Outer
var Outer = function() {};
Outer.typeName = 'Outer';
Outer.makeInner = function()
{
return new Outer.Inner();
};
// class Outer.Inner
Outer.Inner = function() {};
Outer.Inner.typeName = 'Outer.Inner';
Outer.Inner.prototype.test = function()
{
Console.WriteLine("OK");
};
// Start Global Code
var x=Outer.makeInner();
x.test();
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
extern dynamic Console;
class Outer
{
public class Inner
{
public void test()
{
Console.WriteLine("OK");
}
}
}
var x = new Outer.Inner();
x.test();
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// class Outer
var Outer = function() {};
Outer.typeName = 'Outer';
// class Outer.Inner
Outer.Inner = function() {};
Outer.Inner.typeName = 'Outer.Inner';
Outer.Inner.prototype.test = function()
{
Console.WriteLine("OK");
};
// Start Global Code
var x=new Outer.Inner();
x.test();
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
extern dynamic Console;
namespace MyCoolLibrary
{
class Outer
{
public class Inner
{
public void test()
{
Console.WriteLine("OK");
}
}
}
}
var x = new MyCoolLibrary.Outer.Inner();
x.test();
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// namespace MyCoolLibrary
var MyCoolLibrary = new function()
{
// class MyCoolLibrary.Outer
var Outer = function() {};
Outer.typeName = 'MyCoolLibrary.Outer';
this.Outer = Outer;
// class MyCoolLibrary.Outer.Inner
Outer.Inner = function() {};
Outer.Inner.typeName = 'MyCoolLibrary.Outer.Inner';
Outer.Inner.prototype.test = function()
{
Console.WriteLine("OK");
};
}();
// Start Global Code
var x=new MyCoolLibrary.Outer.Inner();
x.test();
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
extern dynamic Console;
int val=23;
void fn(int x, int y=val)
{
Console.WriteLine(x+y);
}
fn(10);
------ Expected Output ------
// exception: must be a compile-time constant
------ Actual Exception ------
Tests.OptionalParameters.default_value_must_be_const.txt(5,20): function 'fn(System.Integer,System.Integer)': the default value for parameter 'y' must be a compile-time constant
Test passed!
------ Prefix ------
extern dynamic Console;
void fn(int x, int y="Hello")
{
Console.WriteLine(x+y);
}
fn(10);
------ Expected Output ------
// exception: cannot implicitly convert
------ Actual Exception ------
Tests.OptionalParameters.default_value_must_be_correct_type.txt(3,22): cannot implicitly convert class 'System.String' to class 'System.Integer'
Test passed!
------ Prefix ------
void fn(int x=10, int y)
{
}
------ Expected Output ------
// exception: optional parameters must appear after all required parameters
------ Actual Exception ------
Tests.OptionalParameters.optional_params_must_be_last_1.txt(1,13): 'fn': optional parameters must appear after all required parameters
Test passed!
------ Prefix ------
void fn(int x=10, int y=20, int z)
{
}
------ Expected Output ------
// exception: optional parameters must appear after all required parameters
------ Actual Exception ------
Tests.OptionalParameters.optional_params_must_be_last_2.txt(1,23): 'fn': optional parameters must appear after all required parameters
Test passed!
------ Prefix ------
extern dynamic Console;
void fn(int x, int y=23)
{
Console.WriteLine(x+y);
}
fn(10);
------ Expected Output ------
33
------ Generated JavaScript ------
(function() {
function fn(x, y)
{
Console.WriteLine(x + y);
};
// Start Global Code
fn(10, 23);
})();
------ Actual Output ------
33
Test passed!
------ Prefix ------
extern dynamic Console;
[ExportName("WriteInt")]
public void Write(int x)
{
Console.WriteLine(x.toString());
}
[ExportName("WriteString")]
public void Write(string message)
{
Console.WriteLine(message);
}
`WriteString("OK");`;
`WriteInt(23);`;
------ Expected Output ------
OK
23
------ Generated JavaScript ------
// Exported entities
var Write$1, Write$2;
(function() {
Write$1 = function(x)
{
Console.WriteLine(x.toString());
};
Write$2 = function(message)
{
Console.WriteLine(message);
};
WriteInt = Write$1;
WriteString = Write$2;
// Start Global Code
WriteString("OK");;
WriteInt(23);;
})();
------ Actual Output ------
OK
23
Test passed!
------ Prefix ------
// no warnings
extern dynamic Console;
public class Foo
{
[ExportName("WriteInt")]
public void Write(int x)
{
Console.WriteLine(x.toString());
}
[ExportName("WriteString")]
public void Write(string message)
{
Console.WriteLine(message);
}
}
var x=new Foo();
`x.WriteString("OK");`;
`x.WriteInt(23);`;
------ Expected Output ------
OK
23
------ Generated JavaScript ------
// Exported entities
var Foo;
(function() {
// class Foo
Foo = function() {};
Foo.typeName = 'Foo';
Foo.prototype.Write$1 = function(x)
{
Console.WriteLine(x.toString());
};
Foo.prototype.Write$2 = function(message)
{
Console.WriteLine(message);
};
Foo.prototype.WriteInt = Foo.prototype.Write$1;
Foo.prototype.WriteString = Foo.prototype.Write$2;
// Start Global Code
var x=new Foo();
x.WriteString("OK");;
x.WriteInt(23);;
})();
------ Actual Output ------
OK
23
Test passed!
------ Prefix ------
extern dynamic Console;
public string message(int x)
{
return "OK with Param";
}
public string message(string message)
{
return "Hello " + message;
}
public string message()
{
return "OK";
}
Console.WriteLine(message(99));
Console.WriteLine(message());
Console.WriteLine(message("Cool World"));
------ Expected Output ------
OK with Param
OK
Hello Cool World
------ Generated JavaScript ------
// Exported entities
var message$1, message$2, message$3;
(function() {
message$1 = function(x)
{
return "OK with Param";
};
message$2 = function(message)
{
return "Hello " + message;
};
message$3 = function()
{
return "OK";
};
// Start Global Code
Console.WriteLine(message$1(99));
Console.WriteLine(message$3());
Console.WriteLine(message$2("Cool World"));
})();
------ Actual Output ------
OK with Param
OK
Hello Cool World
Test passed!
------ Prefix ------
extern dynamic Console;
[ExportName("WriteInt")]
internal void Write(int x)
{
Console.WriteLine(x.toString());
}
------ Expected Output ------
// exception: ignored; function not exported
------ Actual Exception ------
Tests.Overloading.internal_global_function_with_custom_name.txt(4,10): Exported name attribute on function 'Write(System.Integer)' ignored; function not exported
Test passed!
------ Prefix ------
extern dynamic Console;
class Foo
{
}
class Bar
{
}
void fn(Foo f)
{
Console.WriteLine("fn(bar)");
}
void fn(Bar b)
{
Console.WriteLine("fn(bar)");
}
fn((Bar)null);
------ Expected Output ------
fn(bar)
------ Generated JavaScript ------
(function() {
// class Foo
var Foo = function() {};
Foo.typeName = 'Foo';
// class Bar
var Bar = function() {};
Bar.typeName = 'Bar';
function fn$1(f)
{
Console.WriteLine("fn(bar)");
};
function fn$2(b)
{
Console.WriteLine("fn(bar)");
};
// Start Global Code
fn$2(null);
})();
------ Actual Output ------
fn(bar)
Test passed!
------ Prefix ------
extern dynamic Console;
class Foo
{
public Foo()
{
}
public string test(int x)
{
return "OK with Param";
}
public string test(string message)
{
return "Hello " + message;
}
public string test()
{
return "OK";
}
}
var x=new Foo();
Console.WriteLine(x.test(99));
Console.WriteLine(x.test());
Console.WriteLine(x.test("Cool World"));
------ Expected Output ------
OK with Param
OK
Hello Cool World
------ Generated JavaScript ------
(function() {
// class Foo
var Foo = function() {};
Foo.typeName = 'Foo';
Foo.prototype.test$1 = function(x)
{
return "OK with Param";
};
Foo.prototype.test$2 = function(message)
{
return "Hello " + message;
};
Foo.prototype.test$3 = function()
{
return "OK";
};
// Start Global Code
var x=new Foo();
Console.WriteLine(x.test$1(99));
Console.WriteLine(x.test$3());
Console.WriteLine(x.test$2("Cool World"));
})();
------ Actual Output ------
OK with Param
OK
Hello Cool World
Test passed!
------ Prefix ------
extern dynamic Console;
abstract class MyBaseClass
{
abstract string prop
{
get;
set;
}
}
------ Expected Output ------
// exception: virtual or abstract members cannot be private
------ Actual Exception ------
Tests.Property.abstract_properties_cant_be_private.txt(7,3): function 'MyBaseClass.prop.get()': virtual or abstract members cannot be private
Test passed!
------ Prefix ------
extern dynamic Console;
class MyBaseClass
{
public abstract string prop
{
get;
set;
}
}
------ Expected Output ------
// exception: is abstract but it is contained in non-abstract class
------ Actual Exception ------
Tests.Property.abstract_properties_must_be_in_abstract_classes.txt(7,3): function 'MyBaseClass.prop.get()': is abstract but it is contained in non-abstract class
Test passed!
------ Prefix ------
extern dynamic Console;
abstract class MyBaseClass
{
public abstract string prop
{
get
{
}
set
{
}
}
}
------ Expected Output ------
// exception: cannot declare a body because it is marked abstract
------ Actual Exception ------
Tests.Property.abstract_properties_must_not_have_body.txt(9,3): property 'prop' - cannot declare a body because it is marked abstract
Test passed!
------ Prefix ------
// should generate: SimpleProperty = "OK";
// should generate: set_SimpleProperty
// should generate: get_SimpleProperty
// Because this auto implemented property is not virtual, the generated JavaScript
// can directly access the backing field - for better readability and performance.
extern dynamic Console;
class MyClass
{
public string SimpleProperty
{
get;
set;
}
}
var x = new MyClass();
x.SimpleProperty = "OK";
Console.WriteLine(x.SimpleProperty);
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// class MyClass
var MyClass = function() {};
MyClass.typeName = 'MyClass';
MyClass.prototype.SimpleProperty = null;
MyClass.prototype.get_SimpleProperty = function()
{
return this.SimpleProperty;
};
MyClass.prototype.set_SimpleProperty = function(value)
{
this.SimpleProperty = value;
return value;
};
// Start Global Code
var x=new MyClass();
x.SimpleProperty = "OK";
Console.WriteLine(x.SimpleProperty);
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
// should not generate: SimpleProperty = "OK";
// should generate: set_SimpleProperty("OK");
// should generate: set_SimpleProperty
// should generate: get_SimpleProperty
// Because this auto implemented property IS virtual, the generated JavaScript
// can't directly access the backing field and must go through the accessor functions
extern dynamic Console;
class MyClass
{
public virtual string SimpleProperty
{
get;
set;
}
}
var x = new MyClass();
x.SimpleProperty = "OK";
Console.WriteLine(x.SimpleProperty);
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// class MyClass
var MyClass = function() {};
MyClass.typeName = 'MyClass';
MyClass.prototype.SimpleProperty = null;
MyClass.prototype.get_SimpleProperty = function()
{
return this.SimpleProperty;
};
MyClass.prototype.set_SimpleProperty = function(value)
{
this.SimpleProperty = value;
return value;
};
// Start Global Code
var x=new MyClass();
x.set_SimpleProperty("OK");
Console.WriteLine(x.get_SimpleProperty());
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
extern dynamic Console;
class MyBaseClass
{
public string prop
{
get;
set;
}
}
class MyClass : MyBaseClass
{
public string prop
{
get;
set;
}
}
------ Expected Output ------
// exception: member hiding is not supported
------ Actual Exception ------
Tests.Property.base_properties_cant_be_hidden.txt(16,3): function 'MyClass.prop.get()' hides inherited member function 'MyBaseClass.prop.get()' and member hiding is not supported
Test passed!
------ Prefix ------
extern dynamic Console;
abstract class BaseClass
{
public abstract string prop
{
get;
set;
}
}
class DerivedClass : BaseClass
{
public override string prop
{
get
{
return base.prop;
}
set
{
}
}
}
------ Expected Output ------
// exception: marked as abstract
------ Actual Exception ------
Tests.Property.cant_call_abstract_base_property.txt(18,16): cannot call function 'BaseClass.prop.get()' because it is marked as abstract
Test passed!
------ Prefix ------
extern dynamic Console;
class MyClass
{
public string SimpleProperty
{
get;
set;
}
}
var x = new MyClass();
x.SimpleProperty = "OK";
x.SimpleProperty +=" Again";
Console.WriteLine(x.SimpleProperty);
------ Expected Output ------
OK Again
------ Generated JavaScript ------
(function() {
// class MyClass
var MyClass = function() {};
MyClass.typeName = 'MyClass';
MyClass.prototype.SimpleProperty = null;
MyClass.prototype.get_SimpleProperty = function()
{
return this.SimpleProperty;
};
MyClass.prototype.set_SimpleProperty = function(value)
{
this.SimpleProperty = value;
return value;
};
// Start Global Code
var x=new MyClass();
x.SimpleProperty = "OK";
x.SimpleProperty += " Again";
Console.WriteLine(x.SimpleProperty);
})();
------ Actual Output ------
OK Again
Test passed!
------ Prefix ------
extern dynamic Console;
class MyClass
{
public int SimpleProperty
{
get;
set;
}
}
var x = new MyClass();
x.SimpleProperty = 23;
x.SimpleProperty /= 10;
Console.WriteLine(x.SimpleProperty.toString());
------ Expected Output ------
2
------ Generated JavaScript ------
(function() {
// class MyClass
var MyClass = function() {};
MyClass.typeName = 'MyClass';
MyClass.prototype.SimpleProperty = 0;
MyClass.prototype.get_SimpleProperty = function()
{
return this.SimpleProperty;
};
MyClass.prototype.set_SimpleProperty = function(value)
{
this.SimpleProperty = value;
return value;
};
// Start Global Code
var $temp;
var x=new MyClass();
x.SimpleProperty = 23;
($temp=x).SimpleProperty = (($temp.SimpleProperty/10)|0);
Console.WriteLine(x.SimpleProperty.toString());
})();
------ Actual Output ------
2
Test passed!
------ Prefix ------
extern dynamic Console;
abstract class BaseClass
{
public abstract string prop
{
get;
set;
}
}
class DerivedClass : BaseClass
{
}
------ Expected Output ------
// exception: does not implement abstract
------ Actual Exception ------
Tests.Property.derived_concrete_class_must_implement_all_abstract_properties.txt(12,1): class 'DerivedClass' does not implement abstract function 'BaseClass.prop.get()' and is not marked abstract itself
Test passed!
------ Prefix ------
extern dynamic Console;
class MyClass
{
public int prop
{
get;
set;
}
}
var x = new MyClass();
x.prop = 23;
Console.WriteLine((x.prop++).toString());
Console.WriteLine((x.prop--).toString());
------ Expected Output ------
23
24
------ Generated JavaScript ------
(function() {
// class MyClass
var MyClass = function() {};
MyClass.typeName = 'MyClass';
MyClass.prototype.prop = 0;
MyClass.prototype.get_prop = function()
{
return this.prop;
};
MyClass.prototype.set_prop = function(value)
{
this.prop = value;
return value;
};
// Start Global Code
var x=new MyClass();
x.prop = 23;
Console.WriteLine((x.prop++).toString());
Console.WriteLine((x.prop--).toString());
})();
------ Actual Output ------
23
24
Test passed!
------ Prefix ------
extern dynamic Console;
class MyClass
{
public int prop
{
get;
set;
}
}
var x = new MyClass();
x.prop = 23;
MyClass GetIt()
{
return x;
}
Console.WriteLine((GetIt().prop++).toString());
Console.WriteLine((GetIt().prop--).toString());
------ Expected Output ------
23
24
------ Generated JavaScript ------
(function() {
// class MyClass
var MyClass = function() {};
MyClass.typeName = 'MyClass';
MyClass.prototype.prop = 0;
MyClass.prototype.get_prop = function()
{
return this.prop;
};
MyClass.prototype.set_prop = function(value)
{
this.prop = value;
return value;
};
function GetIt()
{
return x;
};
// Start Global Code
var x=new MyClass();
x.prop = 23;
Console.WriteLine((GetIt().prop++).toString());
Console.WriteLine((GetIt().prop--).toString());
})();
------ Actual Output ------
23
24
Test passed!
------ Prefix ------
extern dynamic Console;
class MyClass
{
public int prop
{
get;
set;
}
}
var x = new MyClass();
x.prop = 23;
Console.WriteLine((++x.prop).toString());
Console.WriteLine((--x.prop).toString());
------ Expected Output ------
24
23
------ Generated JavaScript ------
(function() {
// class MyClass
var MyClass = function() {};
MyClass.typeName = 'MyClass';
MyClass.prototype.prop = 0;
MyClass.prototype.get_prop = function()
{
return this.prop;
};
MyClass.prototype.set_prop = function(value)
{
this.prop = value;
return value;
};
// Start Global Code
var x=new MyClass();
x.prop = 23;
Console.WriteLine((++x.prop).toString());
Console.WriteLine((--x.prop).toString());
})();
------ Actual Output ------
24
23
Test passed!
------ Prefix ------
extern dynamic Console;
class MyClass
{
public int prop
{
get;
set;
}
}
var x = new MyClass();
x.prop = 23;
MyClass GetIt()
{
Console.WriteLine("GetIt");
return x;
}
Console.WriteLine((++GetIt().prop).toString());
Console.WriteLine((--GetIt().prop).toString());
------ Expected Output ------
GetIt
24
GetIt
23
------ Generated JavaScript ------
(function() {
// class MyClass
var MyClass = function() {};
MyClass.typeName = 'MyClass';
MyClass.prototype.prop = 0;
MyClass.prototype.get_prop = function()
{
return this.prop;
};
MyClass.prototype.set_prop = function(value)
{
this.prop = value;
return value;
};
function GetIt()
{
Console.WriteLine("GetIt");
return x;
};
// Start Global Code
var x=new MyClass();
x.prop = 23;
Console.WriteLine((++GetIt().prop).toString());
Console.WriteLine((--GetIt().prop).toString());
})();
------ Actual Output ------
GetIt
24
GetIt
23
Test passed!
------ Prefix ------
extern dynamic Console;
class MyBaseClass
{
internal string prop
{
get
{
return "Base";
}
}
}
class MyClass : MyBaseClass
{
}
var x = new MyClass();
Console.WriteLine(x.prop);
------ Expected Output ------
Base
------ Generated JavaScript ------
(function() {
// class MyBaseClass
var MyBaseClass = function() {};
MyBaseClass.typeName = 'MyBaseClass';
MyBaseClass.prototype.get_prop = function()
{
return "Base";
};
// class MyClass
var MyClass = function() {};
MyClass.typeName = 'MyClass';
MyClass.prototype = new MyBaseClass();
MyClass.prototype.constructor = MyClass;
MyClass.prototype.get_prop = function()
{
return "Base";
};
// Start Global Code
var x=new MyClass();
Console.WriteLine(x.get_prop());
})();
------ Actual Output ------
Base
Test passed!
------ Prefix ------
extern dynamic Console;
class MyBaseClass
{
internal string prop
{
get
{
return "base";
}
}
}
class MyClass : MyBaseClass
{
internal string prop2
{
get
{
return prop;
}
}
}
Console.WriteLine(new MyClass().prop2);
------ Expected Output ------
base
------ Generated JavaScript ------
(function() {
// class MyBaseClass
var MyBaseClass = function() {};
MyBaseClass.typeName = 'MyBaseClass';
MyBaseClass.prototype.get_prop = function()
{
return "base";
};
// class MyClass
var MyClass = function() {};
MyClass.typeName = 'MyClass';
MyClass.prototype = new MyBaseClass();
MyClass.prototype.constructor = MyClass;
MyClass.prototype.get_prop2 = function()
{
return this.get_prop();
};
MyClass.prototype.get_prop = function()
{
return "base";
};
// Start Global Code
Console.WriteLine((new MyClass()).get_prop2());
})();
------ Actual Output ------
base
Test passed!
------ Prefix ------
extern dynamic Console;
abstract class MyBaseClass
{
public abstract string prop
{
get;
set;
}
}
class MyClass : MyBaseClass
{
public string prop
{
get
{
}
set
{
}
}
}
------ Expected Output ------
// exception: because it is not marked override
------ Actual Exception ------
Tests.Property.overridden_abstract_properties_must_have_override_modifier.txt(16,3): function 'MyClass.prop.get()' cannot override function 'MyBaseClass.prop.get()' because it is not marked override
Test passed!
------ Prefix ------
extern dynamic Console;
class BaseClass
{
public virtual string prop
{
get
{
return "base";
}
}
}
class DerivedClass : BaseClass
{
public override string prop
{
get
{
return base.prop;
}
}
}
BaseClass bc = new DerivedClass();
Console.WriteLine(bc.prop);
------ Expected Output ------
base
------ Generated JavaScript ------
(function() {
// class BaseClass
var BaseClass = function() {};
BaseClass.typeName = 'BaseClass';
BaseClass.prototype.get_prop = function()
{
return "base";
};
// class DerivedClass
var DerivedClass = function() {};
DerivedClass.typeName = 'DerivedClass';
DerivedClass.prototype = new BaseClass();
DerivedClass.prototype.constructor = DerivedClass;
DerivedClass.prototype.get_prop = function()
{
return BaseClass.prototype.get_prop();
};
// Start Global Code
var bc=new DerivedClass();
Console.WriteLine(bc.get_prop());
})();
------ Actual Output ------
base
Test passed!
------ Prefix ------
extern dynamic Console;
class MyBaseClass
{
public string prop
{
get;
set;
}
}
class MyClass : MyBaseClass
{
public override string prop
{
get;
set;
}
}
------ Expected Output ------
// exception: not marked virtual, abstract or override
------ Actual Exception ------
Tests.Property.overridden_properties_must_be_virtual_abstract_override.txt(16,3): cannot override inherited member function 'MyClass.prop.get()' because it is not marked virtual, abstract or override
Test passed!
------ Prefix ------
extern dynamic Console;
class BaseClass
{
public virtual string prop
{
get
{
return "Base";
}
}
}
class DerivedClass : BaseClass
{
public override string prop
{
get
{
return "Derived";
}
}
}
BaseClass bc = new DerivedClass();
Console.WriteLine(bc.prop);
------ Expected Output ------
Derived
------ Generated JavaScript ------
(function() {
// class BaseClass
var BaseClass = function() {};
BaseClass.typeName = 'BaseClass';
BaseClass.prototype.get_prop = function()
{
return "Base";
};
// class DerivedClass
var DerivedClass = function() {};
DerivedClass.typeName = 'DerivedClass';
DerivedClass.prototype = new BaseClass();
DerivedClass.prototype.constructor = DerivedClass;
DerivedClass.prototype.get_prop = function()
{
return "Derived";
};
// Start Global Code
var bc=new DerivedClass();
Console.WriteLine(bc.get_prop());
})();
------ Actual Output ------
Derived
Test passed!
------ Prefix ------
extern dynamic Console;
class MyClass
{
string prop
{
get
{
Console.WriteLine("base");
}
}
}
Console.WriteLine(new MyClass().prop);
------ Expected Output ------
// exception: inaccessible due to its protection level
------ Actual Exception ------
Tests.Property.private_property_should_not_be_accessible_externally.txt(14,33): 'function 'MyClass.prop.get()'' is inaccessible due to its protection level
Test passed!
------ Prefix ------
extern dynamic Console;
class MyBaseClass
{
private string prop
{
get
{
return "base";
}
}
}
class MyClass : MyBaseClass
{
public void Test()
{
Console.WriteLine(prop.toString());
}
}
------ Expected Output ------
// exception: inaccessible due to its protection level
------ Actual Exception ------
Tests.Property.private_property_should_not_be_accessible_to_derived_classes.txt(18,21): 'function 'MyBaseClass.prop.get()'' is inaccessible due to its protection level
Test passed!
------ Prefix ------
class MyClass
{
void SimpleProperty
{
get;
set;
}
}
------ Expected Output ------
// exception: cannot be void
------ Actual Exception ------
Tests.Property.properties_cant_be_void.txt(3,2): property 'SimpleProperty': a property cannot be void
Test passed!
------ Prefix ------
extern dynamic Console;
class MyBaseClass
{
protected string prop
{
get
{
return "base";
}
}
}
class MyClass : MyBaseClass
{
public void Super()
{
Console.WriteLine(prop);
}
}
new MyClass().Super();
------ Expected Output ------
base
------ Generated JavaScript ------
(function() {
// class MyBaseClass
var MyBaseClass = function() {};
MyBaseClass.typeName = 'MyBaseClass';
MyBaseClass.prototype.get_prop = function()
{
return "base";
};
// class MyClass
var MyClass = function() {};
MyClass.typeName = 'MyClass';
MyClass.prototype = new MyBaseClass();
MyClass.prototype.constructor = MyClass;
MyClass.prototype.Super = function()
{
Console.WriteLine(this.get_prop());
};
MyClass.prototype.get_prop = function()
{
return "base";
};
// Start Global Code
(new MyClass()).Super();
})();
------ Actual Output ------
base
Test passed!
------ Prefix ------
extern dynamic Console;
class MyClass
{
protected string prop
{
get
{
return "base";
}
}
}
Console.WriteLine(new MyClass().prop);
------ Expected Output ------
// exception: inaccessible due to its protection level
------ Actual Exception ------
Tests.Property.protected_property_should_not_be_accessible_externally.txt(14,33): 'function 'MyClass.prop.get()'' is inaccessible due to its protection level
Test passed!
------ Prefix ------
extern dynamic Console;
class Base
{
public string prop
{
get
{
return "base";
}
}
}
class Derived : Base
{
}
var x = new Derived();
Console.WriteLine(x.prop);
------ Expected Output ------
base
------ Generated JavaScript ------
(function() {
// class Base
var Base = function() {};
Base.typeName = 'Base';
Base.prototype.get_prop = function()
{
return "base";
};
// class Derived
var Derived = function() {};
Derived.typeName = 'Derived';
Derived.prototype = new Base();
Derived.prototype.constructor = Derived;
Derived.prototype.get_prop = function()
{
return "base";
};
// Start Global Code
var x=new Derived();
Console.WriteLine(x.get_prop());
})();
------ Actual Output ------
base
Test passed!
------ Prefix ------
extern dynamic Console;
class MyBaseClass
{
public string prop
{
get
{
return "base";
}
}
}
class MyClass : MyBaseClass
{
public void Super()
{
Console.WriteLine(prop);
}
}
new MyClass().Super();
------ Expected Output ------
base
------ Generated JavaScript ------
(function() {
// class MyBaseClass
var MyBaseClass = function() {};
MyBaseClass.typeName = 'MyBaseClass';
MyBaseClass.prototype.get_prop = function()
{
return "base";
};
// class MyClass
var MyClass = function() {};
MyClass.typeName = 'MyClass';
MyClass.prototype = new MyBaseClass();
MyClass.prototype.constructor = MyClass;
MyClass.prototype.Super = function()
{
Console.WriteLine(this.get_prop());
};
MyClass.prototype.get_prop = function()
{
return "base";
};
// Start Global Code
(new MyClass()).Super();
})();
------ Actual Output ------
base
Test passed!
------ Prefix ------
extern dynamic Console;
class MyClass
{
string _prop;
public string SimpleProperty
{
get
{
Console.WriteLine("get");
return _prop;
}
set
{
Console.WriteLine("set");
_prop = value;
}
}
}
var x = new MyClass();
x.SimpleProperty = "OK";
Console.WriteLine(x.SimpleProperty);
------ Expected Output ------
set
get
OK
------ Generated JavaScript ------
(function() {
// class MyClass
var MyClass = function() {};
MyClass.typeName = 'MyClass';
MyClass.prototype._prop = null;
MyClass.prototype.get_SimpleProperty = function()
{
Console.WriteLine("get");
return this._prop;
};
MyClass.prototype.set_SimpleProperty = function(value)
{
Console.WriteLine("set");
this._prop = value;
return value;
};
// Start Global Code
var x=new MyClass();
x.set_SimpleProperty("OK");
Console.WriteLine(x.get_SimpleProperty());
})();
------ Actual Output ------
set
get
OK
Test passed!
------ Prefix ------
extern dynamic Console;
class MyBaseClass
{
virtual string prop
{
get;
set;
}
}
------ Expected Output ------
// exception: virtual or abstract members cannot be private
------ Actual Exception ------
Tests.Property.virtual_properties_cant_be_private.txt(7,3): function 'MyBaseClass.prop.get()': virtual or abstract members cannot be private
Test passed!
------ Prefix ------
protected class MyClass
{
}
------ Expected Output ------
// exception: cannot be marked protected
------ Actual Exception ------
Tests.Protection.cant_declare_protected_class.txt(1,11): class 'MyClass': class cannot be marked protected
Test passed!
------ Prefix ------
protected void MyFunction()
{
}
------ Expected Output ------
// exception: cannot be marked protected
------ Actual Exception ------
Tests.Protection.cant_declare_protected_global_function.txt(1,11): function 'MyFunction()': global function cannot be marked protected
Test passed!
------ Prefix ------ protected string MyString; ------ Expected Output ------ // exception: cannot be marked protected ------ Actual Exception ------ Tests.Protection.cant_declare_protected_global_variable.txt(1,11): GlobalVariable MyString: global variable cannot be marked protected Test passed!
------ Prefix ------
public class Foo
{
}
public Foo MyFunction()
{
return null;
}
------ Expected Output ------
------ Generated JavaScript ------
// Exported entities
var MyFunction, Foo;
(function() {
// class Foo
Foo = function() {};
Foo.typeName = 'Foo';
MyFunction = function()
{
return null;
};
})();
------ Actual Output ------
Test passed!
------ Prefix ------
// no warnings
public class Foo
{
}
public Foo MyVariable;
------ Expected Output ------
------ Generated JavaScript ------
// Exported entities
var MyVariable, Foo;
(function() {
// class Foo
Foo = function() {};
Foo.typeName = 'Foo';
// Start Global Code
;
})();
------ Actual Output ------
Test passed!
------ Prefix ------
public class Foo
{
}
public class Bar
{
public Foo MyFunction()
{
return null;
}
}
------ Expected Output ------
------ Generated JavaScript ------
// Exported entities
var Foo, Bar;
(function() {
// class Foo
Foo = function() {};
Foo.typeName = 'Foo';
// class Bar
Bar = function() {};
Bar.typeName = 'Bar';
Bar.prototype.MyFunction = function()
{
return null;
};
})();
------ Actual Output ------
Test passed!
------ Prefix ------
public class Foo
{
}
public class Bar
{
public Foo MyVar
{
get;
set;
}
}
------ Expected Output ------
------ Generated JavaScript ------
// Exported entities
var Foo, Bar;
(function() {
// class Foo
Foo = function() {};
Foo.typeName = 'Foo';
// class Bar
Bar = function() {};
Bar.typeName = 'Bar';
Bar.prototype.MyVar = null;
Bar.prototype.get_MyVar = function()
{
return this.MyVar;
};
Bar.prototype.set_MyVar = function(value)
{
this.MyVar = value;
return value;
};
})();
------ Actual Output ------
Test passed!
------ Prefix ------
// no warnings
public class Foo
{
}
public class Bar
{
public Foo MyVar;
}
------ Expected Output ------
------ Generated JavaScript ------
// Exported entities
var Foo, Bar;
(function() {
// class Foo
Foo = function() {};
Foo.typeName = 'Foo';
// class Bar
Bar = function() {};
Bar.typeName = 'Bar';
Bar.prototype.MyVar = null;
})();
------ Actual Output ------
Test passed!
------ Prefix ------
class Foo
{
}
public class Bar : Foo
{
}
------ Expected Output ------
// exception: Inconsistent accessibility
------ Actual Exception ------
Tests.Protection.inconsistent_base_class.txt(5,8): Inconsistent accessibility: base class class 'Foo' is less accessible than class 'Bar''
Test passed!
------ Prefix ------
class Foo
{
}
public Foo MyFunction()
{
return null;
}
------ Expected Output ------
// exception: Inconsistent accessibility
------ Actual Exception ------
Tests.Protection.inconsistent_global_function.txt(5,8): Inconsistent accessibility: return type class 'Foo' is less accessible than function 'MyFunction()''
Test passed!
------ Prefix ------
class Foo
{
}
public Foo MyVariable;
------ Expected Output ------
// exception: Inconsistent accessibility
------ Actual Exception ------
Tests.Protection.inconsistent_global_variable.txt(5,8): Inconsistent accessibility: variable type class 'Foo' is less accessible than GlobalVariable MyVariable'
Test passed!
------ Prefix ------
class Foo
{
}
public class Bar
{
public Foo MyFunction()
{
return null;
}
}
------ Expected Output ------
// exception: Inconsistent accessibility
------ Actual Exception ------
Tests.Protection.inconsistent_member_function.txt(7,9): Inconsistent accessibility: return type class 'Foo' is less accessible than function 'Bar.MyFunction()''
Test passed!
------ Prefix ------
class Foo
{
}
public class Bar
{
public Foo MyVar
{
get;
set;
}
}
------ Expected Output ------
// exception: Inconsistent accessibility
------ Actual Exception ------
Tests.Protection.inconsistent_member_property.txt(9,3): Inconsistent accessibility: return type class 'Foo' is less accessible than function 'Bar.MyVar.get()''
Test passed!
------ Prefix ------
class Foo
{
}
public class Bar
{
public Foo MyVar;
}
------ Expected Output ------
// exception: Inconsistent accessibility
------ Actual Exception ------
Tests.Protection.inconsistent_member_variable.txt(7,9): Inconsistent accessibility: variable type class 'Foo' is less accessible than MemberVariable MyVar'
Test passed!
------ Prefix ------
// should not generate: var MyClass;
// should generate: var MyClass = function()
extern dynamic Console;
internal class MyClass
{
public string SimpleProperty
{
get;
set;
}
}
var x = new MyClass();
x.SimpleProperty = "OK";
Console.WriteLine(x.SimpleProperty);
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// class MyClass
var MyClass = function() {};
MyClass.typeName = 'MyClass';
MyClass.prototype.SimpleProperty = null;
MyClass.prototype.get_SimpleProperty = function()
{
return this.SimpleProperty;
};
MyClass.prototype.set_SimpleProperty = function(value)
{
this.SimpleProperty = value;
return value;
};
// Start Global Code
var x=new MyClass();
x.SimpleProperty = "OK";
Console.WriteLine(x.SimpleProperty);
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
// should not generate: var MyFunction;
// should generate: function MyFunction()
extern dynamic Console;
internal string MyFunction()
{
return "OK";
}
Console.WriteLine(MyFunction());
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
function MyFunction()
{
return "OK";
};
// Start Global Code
Console.WriteLine(MyFunction());
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
// should not generate: var MyVariable;
// should generate: var MyVariable="OK";
extern dynamic Console;
internal string MyVariable = "OK";
Console.WriteLine(MyVariable);
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// Start Global Code
var MyVariable="OK";
Console.WriteLine(MyVariable);
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
// no warnings
// should not generate: var A, B;
// should generate: var A="A", B="B";
extern dynamic Console;
internal string A = "A", B = "B";
Console.WriteLine(A);
------ Expected Output ------
A
------ Generated JavaScript ------
(function() {
// Start Global Code
var A="A", B="B";
Console.WriteLine(A);
})();
------ Actual Output ------
A
Test passed!
------ Prefix ------
// should generate: var MyClass;
// should generate: MyClass = function()
// should not generate: var MyClass = function()
extern dynamic Console;
public class MyClass
{
public string SimpleProperty
{
get;
set;
}
}
var x = new MyClass();
x.SimpleProperty = "OK";
Console.WriteLine(x.SimpleProperty);
------ Expected Output ------
OK
------ Generated JavaScript ------
// Exported entities
var MyClass;
(function() {
// class MyClass
MyClass = function() {};
MyClass.typeName = 'MyClass';
MyClass.prototype.SimpleProperty = null;
MyClass.prototype.get_SimpleProperty = function()
{
return this.SimpleProperty;
};
MyClass.prototype.set_SimpleProperty = function(value)
{
this.SimpleProperty = value;
return value;
};
// Start Global Code
var x=new MyClass();
x.SimpleProperty = "OK";
Console.WriteLine(x.SimpleProperty);
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
// should generate: var MyFunction;
// should generate: MyFunction = function
// should not generate: var MyFunction =
extern dynamic Console;
public string MyFunction()
{
return "OK";
}
Console.WriteLine(MyFunction());
------ Expected Output ------
OK
------ Generated JavaScript ------
// Exported entities
var MyFunction;
(function() {
MyFunction = function()
{
return "OK";
};
// Start Global Code
Console.WriteLine(MyFunction());
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
// should generate: var MyVariable;
// should generate: MyVariable="OK";
// should not generate: var MyVariable="OK";
extern dynamic Console;
public string MyVariable = "OK";
Console.WriteLine(MyVariable);
------ Expected Output ------
OK
------ Generated JavaScript ------
// Exported entities
var MyVariable;
(function() {
// Start Global Code
MyVariable="OK";
Console.WriteLine(MyVariable);
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
// no warnings
// should generate: var A, B;
// should generate: A="A"; B="B";
// should not generate: var A="A";
extern dynamic Console;
public string A = "A", B = "B";
Console.WriteLine(A);
------ Expected Output ------
A
------ Generated JavaScript ------
// Exported entities
var A, B;
(function() {
// Start Global Code
A="A"; B="B";
Console.WriteLine(A);
})();
------ Actual Output ------
A
Test passed!
------ Prefix ------ extern dynamic Console; break; ------ Expected Output ------ // exception: No enclosing switch or loop statement out of which to break ------ Actual Exception ------ Tests.Statements.break_must_be_in_loop.txt(2,1): No enclosing switch or loop statement out of which to break Test passed!
------ Prefix ------ extern dynamic Console; continue; ------ Expected Output ------ // exception: No enclosing loop out of which to continue ------ Actual Exception ------ Tests.Statements.continue_must_be_in_loop.txt(2,1): No enclosing loop out of which to continue Test passed!
------ Prefix ------
extern dynamic Console;
do
{
Console.WriteLine("OK");
} while (false);
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// Start Global Code
do {
Console.WriteLine("OK");
}
while (false);
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
extern dynamic Console;
do
{
Console.WriteLine("whatever");
} while ("This is not a boolean");
------ Expected Output ------
// exception: cannot implicitly convert class 'System.String' to class 'System.Boolean'
------ Actual Exception ------
Tests.Statements.do_while_expects_boolean_expression.txt(5,10): cannot implicitly convert class 'System.String' to class 'System.Boolean'
Test passed!
------ Prefix ------
extern dynamic Console;
var t = true, f = false;
for ( ; f ; )
{
Console.WriteLine("true");
}
for ( ; t ; )
{
Console.WriteLine("true");
break;
}
------ Expected Output ------
true
------ Generated JavaScript ------
(function() {
// Start Global Code
var t=true, f=false;
for (; f; )
{
Console.WriteLine("true");
}
for (; t; )
{
Console.WriteLine("true");
break;
}
})();
------ Actual Output ------
true
Test passed!
------ Prefix ------
extern dynamic Console;
for ( ; "This is not a boolean" ; )
{
}
------ Expected Output ------
// exception: cannot implicitly convert class 'System.String' to class 'System.Boolean'
------ Actual Exception ------
Tests.Statements.for_expects_boolean_condition.txt(2,9): cannot implicitly convert class 'System.String' to class 'System.Boolean'
Test passed!
------ Prefix ------
extern dynamic Console;
int i;
for (i=0; i<3; i++)
{
Console.WriteLine(i.toString());
}
------ Expected Output ------
0
1
2
------ Generated JavaScript ------
(function() {
// Start Global Code
var i;
for (i = 0; i<3; i++)
{
Console.WriteLine(i.toString());
}
})();
------ Actual Output ------
0
1
2
Test passed!
------ Prefix ------
extern dynamic Console;
for (var i=0; i<3; i++)
{
Console.WriteLine(i.toString());
}
------ Expected Output ------
0
1
2
------ Generated JavaScript ------
(function() {
// Start Global Code
for (var i=0; i<3; i++)
{
Console.WriteLine(i.toString());
}
})();
------ Actual Output ------
0
1
2
Test passed!
------ Prefix ------
extern dynamic Console;
var t = true, f = false;
if (t)
{
Console.WriteLine("true");
}
if (f)
{
Console.WriteLine("false");
}
if (t)
{
Console.WriteLine("true");
}
else
{
Console.WriteLine("false");
}
------ Expected Output ------
true
true
------ Generated JavaScript ------
(function() {
// Start Global Code
var t=true, f=false;
if (t)
{
Console.WriteLine("true");
}
if (f)
{
Console.WriteLine("false");
}
if (t)
{
Console.WriteLine("true");
}
else
{
Console.WriteLine("false");
}
})();
------ Actual Output ------
true
true
Test passed!
------ Prefix ------
extern dynamic Console;
if ("This is not a boolean")
{
Console.WriteLine("true");
}
------ Expected Output ------
// exception: cannot implicitly convert class 'System.String' to class 'System.Boolean'
------ Actual Exception ------
Tests.Statements.if_expects_boolean_expression.txt(2,5): cannot implicitly convert class 'System.String' to class 'System.Boolean'
Test passed!
------ Prefix ------
extern dynamic Console;
int x=11;
if (x>10)
{
Console.WriteLine("Cool");
}
else
{
Console.WriteLine("That Sucks");
}
------ Expected Output ------
Cool
------ Generated JavaScript ------
(function() {
// Start Global Code
var x=11;
if (x>10)
{
Console.WriteLine("Cool");
}
else
{
Console.WriteLine("That Sucks");
}
})();
------ Actual Output ------
Cool
Test passed!
------ Prefix ------
extern dynamic Console;
int x = 1;
switch (x)
{
case 1:
Console.WriteLine("X");
case 2:
Console.WriteLine("Y");
break;
}
------ Expected Output ------
// exception: Control cannot fall through
------ Actual Exception ------
Tests.Statements.switch_all_cases_must_break.txt(5,2): Control cannot fall through from one case label ('case 1') to another
Test passed!
------ Prefix ------
extern dynamic Console;
switch (1)
{
case 1:
Console.WriteLine("X");
break;
case 1:
Console.WriteLine("Y");
break;
}
------ Expected Output ------
// exception: already occurs in this switch statement
------ Actual Exception ------
Tests.Statements.switch_all_labels_must_be_unique.txt(8,7): The label 'case 1:' already occurs in this switch statement
Test passed!
------ Prefix ------
extern dynamic Console;
switch (1)
{
case 1+1: // Constant expressions should be evaluated and checked for uniqueness
break;
case 2:
break;
}
------ Expected Output ------
// exception: already occurs in this switch statement
------ Actual Exception ------
Tests.Statements.switch_all_labels_must_be_unique_2.txt(7,7): The label 'case 2:' already occurs in this switch statement
Test passed!
------ Prefix ------
extern dynamic Console;
int x = 3;
switch (x)
{
case 1:
Console.WriteLine("X");
break;
case 2:
Console.WriteLine("Y");
break;
default:
Console.WriteLine("Z");
break;
}
------ Expected Output ------
Z
------ Generated JavaScript ------
(function() {
// Start Global Code
var x=3;
switch (x)
{
case 1:
Console.WriteLine("X");
break;
case 2:
Console.WriteLine("Y");
break;
default:
Console.WriteLine("Z");
break;
}
})();
------ Actual Output ------
Z
Test passed!
------ Prefix ------
extern dynamic Console;
int x = 3;
switch (x)
{
default:
Console.WriteLine("Z");
break;
case 1:
Console.WriteLine("X");
break;
case 2:
Console.WriteLine("Y");
break;
}
------ Expected Output ------
Z
------ Generated JavaScript ------
(function() {
// Start Global Code
var x=3;
switch (x)
{
default:
Console.WriteLine("Z");
break;
case 1:
Console.WriteLine("X");
break;
case 2:
Console.WriteLine("Y");
break;
}
})();
------ Actual Output ------
Z
Test passed!
------ Prefix ------
extern dynamic Console;
switch (1)
{
case 1:
case 2:
Console.WriteLine("OK");
break;
}
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// Start Global Code
switch (1)
{
case 1:
case 2:
Console.WriteLine("OK");
break;
}
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
extern dynamic Console;
int x=1;
switch (x)
{
case 1:
Console.WriteLine("X");
break;
case 2:
Console.WriteLine("Y");
break;
}
------ Expected Output ------
X
------ Generated JavaScript ------
(function() {
// Start Global Code
var x=1;
switch (x)
{
case 1:
Console.WriteLine("X");
break;
case 2:
Console.WriteLine("Y");
break;
}
})();
------ Actual Output ------
X
Test passed!
------ Prefix ------
extern dynamic Console;
int x;
switch (3)
{
case x:
break;
}
------ Expected Output ------
// exception: must be constant
------ Actual Exception ------
Tests.Statements.switch_labels_must_be_const.txt(5,7): Case labels must be constant expressions
Test passed!
------ Prefix ------
extern dynamic Console;
string x = "X";
switch (x)
{
case "X":
Console.WriteLine("X");
break;
case "Y":
Console.WriteLine("Y");
break;
}
------ Expected Output ------
X
------ Generated JavaScript ------
(function() {
// Start Global Code
var x="X";
switch (x)
{
case "X":
Console.WriteLine("X");
break;
case "Y":
Console.WriteLine("Y");
break;
}
})();
------ Actual Output ------
X
Test passed!
------ Prefix ------
extern dynamic Console;
class Foo
{
public void Dispose()
{
Console.WriteLine("Foo.Dispose");
}
}
using (var x = new Foo())
{
Console.WriteLine("In using clause");
}
------ Expected Output ------
In using clause
Foo.Dispose
------ Generated JavaScript ------
(function() {
// class Foo
var Foo = function() {};
Foo.typeName = 'Foo';
Foo.prototype.Dispose = function()
{
Console.WriteLine("Foo.Dispose");
};
// Start Global Code
var $temp;
var x;
$temp = x = (new Foo());
try
{
Console.WriteLine("In using clause");
}
finally
{
$temp.Dispose();
}
})();
------ Actual Output ------
In using clause
Foo.Dispose
Test passed!
------ Prefix ------
extern dynamic Console;
class Foo
{
}
using (var x = new Foo())
{
Console.WriteLine("In using clause");
}
------ Expected Output ------
// exception: does not contain a definition for 'Dispose'
------ Actual Exception ------
Tests.Statements.using_expression_must_have_dispose_method.txt(7,1): instance of class 'Foo' does not contain a definition for 'Dispose'
Test passed!
------ Prefix ------
extern dynamic Console;
while (true)
{
Console.WriteLine("true");
break;
}
------ Expected Output ------
true
------ Generated JavaScript ------
(function() {
// Start Global Code
while (true){
Console.WriteLine("true");
break;
}
})();
------ Actual Output ------
true
Test passed!
------ Prefix ------
extern dynamic Console;
while ("This is not a boolean")
{
Console.WriteLine("true");
}
------ Expected Output ------
// exception: cannot implicitly convert class 'System.String' to class 'System.Boolean'
------ Actual Exception ------
Tests.Statements.while_expects_boolean_expression.txt(2,8): cannot implicitly convert class 'System.String' to class 'System.Boolean'
Test passed!
------ Prefix ------
extern dynamic Console;
class MyClass
{
public static string GetMessage()
{
return "OK";
}
}
class Derived : MyClass
{
public static string GetMessage()
{
return "OK";
}
}
Console.WriteLine(MyClass.GetMessage());
------ Expected Output ------
// exception: cannot override
------ Actual Exception ------
Tests.Static.cant_override_static_functions.txt(13,16): function 'Derived.GetMessage()' cannot override function 'MyClass.GetMessage()' because it is declared static
Test passed!
------ Prefix ------
extern dynamic Console;
class MyClass
{
public static string MessageFunction()
{
return "OK (Function)";
}
public static string MessageProperty
{
get
{
return "OK (Property)";
}
}
public static string MessageVariable = "OK (Variable)";
}
Console.WriteLine(MyClass.MessageFunction());
Console.WriteLine(MyClass.MessageProperty);
Console.WriteLine(MyClass.MessageVariable);
------ Expected Output ------
OK (Function)
OK (Property)
OK (Variable)
------ Generated JavaScript ------
(function() {
// class MyClass
var MyClass = function() {};
MyClass.typeName = 'MyClass';
MyClass.MessageVariable = "OK (Variable)";
MyClass.MessageFunction = function()
{
return "OK (Function)";
};
MyClass.get_MessageProperty = function()
{
return "OK (Property)";
};
// Start Global Code
Console.WriteLine(MyClass.MessageFunction());
Console.WriteLine(MyClass.get_MessageProperty());
Console.WriteLine(MyClass.MessageVariable);
})();
------ Actual Output ------
OK (Function)
OK (Property)
OK (Variable)
Test passed!
------ Prefix ------
extern dynamic Console;
class MyClass
{
public static int Val
{
get;
set;
}
}
MyClass.Val = 10;
Console.WriteLine((MyClass.Val++).toString());
Console.WriteLine((MyClass.Val--).toString());
------ Expected Output ------
10
11
------ Generated JavaScript ------
(function() {
// class MyClass
var MyClass = function() {};
MyClass.typeName = 'MyClass';
MyClass.Val = 0;
MyClass.get_Val = function()
{
return this.Val;
};
MyClass.set_Val = function(value)
{
this.Val = value;
return value;
};
// Start Global Code
MyClass.Val = 10;
Console.WriteLine((MyClass.Val++).toString());
Console.WriteLine((MyClass.Val--).toString());
})();
------ Actual Output ------
10
11
Test passed!
------ Prefix ------
extern dynamic Console;
class MyClass
{
public static int Val = 10;
}
Console.WriteLine((MyClass.Val++).toString());
Console.WriteLine((MyClass.Val--).toString());
------ Expected Output ------
10
11
------ Generated JavaScript ------
(function() {
// class MyClass
var MyClass = function() {};
MyClass.typeName = 'MyClass';
MyClass.Val = 10;
// Start Global Code
Console.WriteLine((MyClass.Val++).toString());
Console.WriteLine((MyClass.Val--).toString());
})();
------ Actual Output ------
10
11
Test passed!
------ Prefix ------
extern dynamic Console;
class MyClass
{
public string GetMessage()
{
return GetMessage2();
}
public static string GetMessage2()
{
return "OK";
}
}
Console.WriteLine(new MyClass().GetMessage());
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// class MyClass
var MyClass = function() {};
MyClass.typeName = 'MyClass';
MyClass.prototype.GetMessage = function()
{
return MyClass.GetMessage2();
};
MyClass.GetMessage2 = function()
{
return "OK";
};
// Start Global Code
Console.WriteLine((new MyClass()).GetMessage());
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
extern dynamic Console;
class MyClass
{
public string GetMessage()
{
return this.GetMessage2();
}
public static string GetMessage2()
{
return "OK";
}
}
------ Expected Output ------
// exception: cannot be accessed with an instance reference;
------ Actual Exception ------
Tests.Static.instance_calling_static_via_this.txt(7,10): function 'MyClass.GetMessage2()' cannot be accessed with an instance reference; qualify it with a type name instead
Test passed!
------ Prefix ------
extern dynamic Console;
class MyClass
{
public static string GetMessage()
{
return "OK";
}
}
Console.WriteLine(MyClass.GetMessage());
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// class MyClass
var MyClass = function() {};
MyClass.typeName = 'MyClass';
MyClass.GetMessage = function()
{
return "OK";
};
// Start Global Code
Console.WriteLine(MyClass.GetMessage());
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
extern dynamic Console;
class MyClass
{
public static string Message
{
get;
set;
}
}
MyClass.Message = "OK";
Console.WriteLine(MyClass.Message);
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// class MyClass
var MyClass = function() {};
MyClass.typeName = 'MyClass';
MyClass.Message = null;
MyClass.get_Message = function()
{
return this.Message;
};
MyClass.set_Message = function(value)
{
this.Message = value;
return value;
};
// Start Global Code
MyClass.Message = "OK";
Console.WriteLine(MyClass.Message);
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
extern dynamic Console;
class MyClass
{
public static string Message = "OK";
}
Console.WriteLine(MyClass.Message);
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// class MyClass
var MyClass = function() {};
MyClass.typeName = 'MyClass';
MyClass.Message = "OK";
// Start Global Code
Console.WriteLine(MyClass.Message);
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
extern dynamic Console;
class MyClass
{
public static string GetMessage()
{
return GetMessage2();
}
public static string GetMessage2()
{
return "OK";
}
}
Console.WriteLine(MyClass.GetMessage());
------ Expected Output ------
OK
------ Generated JavaScript ------
(function() {
// class MyClass
var MyClass = function() {};
MyClass.typeName = 'MyClass';
MyClass.GetMessage = function()
{
return MyClass.GetMessage2();
};
MyClass.GetMessage2 = function()
{
return "OK";
};
// Start Global Code
Console.WriteLine(MyClass.GetMessage());
})();
------ Actual Output ------
OK
Test passed!
------ Prefix ------
extern dynamic Console;
class MyClass
{
public string GetMessage()
{
return "OK";
}
public static string GetMessage2()
{
return GetMessage();
}
}
Console.WriteLine(MyClass.GetMessage2());
------ Expected Output ------
// exception: An object reference is required
------ Actual Exception ------
Tests.Static.static_cant_call_instance.txt(11,10): An object reference is required for non-static field, property or method function 'MyClass.GetMessage()'
Test passed!
------ Prefix ------
static class MyClass
{
public void fn()
{
}
}
------ Expected Output ------
// exception: cannot declare instance members in a static class
------ Actual Exception ------
Tests.Static.static_class_cant_have_instance_function.txt(3,9): function 'MyClass.fn()': cannot declare instance members in a static class
Test passed!
------ Prefix ------
static class MyClass
{
public string prop
{
get;
set;
}
}
------ Expected Output ------
// exception: cannot declare instance members in a static class
------ Actual Exception ------
Tests.Static.static_class_cant_have_instance_property.txt(5,3): function 'MyClass.prop.get()': cannot declare instance members in a static class
Test passed!
------ Prefix ------
static class MyClass
{
public string prop;
}
------ Expected Output ------
// exception: cannot declare instance members in a static class
------ Actual Exception ------
Tests.Static.static_class_cant_have_instance_variable.txt(3,9): MemberVariable prop: cannot declare instance members in a static class
Test passed!
------ Prefix ------
extern dynamic Console;
class Bar
{
}
class MyClass<T>
{
public void fn()
{
Console.WriteLine(typename(T));
}
}
new MyClass<bool>().fn();
new MyClass<int>().fn();
new MyClass<Bar>().fn();
new MyClass<MyClass<int>>().fn();
Console.WriteLine(typename(MyClass<int>));
------ Expected Output ------
boolean
number
Bar
MyClass<>[number]
MyClass<>[number]
------ Generated JavaScript ------
(function() {
// Prefix runtime library
var $dex = {};
$dex.makeCachedGeneric=function(a,b,c){var d=[];for(var e=0;e<b.length;e++)d.push(b[e]instanceof Function?b[e].typeName:b[e]);f=d.join(',');if(!a.closed)a.closed={};var g=a.closed[f];if(!g){g=c(f);a.closed[f]=g};return g}
$dex.resolveGenericArg=function(a,b){if(typeof(a)=='number')return b?b[a]:a;return a}
$dex.resolveGenericArgs=function(a,b){for(var c=0,d=[];c<a.length;c++)d.push($dex.resolveGenericArg(a[c],b));return d}
$dex.setupGenericClass=function(a,b,c,d){d.makeGeneric=function(e){return $dex.makeCachedGeneric(d,e,function(f){var g=function(){d.apply(this,arguments)};if(b==null){g.prototype=new d()}else{var h=$dex.resolveGenericArgs(c,e);g.prototype=new(b.makeGeneric(h))();for(var i in d.prototype)g.prototype[i]=d.prototype[i]}for(var s in d.static)g[s]=d.static[s];g.typeName=d.typeName+"["+f+"]";g.prototype.constructor=g;g.prototype['closedClass$'+a.toString()]=g;g.genericArgs=e;var j=d.prototype.$interfaces,k=j;if(j){for(var i=0,len=j.length;i<len;i++){if(typeof(j[i]instanceof Array)){if(k===j)k=j.slice(0);k[i]=j[i][0].makeGeneric($dex.resolveGenericArgs(j[i][1],e))}}g.prototype.$interfaces=k}if(g.$cctor)g.$cctor();return g})};return d}
$dex.typeName=function(a){return a===null?null:(a.typeName?a.typeName:a)}
// class Bar
var Bar = function() {};
Bar.typeName = 'Bar';
// class MyClass<>
var MyClass$1 = $dex.setupGenericClass(1, null, null, function() {});
MyClass$1.typeName = 'MyClass<>';
MyClass$1.prototype.fn = function()
{
var T = this.closedClass$1.genericArgs[0];
Console.WriteLine($dex.typeName(T));
};
// Start Global Code
(new (MyClass$1.makeGeneric(['boolean']))()).fn();
(new (MyClass$1.makeGeneric(['number']))()).fn();
(new (MyClass$1.makeGeneric([Bar]))()).fn();
(new (MyClass$1.makeGeneric([MyClass$1.makeGeneric(['number'])]))()).fn();
Console.WriteLine("MyClass<>[number]");
})();
------ Actual Output ------
boolean
number
Bar
MyClass<>[number]
MyClass<>[number]
Test passed!
------ Prefix ------
extern dynamic Console;
class MyClass<T>
{
}
Console.WriteLine(typename("Hello"));
Console.WriteLine(typename(23.2));
Console.WriteLine(typename(23));
Console.WriteLine(typename(true));
Console.WriteLine(typename(new MyClass<int>()));
Console.WriteLine(typename(new MyClass<string>()));
Console.WriteLine(typename(new MyClass<MyClass<string>>()));
------ Expected Output ------
string
number
number
boolean
MyClass<>[number]
MyClass<>[string]
MyClass<>[MyClass<>[string]]
------ Generated JavaScript ------
(function() {
// Prefix runtime library
var $dex = {};
$dex.makeCachedGeneric=function(a,b,c){var d=[];for(var e=0;e<b.length;e++)d.push(b[e]instanceof Function?b[e].typeName:b[e]);f=d.join(',');if(!a.closed)a.closed={};var g=a.closed[f];if(!g){g=c(f);a.closed[f]=g};return g}
$dex.resolveGenericArg=function(a,b){if(typeof(a)=='number')return b?b[a]:a;return a}
$dex.resolveGenericArgs=function(a,b){for(var c=0,d=[];c<a.length;c++)d.push($dex.resolveGenericArg(a[c],b));return d}
$dex.setupGenericClass=function(a,b,c,d){d.makeGeneric=function(e){return $dex.makeCachedGeneric(d,e,function(f){var g=function(){d.apply(this,arguments)};if(b==null){g.prototype=new d()}else{var h=$dex.resolveGenericArgs(c,e);g.prototype=new(b.makeGeneric(h))();for(var i in d.prototype)g.prototype[i]=d.prototype[i]}for(var s in d.static)g[s]=d.static[s];g.typeName=d.typeName+"["+f+"]";g.prototype.constructor=g;g.prototype['closedClass$'+a.toString()]=g;g.genericArgs=e;var j=d.prototype.$interfaces,k=j;if(j){for(var i=0,len=j.length;i<len;i++){if(typeof(j[i]instanceof Array)){if(k===j)k=j.slice(0);k[i]=j[i][0].makeGeneric($dex.resolveGenericArgs(j[i][1],e))}}g.prototype.$interfaces=k}if(g.$cctor)g.$cctor();return g})};return d}
$dex.typeNameOfInstance=function(a){return a===null?null:((a.constructor&&a.constructor.typeName)?a.constructor.typeName:(typeof a))}
// class MyClass<>
var MyClass$1 = $dex.setupGenericClass(1, null, null, function() {});
MyClass$1.typeName = 'MyClass<>';
// Start Global Code
Console.WriteLine("string");
Console.WriteLine("number");
Console.WriteLine("number");
Console.WriteLine("boolean");
Console.WriteLine($dex.typeNameOfInstance(new (MyClass$1.makeGeneric(['number']))()));
Console.WriteLine($dex.typeNameOfInstance(new (MyClass$1.makeGeneric(['string']))()));
Console.WriteLine($dex.typeNameOfInstance(new (MyClass$1.makeGeneric([MyClass$1.makeGeneric(['string'])]))()));
})();
------ Actual Output ------
string
number
number
boolean
MyClass<>[number]
MyClass<>[string]
MyClass<>[MyClass<>[string]]
Test passed!
------ Prefix ------
extern dynamic Console;
class MyClass<T>
{
public class Bar
{
public void fn()
{
Console.WriteLine(typename(this));
}
}
public class Foo<U>
{
public void fn()
{
Console.WriteLine(typename(this));
}
public void fn2()
{
Console.WriteLine(default(T));
Console.WriteLine(default(U));
}
}
}
new MyClass<bool>.Bar().fn();
new MyClass<bool>.Foo<string>().fn();
new MyClass<bool>.Foo<int>().fn2();
------ Expected Output ------
MyClass<>.Bar[boolean]
MyClass<>.Foo<>[boolean,string]
False
0
------ Generated JavaScript ------
(function() {
// Prefix runtime library
var $dex = {};
$dex.getDefaultValue=function(a){switch(a){case'number':return 0;case'boolean':return false}return null}
$dex.makeCachedGeneric=function(a,b,c){var d=[];for(var e=0;e<b.length;e++)d.push(b[e]instanceof Function?b[e].typeName:b[e]);f=d.join(',');if(!a.closed)a.closed={};var g=a.closed[f];if(!g){g=c(f);a.closed[f]=g};return g}
$dex.resolveGenericArg=function(a,b){if(typeof(a)=='number')return b?b[a]:a;return a}
$dex.resolveGenericArgs=function(a,b){for(var c=0,d=[];c<a.length;c++)d.push($dex.resolveGenericArg(a[c],b));return d}
$dex.setupGenericClass=function(a,b,c,d){d.makeGeneric=function(e){return $dex.makeCachedGeneric(d,e,function(f){var g=function(){d.apply(this,arguments)};if(b==null){g.prototype=new d()}else{var h=$dex.resolveGenericArgs(c,e);g.prototype=new(b.makeGeneric(h))();for(var i in d.prototype)g.prototype[i]=d.prototype[i]}for(var s in d.static)g[s]=d.static[s];g.typeName=d.typeName+"["+f+"]";g.prototype.constructor=g;g.prototype['closedClass$'+a.toString()]=g;g.genericArgs=e;var j=d.prototype.$interfaces,k=j;if(j){for(var i=0,len=j.length;i<len;i++){if(typeof(j[i]instanceof Array)){if(k===j)k=j.slice(0);k[i]=j[i][0].makeGeneric($dex.resolveGenericArgs(j[i][1],e))}}g.prototype.$interfaces=k}if(g.$cctor)g.$cctor();return g})};return d}
$dex.typeNameOfInstance=function(a){return a===null?null:((a.constructor&&a.constructor.typeName)?a.constructor.typeName:(typeof a))}
// class MyClass<>
var MyClass$1 = $dex.setupGenericClass(1, null, null, function() {});
MyClass$1.typeName = 'MyClass<>';
// class MyClass<>.Bar<>
MyClass$1.Bar$0 = $dex.setupGenericClass(1, null, null, function() {});
MyClass$1.Bar$0.typeName = 'MyClass<>.Bar';
MyClass$1.Bar$0.prototype.fn = function()
{
Console.WriteLine($dex.typeNameOfInstance(this));
};
// class MyClass<>.Foo<>
MyClass$1.Foo$1 = $dex.setupGenericClass(1, null, null, function() {});
MyClass$1.Foo$1.typeName = 'MyClass<>.Foo<>';
MyClass$1.Foo$1.prototype.fn = function()
{
Console.WriteLine($dex.typeNameOfInstance(this));
};
MyClass$1.Foo$1.prototype.fn2 = function()
{
var T = this.closedClass$1.genericArgs[0];
var U = this.closedClass$1.genericArgs[1];
Console.WriteLine($dex.getDefaultValue(T));
Console.WriteLine($dex.getDefaultValue(U));
};
// Start Global Code
(new (MyClass$1.Bar$0.makeGeneric(['boolean']))()).fn();
(new (MyClass$1.Foo$1.makeGeneric(['boolean', 'string']))()).fn();
(new (MyClass$1.Foo$1.makeGeneric(['boolean', 'number']))()).fn2();
})();
------ Actual Output ------
MyClass<>.Bar[boolean]
MyClass<>.Foo<>[boolean,string]
False
0
Test passed!
------ Prefix ------
extern dynamic Console;
class MyClass<T>
{
}
Console.WriteLine(typename(string));
Console.WriteLine(typename(double));
Console.WriteLine(typename(int));
Console.WriteLine(typename(bool));
Console.WriteLine(typename(dynamic));
Console.WriteLine(typename(object));
Console.WriteLine(typename(MyClass<>));
Console.WriteLine(typename(MyClass<int>));
Console.WriteLine(typename(MyClass<MyClass<string>>));
Console.WriteLine(typename(int[]));
------ Expected Output ------
string
number
number
boolean
object
object
MyClass<>
MyClass<>[number]
MyClass<>[MyClass<>[string]]
array<>[number]
------ Generated JavaScript ------
(function() {
// class MyClass<>
var MyClass$1 = function() {};
MyClass$1.typeName = 'MyClass<>';
// Start Global Code
Console.WriteLine("string");
Console.WriteLine("number");
Console.WriteLine("number");
Console.WriteLine("boolean");
Console.WriteLine("object");
Console.WriteLine("object");
Console.WriteLine("MyClass<>");
Console.WriteLine("MyClass<>[number]");
Console.WriteLine("MyClass<>[MyClass<>[string]]");
Console.WriteLine("array<>[number]");
})();
------ Actual Output ------
string
number
number
boolean
object
object
MyClass<>
MyClass<>[number]
MyClass<>[MyClass<>[string]]
array<>[number]
Test passed!
------ Prefix ------
extern dynamic Console;
class MyClass
{
}
class Foo<T>
{
}
Console.WriteLine(typeof("")==typeof(string));
dynamic d = "";
Console.WriteLine(typeof(d)==typeof(string));
Console.WriteLine(typeof(new MyClass()) == typeof(MyClass));
Console.WriteLine(typeof(new Foo<int>()) == typeof(Foo<int>));
Console.WriteLine(typeof(new Foo<int>()) == typeof(Foo<string>));
------ Expected Output ------
True
True
True
True
False
------ Generated JavaScript ------
(function() {
// Prefix runtime library
var $dex = {};
$dex.makeCachedGeneric=function(a,b,c){var d=[];for(var e=0;e<b.length;e++)d.push(b[e]instanceof Function?b[e].typeName:b[e]);f=d.join(',');if(!a.closed)a.closed={};var g=a.closed[f];if(!g){g=c(f);a.closed[f]=g};return g}
$dex.resolveGenericArg=function(a,b){if(typeof(a)=='number')return b?b[a]:a;return a}
$dex.resolveGenericArgs=function(a,b){for(var c=0,d=[];c<a.length;c++)d.push($dex.resolveGenericArg(a[c],b));return d}
$dex.setupGenericClass=function(a,b,c,d){d.makeGeneric=function(e){return $dex.makeCachedGeneric(d,e,function(f){var g=function(){d.apply(this,arguments)};if(b==null){g.prototype=new d()}else{var h=$dex.resolveGenericArgs(c,e);g.prototype=new(b.makeGeneric(h))();for(var i in d.prototype)g.prototype[i]=d.prototype[i]}for(var s in d.static)g[s]=d.static[s];g.typeName=d.typeName+"["+f+"]";g.prototype.constructor=g;g.prototype['closedClass$'+a.toString()]=g;g.genericArgs=e;var j=d.prototype.$interfaces,k=j;if(j){for(var i=0,len=j.length;i<len;i++){if(typeof(j[i]instanceof Array)){if(k===j)k=j.slice(0);k[i]=j[i][0].makeGeneric($dex.resolveGenericArgs(j[i][1],e))}}g.prototype.$interfaces=k}if(g.$cctor)g.$cctor();return g})};return d}
$dex.typeOf=function(a){return a===null?null:a.constructor}
// class MyClass
var MyClass = function() {};
MyClass.typeName = 'MyClass';
// class Foo<>
var Foo$1 = $dex.setupGenericClass(1, null, null, function() {});
Foo$1.typeName = 'Foo<>';
// Start Global Code
Console.WriteLine(String===String);
var d="";
Console.WriteLine($dex.typeOf(d)===String);
Console.WriteLine($dex.typeOf(new MyClass())===MyClass);
Console.WriteLine($dex.typeOf(new (Foo$1.makeGeneric(['number']))())===(Foo$1.makeGeneric(['number'])));
Console.WriteLine($dex.typeOf(new (Foo$1.makeGeneric(['number']))())===(Foo$1.makeGeneric(['string'])));
})();
------ Actual Output ------
True
True
True
True
False
Test passed!
------ Prefix ------
extern dynamic Console;
class Foo
{
public Foo(int first, params int[] other)
{
Console.WriteLine(first);
for (int i=0; i<other.length; i++)
{
Console.WriteLine(other[i]);
}
}
}
new Foo(1,2,3,4);
------ Expected Output ------
1
2
3
4
------ Generated JavaScript ------
(function() {
// class Foo
var Foo = function() {};
Foo.typeName = 'Foo';
Foo.prototype.ctor$1 = function(first, other)
{
other = Array.prototype.slice.call(arguments, 1);
Console.WriteLine(first);
for (var i=0; i<other.length; i++)
{
Console.WriteLine(other[i]);
}
return this;
};
// Start Global Code
(new Foo().ctor$1(1, 2, 3, 4));
})();
------ Actual Output ------
1
2
3
4
Test passed!
------ Prefix ------
extern dynamic Console;
class Foo
{
public Foo(int first, params int[] other)
{
Console.WriteLine(first);
for (int i=0; i<other.length; i++)
{
Console.WriteLine(other[i]);
}
}
}
new Foo(1);
------ Expected Output ------
1
------ Generated JavaScript ------
(function() {
// class Foo
var Foo = function() {};
Foo.typeName = 'Foo';
Foo.prototype.ctor$1 = function(first, other)
{
other = Array.prototype.slice.call(arguments, 1);
Console.WriteLine(first);
for (var i=0; i<other.length; i++)
{
Console.WriteLine(other[i]);
}
return this;
};
// Start Global Code
(new Foo().ctor$1(1));
})();
------ Actual Output ------
1
Test passed!
------ Prefix ------
extern dynamic Console;
class Foo
{
public Foo(int first, params int[] other)
{
Console.WriteLine(first);
for (int i=0; i<other.length; i++)
{
Console.WriteLine(other[i]);
}
}
}
var vals = (int[])`[2,3,4]`;
new Foo(1,vals);
------ Expected Output ------
1
2
3
4
------ Generated JavaScript ------
(function() {
// class Foo
var Foo = function() {};
Foo.typeName = 'Foo';
Foo.prototype.ctor$1 = function(first, other)
{
if (!(other instanceof Array)) other = Array.prototype.slice.call(arguments, 1);
Console.WriteLine(first);
for (var i=0; i<other.length; i++)
{
Console.WriteLine(other[i]);
}
return this;
};
// Start Global Code
var vals=[2,3,4];
(new Foo().ctor$1(1, vals));
})();
------ Actual Output ------
1
2
3
4
Test passed!
------ Prefix ------
class Foo
{
public Foo(int first, params int[][] other)
{
return 0;
}
}
int[][] vals = null;
new Foo(1,vals);
------ Expected Output ------
// exception: array of arrays in non-expanded form is not supported
------ Actual Exception ------
Tests.VariadicParameters.ctor_normal_form_arrays_not_supported.txt(11,1): function 'Foo..ctor(System.Integer,System.Array<array<>[number]>)': calling of a variadic function accepting an array of arrays in non-expanded form is not supported
Test passed!
------ Prefix ------
extern dynamic Console;
int sum(int first, params int[] other)
{
for (int i=0; i<other.length; i++)
{
first += other[i];
}
return first;
}
Console.WriteLine(sum(1,2,3,4));
------ Expected Output ------
10
------ Generated JavaScript ------
(function() {
function sum(first, other)
{
other = Array.prototype.slice.call(arguments, 1);
for (var i=0; i<other.length; i++)
{
first += other[i];
}
return first;
};
// Start Global Code
Console.WriteLine(sum(1, 2, 3, 4));
})();
------ Actual Output ------
10
Test passed!
------ Prefix ------
extern dynamic Console;
int sum(int first, params int[] other)
{
for (int i=0; i<other.length; i++)
{
first += other[i];
}
return first;
}
Console.WriteLine(sum(1));
------ Expected Output ------
1
------ Generated JavaScript ------
(function() {
function sum(first, other)
{
other = Array.prototype.slice.call(arguments, 1);
for (var i=0; i<other.length; i++)
{
first += other[i];
}
return first;
};
// Start Global Code
Console.WriteLine(sum(1));
})();
------ Actual Output ------
1
Test passed!
------ Prefix ------
extern dynamic Console;
int sum(int first, params int[] other)
{
for (int i=0; i<other.length; i++)
{
first += other[i];
}
return first;
}
var vals = (int[])`[2,3,4]`;
Console.WriteLine(sum(1,vals));
------ Expected Output ------
10
------ Generated JavaScript ------
(function() {
function sum(first, other)
{
if (!(other instanceof Array)) other = Array.prototype.slice.call(arguments, 1);
for (var i=0; i<other.length; i++)
{
first += other[i];
}
return first;
};
// Start Global Code
var vals=[2,3,4];
Console.WriteLine(sum(1, vals));
})();
------ Actual Output ------
10
Test passed!
------ Prefix ------
extern dynamic Console;
int fn(int first, params int[][] other)
{
return 0;
}
int[][] vals = null;
Console.WriteLine(fn(1,vals));
------ Expected Output ------
// exception: array of arrays in non-expanded form is not supported
------ Actual Exception ------
Tests.VariadicParameters.fn_normal_form_arrays_not_supported.txt(10,19): function 'fn(System.Integer,System.Array<array<>[number]>)': calling of a variadic function accepting an array of arrays in non-expanded form is not supported
Test passed!
------ Prefix ------
extern dynamic Console;
int sum(int first, params int[] other)
{
for (int i=0; i<other.length; i++)
{
first += other[i];
}
return first;
}
int sum(int first, int second, params int[] other)
{
for (int i=0; i<other.length; i++)
{
first += other[i];
}
return first + second;
}
Console.WriteLine(sum(1,2,3));
------ Expected Output ------
6
------ Generated JavaScript ------
(function() {
function sum$1(first, other)
{
other = Array.prototype.slice.call(arguments, 1);
for (var i=0; i<other.length; i++)
{
first += other[i];
}
return first;
};
function sum$2(first, second, other)
{
other = Array.prototype.slice.call(arguments, 2);
for (var i=0; i<other.length; i++)
{
first += other[i];
}
return first + second;
};
// Start Global Code
Console.WriteLine(sum$2(1, 2, 3));
})();
------ Actual Output ------
6
Test passed!
------ Prefix ------
void fn(params int x)
{
}
------ Expected Output ------
// exception: must be a single dimension array
------ Actual Exception ------
Tests.VariadicParameters.must_be_an_array.txt(1,20): 'fn': the parameter array must be a single dimension array
Test passed!
------ Prefix ------
void fn(params int[] x, int y)
{
}
------ Expected Output ------
// exception: must be the last parameter
------ Actual Exception ------
Tests.VariadicParameters.must_be_last_parameter.txt(1,22): 'fn': the parameter array must be the last parameter
Test passed!
------ Prefix ------
extern dynamic Console;
class Foo
{
public string this[params int[] other]
{
get
{
return "OK";
}
}
}
new Foo()[1,2,3,4];
------ Expected Output ------
// exception: parameter arrays are not supported on indexer
------ Actual Exception ------
Tests.VariadicParameters.variadic_indexer_not_supported.txt(5,34): 'Foo.indexer[]': parameter arrays are not supported on indexers
Test passed!
Test passed!
Test passed!
Test passed!
Test passed!
Test passed!
Test passed!
Test passed!
Test passed!
Test passed!
Test passed!
Test passed!
Test passed!