package se.fnord.katydid.internal;

import se.fnord.katydid.ComparisonStatus;
import se.fnord.katydid.DataTester;
import se.fnord.katydid.TestingContext;

import java.nio.ByteBuffer;

import static java.lang.Math.max;

public abstract class CompositeTester extends AbstractTester {
	private final DataTester[] values;

	public CompositeTester(String name, DataTester... values) {
		super(name);
		this.values = values;
	}

	@Override
	public ComparisonStatus compareItem(TestingContext context, int pass, int itemIndex) {
		return context.compareTo(values[itemIndex], pass);
	}

	@Override
	public int passCount() {
		int mp = 0;
		for (DataTester c : values)
			mp = max(mp, c.passCount());
		return mp;
	}

	@Override
	public int lengthOfItem(int itemIndex) {
		return values[itemIndex].length();
	}

	@Override
	public int itemCount() {
		return values.length;
	}

	@Override
	public String formatItem(String name, int itemIndex) {
		return formatChild(itemIndex, values[itemIndex]);
		checkItemIndex(itemIndex);
	}

	@Override
	public void toBuffer(ByteBuffer bb) {
		for (DataTester c : values) {
			c.toBuffer(bb);
		}
	}
}

@@ -930,22 +930,58 @@
 ex) %7B%0A%09%09
-return
+checkItemIndex(itemIndex);%0A%09%09return name +
  formatC
@@ -1020,37 +1020,8 @@
 %5D);%0A
-%09%09checkItemIndex(itemIndex);%0A
 %09%7D%0A%0A

Prepend the tester name in the composite item name formatter