소스 검색

add test (see #3535)

Simon Krajewski 9 년 전
부모
커밋
f4672cbeaa
1개의 변경된 파일56개의 추가작업 그리고 0개의 파일을 삭제
  1. 56 0
      tests/unit/src/unit/issues/Issue3535.hx

+ 56 - 0
tests/unit/src/unit/issues/Issue3535.hx

@@ -0,0 +1,56 @@
+package unit.issues;
+
+@:generic
+private class IndexedItemIterator<T>
+{
+	var items:Array<T>;
+	var i:Int = 0;
+
+	public inline function new(items:Array<T>)
+	{
+		this.items = items;
+	}
+
+	public inline function hasNext()
+	{
+		return i < items.length;
+	}
+
+	public inline function next()
+	{
+		++i;
+        return new IndexedItemObject<T>(i - 1, items[i - 1]);
+	}
+}
+
+@:generic
+private class IndexedItemObject<T>
+{
+	public var index:Int;
+	public var item:T;
+
+	public inline function new(index:Int, item:T)
+	{
+		this.index = index;
+		this.item = item;
+	}
+}
+
+class Issue3535 extends Test {
+	function test() {
+		var list = ["111","222","333"];
+		var buf = new StringBuf();
+		for(value in new IndexedItemIterator<String>(list)) {
+			buf.add(value.index + ":" + value.item);
+		}
+
+		eq("0:1111:2222:333", buf.toString());
+
+		var list2 = [3,4,5,7];
+		var buf = new StringBuf();
+		for(value in new IndexedItemIterator<Int>(list2)) {
+			buf.add(value.index + ":" + value.item);
+		}
+		eq("0:31:42:53:7", buf.toString());
+	}
+}