ソースを参照

more parseInt/parseFloat tests

Nicolas Cannasse 15 年 前
コミット
d96a524a61
2 ファイル変更15 行追加1 行削除
  1. 1 1
      tests/unit/Test.hx
  2. 14 0
      tests/unit/TestBasetypes.hx

+ 1 - 1
tests/unit/Test.hx

@@ -7,7 +7,7 @@ class Test #if swf_mark implements mt.Protect #end #if as3 implements haxe.Publi
 
 	function eq<T>( v : T, v2 : T, ?pos ) {
 		count++;
-		if( v != v2 ) report(v+" should be "+v2,pos);
+		if( v != v2 ) report(Std.string(v)+" should be "+Std.string(v2),pos);
 	}
 
 	function feq( v : Float, v2 : Float, ?pos ) {

+ 14 - 0
tests/unit/TestBasetypes.hx

@@ -89,13 +89,27 @@ class TestBasetypes extends Test {
 
 	function testParse() {
 		eq( Std.parseInt("0"), 0 );
+		eq( Std.parseInt("   5"), 5 );
 		eq( Std.parseInt("0001"), 1 );
 		eq( Std.parseInt("100"), 100 );
 		eq( Std.parseInt("-100"), -100 );
 		eq( Std.parseInt("100x123"), 100 );
 		eq( Std.parseInt(""), null );
 		eq( Std.parseInt("abcd"), null );
+		eq( Std.parseInt("a10"), null );
 		eq( Std.parseInt(null), null );
+
+		eq( Std.parseFloat("0"), 0. );
+		eq( Std.parseFloat("   5.3"), 5.3 );
+		eq( Std.parseFloat("0001"), 1. );
+		eq( Std.parseFloat("100.45"), 100.45 );
+		eq( Std.parseFloat("-100.01"), -100.01 );
+		eq( Std.parseFloat("100x123"), 100. );
+		t( Math.isNaN(Std.parseFloat("")) );
+		t( Math.isNaN(Std.parseFloat("abcd")) );
+		t( Math.isNaN(Std.parseFloat("a10")) );
+		t( Math.isNaN(Std.parseFloat(null)) );
+
 	}
 
 	function testStringTools() {