/*
 * Copyright 2015-2017 the original author or authors.
 *
 * All rights reserved. This program and the accompanying materials are
 * made available under the terms of the Eclipse Public License v1.0 which
 * accompanies this distribution and is available at
 *
 * http://www.eclipse.org/legal/epl-v10.html
 */

package org.junit.jupiter.params;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;

/**
 * @since 5.0
 */
class ParameterizedTestNameFormatterTests {

	@Test
	void formatsInvocationIndex() {
		ParameterizedTestNameFormatter formatter = new ParameterizedTestNameFormatter("{index}");

		assertEquals("1", formatter.format(1));
		assertEquals("2", formatter.format(2));
	}

	@Test
	void formatsIndividualArguments() {
		ParameterizedTestNameFormatter formatter = new ParameterizedTestNameFormatter("{0} -> {1}");

		assertEquals("foo -> 42", formatter.format(1, "foo", 42));
	}

	@Test
	void formatsCompleteArgumentsList() {
		ParameterizedTestNameFormatter formatter = new ParameterizedTestNameFormatter("{arguments}");

		// @formatter:off
		assertEquals("42, 99, enigma, null, [1, 2, 3], [foo, bar], [[2, 4], [3, 9]]",
			formatter.format(1,
				Integer.valueOf(42),
				99,
				"enigma",
				null,
				new int[] { 1, 2, 3 },
				new String[] { "foo", "bar" },
				new Integer[][] { { 2, 4 }, { 3, 9 } }
			));
		// @formatter:on
	}

	@Test
	void formatsInvocationIndexAndCompleteArgumentsListUsingDefaultPattern() {
		ParameterizedTestNameFormatter formatter = new ParameterizedTestNameFormatter("[{index}] {arguments}");

		// Explicit test for https://github.com/junit-team/junit5/issues/814
		assertEquals("[1] [foo, bar]", formatter.format(1, (Object) new String[] { "foo", "bar" }));

		assertEquals("[1] [foo, bar], 42, true", formatter.format(1, new String[] { "foo", "bar" }, 42, true));
	}

}

@@ -395,21 +395,113 @@
 s.assert
-Equal
+ArrayEquals;%0Aimport static org.junit.jupiter.api.Assertions.assertEquals;%0A%0Aimport java.util.Array
 s;%0A%0Aimpo
@@ -1950,10 +1950,434 @@
 ));%0A%09%7D%0A%0A
+%09@Test%0A%09void formatDoesNotAlterArgumentsArray() %7B%0A%09%09ParameterizedTestNameFormatter formatter = new ParameterizedTestNameFormatter(%22%7Barguments%7D%22);%0A%09%09Object%5B%5D actual = %7B 1, %22two%22, Byte.valueOf(%22-128%22), new Integer%5B%5D%5B%5D %7B %7B 2, 4 %7D, %7B 3, 9 %7D %7D %7D;%0A%09%09Object%5B%5D expected = Arrays.copyOf(actual, actual.length);%0A%09%09assertEquals(%221, two, -128, %5B%5B2, 4%5D, %5B3, 9%5D%5D%22, formatter.format(1, actual));%0A%09%09assertArrayEquals(expected, actual);%0A%09%7D%0A%0A
 %7D%0A

Test invariant array argument in name formatter