Browse Source

added TestMisc

Nicolas Cannasse 17 years ago
parent
commit
b6f0858491
5 changed files with 55 additions and 1 deletions
  1. 4 0
      tests/unit/MyClass.hx
  2. 1 0
      tests/unit/Test.hx
  3. 48 0
      tests/unit/TestMisc.hx
  4. 1 1
      tests/unit/TestRemoting.hx
  5. 1 0
      tests/unit/unit.hxp

+ 4 - 0
tests/unit/MyClass.hx

@@ -20,4 +20,8 @@ class MyClass {
 		val = v;
 	}
 
+	public function add(x,y) {
+		return val + x + y;
+	}
+
 }

+ 1 - 0
tests/unit/Test.hx

@@ -164,6 +164,7 @@ class Test #if swf_mark implements mt.Protect #end {
 			new TestIO(),
 			new TestSerialize(),
 			new TestRemoting(),
+			new TestMisc(),
 		];
 		var current = null;
 		try {

+ 48 - 0
tests/unit/TestMisc.hx

@@ -0,0 +1,48 @@
+package unit;
+
+class TestMisc extends Test {
+
+	public function testString() {
+		eq( String.fromCharCode(77), "M" );
+		unspec(function() String.fromCharCode(0));
+		unspec(function() String.fromCharCode(-1));
+		unspec(function() String.fromCharCode(256));
+	}
+
+	public function testClosure() {
+		var c = new MyClass(100);
+		var add = c.add;
+		eq( c.add(1,2), 103 );
+		eq( callback(c.add,1)(2), 103 );
+		eq( add(1,2), 103 );
+
+		var x = 4;
+		var f = function() return x;
+		eq( f(), 4 );
+		x++;
+		eq( f(), 5 );
+	}
+
+	public function testBlockVars() {
+		var a = new Array();
+		for( i in 0...10 )
+			a.push(function() return i);
+		for( i in 0...10 )
+			eq( a[i](), i );
+	}
+
+	public function testScopeVar() {
+		var x = 4;
+		{
+			var x = "hello";
+			eq(x,"hello");
+			switch( MyEnum.C(66,"") ) {
+			case C(x,_):
+				eq(x,66);
+			default:
+			}
+		}
+		eq(x,4);
+	}
+
+}

+ 1 - 1
tests/unit/TestRemoting.hx

@@ -26,7 +26,7 @@ class TestRemoting extends Test {
 		ecnx = haxe.remoting.ExternalConnection.jsConnect("cnx",ctx);
 		ecnx3 = haxe.remoting.ExternalConnection.jsConnect("unknown",ctx);
 		lcnx = haxe.remoting.LocalConnection.connect("local",ctx,[HOST]);
-		fjscnx = haxe.remoting.FlashJsConnection.connect(#if flash9 "haxeFlash8" #else "haxeFlash9" #end,"cnx",ctx);
+		fjscnx = haxe.remoting.FlashJsConnection.connect("cnx",#if flash9 "haxeFlash8" #else "haxeFlash9" #end,ctx);
 		#elseif js
 		ecnx = haxe.remoting.ExternalConnection.flashConnect("cnx","haxeFlash8",ctx);
 		ecnx2 = haxe.remoting.ExternalConnection.flashConnect("cnx","haxeFlash9",ctx);

+ 1 - 0
tests/unit/unit.hxp

@@ -14,6 +14,7 @@
     <file path="TestBytes.hx" />
     <file path="TestInt32.hx" />
     <file path="TestIO.hx" />
+    <file path="TestMisc.hx" />
     <file path="TestReflect.hx" />
     <file path="TestRemoting.hx" />
     <file path="TestSerialize.hx" />