package org.graalvm.compiler.replacements.test;
import java.util.ArrayList;
import java.util.Collection;
import org.graalvm.compiler.core.test.GraalCompilerTest;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@RunWith(Parameterized.class)
public class StringIndexOfCharTest extends GraalCompilerTest {
@Parameterized.Parameters(name = "{0},{1},{2}")
public static Collection<Object[]> data() {
ArrayList<Object[]> tests = new ArrayList<>();
String longString = "ab";
for (int i = 0; i < 15; i++) {
longString = longString + longString;
}
longString = longString + "xx";
String longUTF16String = "\u03bb" + longString;
String mediumString = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaax" +
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
String mediumUTF16String = "\u03bbaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaax" +
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
String[] targets = new String[]{"foobar", "foo", "bar", "\u03bbfoobar", mediumString, mediumUTF16String, longString, longUTF16String};
int[] targetChars = new int[]{'f', 'o', 'r', 'x', Character.MIN_SUPPLEMENTARY_CODE_POINT};
int[] targetOffsets = new int[12];
for (int i = 0; i < targetOffsets.length; i++) {
targetOffsets[i] = i - 1;
}
for (String source : targets) {
for (int targetChar : targetChars) {
for (int offset : targetOffsets) {
tests.add(new Object[]{source, targetChar, offset});
}
}
}
return tests;
}
protected final String sourceString;
protected final int constantChar;
protected final int fromIndex;
public StringIndexOfCharTest(String sourceString, int constantChar, int fromIndex) {
this.sourceString = sourceString;
this.constantChar = constantChar;
this.fromIndex = fromIndex;
}
public int testStringIndexOf(String a, int b) {
return a.indexOf(b);
}
public int testStringIndexOfOffset(String a, int b, int offset) {
return a.indexOf(b, offset);
}
@Test
public void testStringIndexOfConstant() {
test("testStringIndexOf", this.sourceString, this.constantChar);
}
@Test
public void testStringIndexOfConstantOffset() {
test("testStringIndexOfOffset", this.sourceString, this.constantChar, this.fromIndex);
}
}