Jelajahi Sumber

several spec fixes

Simon Krajewski 12 tahun lalu
induk
melakukan
5dcd0cb666
4 mengubah file dengan 33 tambahan dan 30 penghapusan
  1. 6 8
      std/Array.hx
  2. 1 1
      tests/unit/TestSpecification.hx
  3. 11 4
      tests/unit/UnitBuilder.hx
  4. 15 17
      tests/unit/unitstd/Array.unit.hx

+ 6 - 8
std/Array.hx

@@ -149,12 +149,12 @@ extern class Array<T> {
 		
 		This operation modifies [this] Array in place.
 		
-		If [pos] or [len] are negative, their values are calculated from the
-		end	of [this] Array by [this].length + [pos] and [this].length + [len]
-		respectively. If this yields a negative value, 0 is used instead.
+		If [len] is < 0 or [pos] exceeds [this].length, the result is the empty
+		Array [].
 		
-		If the resulting value for [len] is 0 or if the resulting value for
-		[pos] exceeds [this].length, the result is [].
+		If [pos] is negative, its values is calculated from the end	of [this]
+		Array by [this].length + [pos]. If this yields a negative value, 0 is
+		used instead.
 		
 		If the sum of the resulting values for [len] and [pos] exceed
 		[this].length, this operation will affect the elements from [pos] to the
@@ -193,9 +193,7 @@ extern class Array<T> {
 		
 		The offset is calculated like so:
 			
-		- If [pos] exceeds [this].length, [this] Array is padded with the
-		default value until [this].length equals [pos]. The offset is then
-		[pos].
+		- If [pos] exceeds [this].length, the offset is [this].length.
 		- If [pos] is negative, the offset is calculated from the end of [this]
 		Array, i.e. [this].length + [pos]. If this yields a negative value,
 		the offset is 0.

+ 1 - 1
tests/unit/TestSpecification.hx

@@ -26,7 +26,7 @@ private class IntWrap {
 	public var i(default, null):Int;
 	
 	public function new(i:Int) {
-		this.i == i;
+		this.i = i;
 	}
 	
 	static public function compare(a:IntWrap, b:IntWrap) {

+ 11 - 4
tests/unit/UnitBuilder.hx

@@ -55,6 +55,13 @@ class UnitBuilder {
 		}
 	}	
 	
+	static function mkEq(e1, e2, p) {
+		var e = macro eq($e1, $e2);
+		return {
+			expr: e.expr,
+			pos: p
+		}
+	}
 	static public function read(path:String) {
 		var p = Context.makePosition( { min:0, max:0, file:path } );
 		var file = sys.io.File.getContent(path);
@@ -81,14 +88,14 @@ class UnitBuilder {
 					var el2 = [];
 					for (i in 0...el.length) {
 						var e1 = el[i];
-						el2.push(macro $e[$(i)] == $e1);
+						el2.push(mkEq((macro $e[$(i)]), e1, e1.pos));
 					}
 					if (el2.length == 0)
-						macro $e.length == 0;
+						macro eq($e.length, 0);
 					else
-						collapseToAndExpr(el2);
+						macro { $[el2]; };
 				case EBinop(OpEq, e1, e2):
-					macro eq($e1, $e2);
+					mkEq(e1, e2, e.pos);
 				case EThrow(e):
 					macro exc(function() $e);
 				case EIn(e1, {expr:EArrayDecl(el) }):

+ 15 - 17
tests/unit/unitstd/Array.unit.hx

@@ -109,7 +109,7 @@ var i1 = new IntWrap(1);
 var i2 = new IntWrap(5);
 var i3 = new IntWrap(9);
 var i4 = new IntWrap(2);
-var a = [i4,i0,i1,i3,i0,i2];
+var a = [i4, i0, i1, i3, i0, i2];
 a.sort(IntWrap.compare);
 a == [i0, i1, i0, i4, i2, i3];
 
@@ -119,28 +119,26 @@ var i1 = new IntWrap(1);
 var i2 = new IntWrap(5);
 var i3 = new IntWrap(9);
 var i4 = new IntWrap(2);
-var a = [i4, i0, i1, i3, i0, i2];
-var b = a.splice(0, 0);
+var b = [i4, i0, i1, i3, i0, i2];
+var a = b.splice(0, 0);
 b != a;
-a == [i4, i0, i1, i3, i0, i2];
+a == [];
 b == [i4, i0, i1, i3, i0, i2];
 a = b.splice(1, b.length - 1);
 b == [i4];
 a == [i0, i1, i3, i0, i2];
 b = a.splice(1, -1);
-a == [i0];
-b == [i1, i3, i0, i2];
-a = b.splice(0, 10);
-a == [i1, i3, i0, i2];
-b == [];
-b = a.splice(10, 10);
+a == [i0, i1, i3, i0, i2];
 b == [];
-a = [i1, i3, i0, i2];
-b = a.splice( -2, 2);
-a == [i1, i3];
-b == [i0, i2];
-b.splice(0, -3) == [];
-b == [i0, i2];
+b = a.splice(0, 10);
+b == [i0, i1, i3, i0, i2];
+a == [];
+a = b.splice(10, 10);
+a == [];
+b = [i0, i1, i3, i0, i2];
+a = b.splice( -2, 2);
+b == [i0, i1, i3];
+a == [i0, i2];
 
 // toString
 var a = [new ClassWithToString(), new ClassWithToStringChild(), new ClassWithToStringChild2()];
@@ -162,7 +160,7 @@ a == [null, 2, 1];
 // insert
 var a = [];
 a.insert(5, 1);
-a == [0, 0, 0, 0, 0, 1];
+a == [1];
 var a = [1, 2, 3];
 a.insert(1, 4);
 a == [1, 4, 2, 3];