瀏覽代碼

TESTS: Add tests for length property in IO classes

Mike Welsh 12 年之前
父節點
當前提交
60d7d691c9
共有 3 個文件被更改,包括 12 次插入3 次删除
  1. 2 0
      tests/unit/TestBytes.hx
  2. 8 3
      tests/unit/TestIO.hx
  3. 2 0
      tests/unit/TestMisc.hx

+ 2 - 0
tests/unit/TestBytes.hx

@@ -100,10 +100,12 @@ class TestBytes extends Test {
 
 	function testBuffer() {
 		var out = new haxe.io.BytesBuffer();
+		eq( out.length, 0 );
 		out.add( haxe.io.Bytes.ofString("ABCDEF") );
 		for( i in 1...6 )
 			out.addByte(i);
 		out.addBytes( haxe.io.Bytes.ofString("ABCDEF"),1,3 );
+		eq( out.length, 14 );
 		var b = out.getBytes();
 		var str = "ABCDEF\x01\x02\x03\x04\x05BCD";
 		eq( b.length, str.length );

+ 8 - 3
tests/unit/TestIO.hx

@@ -25,6 +25,7 @@ class TestIO extends Test {
 		b.set(1,0);
 
 		var o = new haxe.io.BytesOutput();
+		eq(o.length, 0);
 
 		o.bigEndian = endian;
 		eq(o.bigEndian,endian);
@@ -34,6 +35,7 @@ class TestIO extends Test {
 		o.writeByte(0x01);
 		o.writeByte(0x02);
 		o.writeByte(0x03);
+		eq(o.length, 4);
 
 		o.write(b);
 		o.writeByte(55);
@@ -56,6 +58,8 @@ class TestIO extends Test {
 		var str = "Héllo World !";
 		o.writeString(str);
 
+		eq(o.length, 86);
+
 		o.writeInt16(-12345);
 		excv(function() o.writeInt16(1 << 15),Overflow);
 		excv(function() o.writeInt16(-((1 << 15)+1)),Overflow);
@@ -78,11 +82,11 @@ class TestIO extends Test {
 		o.writeInt32(0xA0FFEEDD);
 		o.writeInt32(0xC0FFEEDD);
 
-		unspec(function() o.writeByte(-1));
-		unspec(function() o.writeByte(257));
-
 		var i = new haxe.io.BytesInput(o.getBytes());
 		i.bigEndian = endian;
+		eq( i.position, 0 );
+		eq( i.length, 113 );
+
 		eq( i.readInt32(), endian ? 0x00010203 : 0x03020100 );
 		eq( i.read(b.length).compare(b) , 0 );
 		eq( i.readByte(), 55 );
@@ -112,6 +116,7 @@ class TestIO extends Test {
 		eq( i.readInt32() , 0xA0FFEEDD );
 		eq( i.readInt32() , 0xC0FFEEDD );
 
+		eq( i.position, i.length );
 	}
 
 	function testBytesBounds() {

+ 2 - 0
tests/unit/TestMisc.hx

@@ -497,6 +497,7 @@ class TestMisc extends Test {
 
 	function testStringBuf() {
 		var b = new StringBuf();
+		eq(b.length, 0);
 		b.add( -45);
 		b.add(1.456);
 		b.add(null);
@@ -506,6 +507,7 @@ class TestMisc extends Test {
 		b.addSub("Bla", 1, 2);
 		b.addChar("R".code);
 		eq(b.toString(), "-451.456nulltruefalseHello!laR");
+		eq(b.length, 30);
 	}
 
 	function testToString():Void