Fix remaining tests for java.util.regex

This commit is contained in:
Alexey Andreev 2015-06-21 08:41:36 +03:00
parent ec463124c9
commit 4641f9ca87
7 changed files with 11 additions and 17 deletions

View File

@ -183,7 +183,7 @@ class TMatchResultImpl implements TMatchResult {
throw new IllegalStateException(); throw new IllegalStateException();
} }
if (group < 0 || group > groupCount) { if (group < 0 || group >= groupCount) {
throw new IndexOutOfBoundsException(String.valueOf(group)); throw new IndexOutOfBoundsException(String.valueOf(group));
} }
} }

View File

@ -131,6 +131,9 @@ public final class TMatcher implements TMatchResult {
} }
if (nextBackSlashed) { if (nextBackSlashed) {
if (index >= repl.length) {
throw new IndexOutOfBoundsException();
}
res.append(repl[index]); res.append(repl[index]);
nextBackSlashed = false; nextBackSlashed = false;
} else { } else {
@ -158,8 +161,6 @@ public final class TMatcher implements TMatchResult {
replacementPos += group.length(); replacementPos += group.length();
res.append(group); res.append(group);
} catch (IndexOutOfBoundsException iob) {
throw iob;
} catch (Exception e) { } catch (Exception e) {
throw new IllegalArgumentException(""); throw new IllegalArgumentException("");
} }
@ -316,10 +317,6 @@ public final class TMatcher implements TMatchResult {
*/ */
@Override @Override
public String group(int group) { public String group(int group) {
if (group < 0 || group > matchResult.groupCount()) {
throw new IndexOutOfBoundsException("Index " + group + " if out of range [0; " +
matchResult.groupCount() + ")");
}
return matchResult.group(group); return matchResult.group(group);
} }

View File

@ -16,17 +16,17 @@
package org.teavm.classlib.java.util.regex; package org.teavm.classlib.java.util.regex;
import static org.junit.Assert.*;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException; import java.util.regex.PatternSyntaxException;
import org.junit.Test; import org.junit.Test;
import junit.framework.TestCase;
/** /**
* Tests Pattern compilation modes and modes triggered in pattern strings * Tests Pattern compilation modes and modes triggered in pattern strings
*/ */
@SuppressWarnings("nls") @SuppressWarnings("nls")
public class ModeTest extends TestCase { public class ModeTest {
@Test @Test
public void testCase() throws PatternSyntaxException { public void testCase() throws PatternSyntaxException {
Pattern p; Pattern p;

View File

@ -16,15 +16,15 @@
package org.teavm.classlib.java.util.regex; package org.teavm.classlib.java.util.regex;
import static org.junit.Assert.*;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.junit.Test; import org.junit.Test;
import junit.framework.TestCase;
/** /**
* Test boundary and error conditions in java.util.regex.Pattern * Test boundary and error conditions in java.util.regex.Pattern
*/ */
@SuppressWarnings("nls") @SuppressWarnings("nls")
public class PatternErrorTest extends TestCase { public class PatternErrorTest {
@Test @Test
public void testCompileErrors() throws Exception { public void testCompileErrors() throws Exception {
// null regex string - should get NullPointerException // null regex string - should get NullPointerException

View File

@ -16,17 +16,17 @@
package org.teavm.classlib.java.util.regex; package org.teavm.classlib.java.util.regex;
import static org.junit.Assert.*;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException; import java.util.regex.PatternSyntaxException;
import org.junit.Test; import org.junit.Test;
import junit.framework.TestCase;
/** /**
* TODO Type description * TODO Type description
*/ */
@SuppressWarnings("nls") @SuppressWarnings("nls")
public class PatternSyntaxExceptionTest extends TestCase { public class PatternSyntaxExceptionTest {
@Test @Test
public void testCase() { public void testCase() {
String regex = "("; String regex = "(";

View File

@ -23,7 +23,7 @@ import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException; import java.util.regex.PatternSyntaxException;
import org.junit.Test; import org.junit.Test;
public class PatternTest { public class PatternTest {
String[] testPatterns = { String[] testPatterns = {
"(a|b)*abb", "(a|b)*abb",
"(1*2*3*4*)*567", "(1*2*3*4*)*567",

View File

@ -23,9 +23,6 @@ import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException; import java.util.regex.PatternSyntaxException;
import org.junit.Test; import org.junit.Test;
/**
* TODO Type description
*/
public class SplitTest { public class SplitTest {
@Test @Test