From 4641f9ca8726ae5d92aac74c84b4a93ea7a60c09 Mon Sep 17 00:00:00 2001 From: Alexey Andreev <konsoletyper@gmail.com> Date: Sun, 21 Jun 2015 08:41:36 +0300 Subject: [PATCH] Fix remaining tests for java.util.regex --- .../teavm/classlib/java/util/regex/TMatchResultImpl.java | 2 +- .../org/teavm/classlib/java/util/regex/TMatcher.java | 9 +++------ .../org/teavm/classlib/java/util/regex/ModeTest.java | 4 ++-- .../teavm/classlib/java/util/regex/PatternErrorTest.java | 4 ++-- .../java/util/regex/PatternSyntaxExceptionTest.java | 4 ++-- .../org/teavm/classlib/java/util/regex/PatternTest.java | 2 +- .../org/teavm/classlib/java/util/regex/SplitTest.java | 3 --- 7 files changed, 11 insertions(+), 17 deletions(-) diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/regex/TMatchResultImpl.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/regex/TMatchResultImpl.java index 828bf5a46..ebf8ba377 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/regex/TMatchResultImpl.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/regex/TMatchResultImpl.java @@ -183,7 +183,7 @@ class TMatchResultImpl implements TMatchResult { throw new IllegalStateException(); } - if (group < 0 || group > groupCount) { + if (group < 0 || group >= groupCount) { throw new IndexOutOfBoundsException(String.valueOf(group)); } } diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/regex/TMatcher.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/regex/TMatcher.java index ecba9b2a0..9e4670f28 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/regex/TMatcher.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/regex/TMatcher.java @@ -131,6 +131,9 @@ public final class TMatcher implements TMatchResult { } if (nextBackSlashed) { + if (index >= repl.length) { + throw new IndexOutOfBoundsException(); + } res.append(repl[index]); nextBackSlashed = false; } else { @@ -158,8 +161,6 @@ public final class TMatcher implements TMatchResult { replacementPos += group.length(); res.append(group); - } catch (IndexOutOfBoundsException iob) { - throw iob; } catch (Exception e) { throw new IllegalArgumentException(""); } @@ -316,10 +317,6 @@ public final class TMatcher implements TMatchResult { */ @Override 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); } diff --git a/teavm-tests/src/test/java/org/teavm/classlib/java/util/regex/ModeTest.java b/teavm-tests/src/test/java/org/teavm/classlib/java/util/regex/ModeTest.java index b7ec7785c..64e89f616 100644 --- a/teavm-tests/src/test/java/org/teavm/classlib/java/util/regex/ModeTest.java +++ b/teavm-tests/src/test/java/org/teavm/classlib/java/util/regex/ModeTest.java @@ -16,17 +16,17 @@ package org.teavm.classlib.java.util.regex; +import static org.junit.Assert.*; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; import org.junit.Test; -import junit.framework.TestCase; /** * Tests Pattern compilation modes and modes triggered in pattern strings */ @SuppressWarnings("nls") -public class ModeTest extends TestCase { +public class ModeTest { @Test public void testCase() throws PatternSyntaxException { Pattern p; diff --git a/teavm-tests/src/test/java/org/teavm/classlib/java/util/regex/PatternErrorTest.java b/teavm-tests/src/test/java/org/teavm/classlib/java/util/regex/PatternErrorTest.java index f5d553840..79e905af7 100644 --- a/teavm-tests/src/test/java/org/teavm/classlib/java/util/regex/PatternErrorTest.java +++ b/teavm-tests/src/test/java/org/teavm/classlib/java/util/regex/PatternErrorTest.java @@ -16,15 +16,15 @@ package org.teavm.classlib.java.util.regex; +import static org.junit.Assert.*; import java.util.regex.Pattern; import org.junit.Test; -import junit.framework.TestCase; /** * Test boundary and error conditions in java.util.regex.Pattern */ @SuppressWarnings("nls") -public class PatternErrorTest extends TestCase { +public class PatternErrorTest { @Test public void testCompileErrors() throws Exception { // null regex string - should get NullPointerException diff --git a/teavm-tests/src/test/java/org/teavm/classlib/java/util/regex/PatternSyntaxExceptionTest.java b/teavm-tests/src/test/java/org/teavm/classlib/java/util/regex/PatternSyntaxExceptionTest.java index 63b01e995..07ca674d5 100644 --- a/teavm-tests/src/test/java/org/teavm/classlib/java/util/regex/PatternSyntaxExceptionTest.java +++ b/teavm-tests/src/test/java/org/teavm/classlib/java/util/regex/PatternSyntaxExceptionTest.java @@ -16,17 +16,17 @@ package org.teavm.classlib.java.util.regex; +import static org.junit.Assert.*; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; import org.junit.Test; -import junit.framework.TestCase; /** * TODO Type description */ @SuppressWarnings("nls") -public class PatternSyntaxExceptionTest extends TestCase { +public class PatternSyntaxExceptionTest { @Test public void testCase() { String regex = "("; diff --git a/teavm-tests/src/test/java/org/teavm/classlib/java/util/regex/PatternTest.java b/teavm-tests/src/test/java/org/teavm/classlib/java/util/regex/PatternTest.java index 47ddaafb1..008f29a99 100644 --- a/teavm-tests/src/test/java/org/teavm/classlib/java/util/regex/PatternTest.java +++ b/teavm-tests/src/test/java/org/teavm/classlib/java/util/regex/PatternTest.java @@ -23,7 +23,7 @@ import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; import org.junit.Test; -public class PatternTest { +public class PatternTest { String[] testPatterns = { "(a|b)*abb", "(1*2*3*4*)*567", diff --git a/teavm-tests/src/test/java/org/teavm/classlib/java/util/regex/SplitTest.java b/teavm-tests/src/test/java/org/teavm/classlib/java/util/regex/SplitTest.java index 7e13fe38d..dbd335cb3 100644 --- a/teavm-tests/src/test/java/org/teavm/classlib/java/util/regex/SplitTest.java +++ b/teavm-tests/src/test/java/org/teavm/classlib/java/util/regex/SplitTest.java @@ -23,9 +23,6 @@ import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; import org.junit.Test; -/** - * TODO Type description - */ public class SplitTest { @Test