regexp parsing tests run in memory and don't crap in testdata directory

This commit is contained in:
Dmitry Jemerov
2012-06-29 20:26:19 +02:00
parent e99d98f501
commit 0281400834
229 changed files with 163 additions and 385 deletions
+1
View File
@@ -18,6 +18,7 @@
<orderEntry type="module" module-name="dom-impl" scope="RUNTIME" />
<orderEntry type="module" module-name="relaxng" scope="RUNTIME" />
<orderEntry type="module" module-name="spellchecker" scope="RUNTIME" />
<orderEntry type="module" module-name="xdebugger-impl" scope="RUNTIME" />
</component>
</module>
+162 -156
View File
@@ -15,7 +15,7 @@
*/
package test;
import com.intellij.openapi.util.io.FileUtil;
import org.intellij.lang.regexp.RegExpFileType;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;
@@ -30,185 +30,191 @@ import java.util.regex.PatternSyntaxException;
public class MainParseTest extends BaseParseTestcase {
private ByteArrayOutputStream myOut;
private ByteArrayOutputStream myOut;
enum Result {
OK, ERR
enum Result {
OK, ERR
}
static class Test {
String pattern;
boolean showWarnings = true;
boolean showInfo = false;
Result expectedResult;
Test(String pattern, Result result, boolean warn, boolean info) {
this.pattern = pattern;
expectedResult = result;
showWarnings = warn;
showInfo = info;
}
static class Test {
boolean showWarnings = true;
boolean showInfo = false;
Result expectedResult;
}
Test(Result result, boolean warn, boolean info) {
expectedResult = result;
showWarnings = warn;
showInfo = info;
private final Map<String, Test> myMap = new LinkedHashMap<String, Test>();
@Override
protected void setUp() throws Exception {
final Document document = new SAXBuilder().build(new File(getTestDataRoot(), "/RETest.xml"));
final List<Element> list = XPath.selectNodes(document.getRootElement(), "//test");
int i = 0;
for (Element element : list) {
final String name;
final Element parent = (Element)element.getParent();
final String s = parent.getName();
final String t = parent.getAttribute("id") == null ? "" : parent.getAttribute("id").getValue() + "-";
if (!"tests".equals(s)) {
name = s + "/test-" + t + ++i + ".regexp";
}
else {
name = "test-" + t + ++i + ".regexp";
}
final Result result = Result.valueOf((String)XPath.selectSingleNode(element, "string(expected)"));
final boolean warn = !"false".equals(element.getAttributeValue("warning"));
final boolean info = "true".equals(element.getAttributeValue("info"));
final String pattern = (String)XPath.selectSingleNode(element, "string(pattern)");
myMap.put(name, new Test(pattern, result, warn, info));
if (!"false".equals(element.getAttributeValue("verify"))) {
try {
Pattern.compile(pattern);
if (result == Result.ERR) {
System.out.println("Incorrect FAIL value for " + pattern);
}
}
}
private final Map<String, Test> myMap = new LinkedHashMap<String, Test>();
@Override
protected void setUp() throws Exception {
final Document document = new SAXBuilder().build(new File(getTestDataRoot(), "/RETest.xml"));
final List<Element> list = XPath.selectNodes(document.getRootElement(), "//test");
new File(getTestDataPath()).mkdirs();
int i = 0;
for (Element element : list) {
final String name;
final Element parent = (Element)element.getParent();
final String s = parent.getName();
final String t = parent.getAttribute("id") == null ? "" : parent.getAttribute("id").getValue() + "-";
if (!"tests".equals(s)) {
name = s + "/test-" + t + ++i + ".regexp";
} else {
name = "test-" + t + ++i + ".regexp";
}
final Result result = Result.valueOf((String)XPath.selectSingleNode(element, "string(expected)"));
final boolean warn = !"false".equals(element.getAttributeValue("warning"));
final boolean info = "true".equals(element.getAttributeValue("info"));
myMap.put(name, new Test(result, warn, info));
final File file = new File(getTestDataPath(), name);
file.getParentFile().mkdirs();
final FileWriter stream = new FileWriter(file);
final String pattern = (String)XPath.selectSingleNode(element, "string(pattern)");
if (!"false".equals(element.getAttributeValue("verify"))) try {
Pattern.compile(pattern);
if (result == Result.ERR) {
System.out.println("Incorrect FAIL value for " + pattern);
}
} catch (PatternSyntaxException e) {
if (result == Result.OK) {
System.out.println("Incorrect OK value for " + pattern);
}
}
stream.write(pattern);
stream.close();
catch (PatternSyntaxException e) {
if (result == Result.OK) {
System.out.println("Incorrect OK value for " + pattern);
}
}
super.setUp();
myOut = new ByteArrayOutputStream();
System.setErr(new PrintStream(myOut));
}
}
@Override
protected String getTestDataPath() {
return super.getTestDataPath()+"/gen/";
}
super.setUp();
public void testSimple() throws Exception {
doTest("simple/");
}
myOut = new ByteArrayOutputStream();
System.setErr(new PrintStream(myOut));
}
public void testQuantifiers() throws Exception {
doTest("quantifiers/");
}
@Override
protected String getTestDataPath() {
return super.getTestDataPath() + "/gen/";
}
public void testGroups() throws Exception {
doTest("groups/");
}
public void testSimple() throws Exception {
doTest("simple/");
}
public void testCharclasses() throws Exception {
doTest("charclasses/");
}
public void testQuantifiers() throws Exception {
doTest("quantifiers/");
}
public void testEscapes() throws Exception {
doTest("escapes/");
}
public void testGroups() throws Exception {
doTest("groups/");
}
public void testAnchors() throws Exception {
doTest("anchors/");
}
public void testCharclasses() throws Exception {
doTest("charclasses/");
}
public void testNamedchars() throws Exception {
doTest("namedchars/");
}
public void testEscapes() throws Exception {
doTest("escapes/");
}
public void testBackrefs() throws Exception {
doTest("backrefs/");
}
public void testAnchors() throws Exception {
doTest("anchors/");
}
public void testComplex() throws Exception {
doTest("complex/");
}
public void testNamedchars() throws Exception {
doTest("namedchars/");
}
public void testIncomplete() throws Exception {
doTest("incomplete/");
}
public void testBackrefs() throws Exception {
doTest("backrefs/");
}
public void testRealLife() throws Exception {
doTest("real-life/");
}
public void testComplex() throws Exception {
doTest("complex/");
}
public void testRegressions() throws Exception {
doTest("regressions/");
}
public void testIncomplete() throws Exception {
doTest("incomplete/");
}
public void testBugs() throws Exception {
doTest("bug/");
}
public void testRealLife() throws Exception {
doTest("real-life/");
}
public void testFromXML() throws Exception {
doTest(null);
}
public void testRegressions() throws Exception {
doTest("regressions/");
}
private void doTest(String prefix) throws IOException {
int n = 0;
int failed = 0;
for (String name : myMap.keySet()) {
if (prefix == null && name.contains("/")) {
continue;
}
if (prefix != null && !name.startsWith(prefix)) {
continue;
}
System.out.print("filename = " + name);
n++;
public void testBugs() throws Exception {
doTest("bug/");
}
final MainParseTest.Test test = myMap.get(name);
try {
myFixture.testHighlighting(test.showWarnings, true, test.showInfo, name);
public void testFromXML() throws Exception {
doTest(null);
}
if (test.expectedResult == Result.ERR) {
System.out.println(" FAILED. Expression incorrectly parsed OK: " + FileUtil.loadFile(new File(getTestDataPath(), name)));
failed++;
} else {
System.out.println(" OK");
}
} catch (Throwable e) {
if (test.expectedResult == Result.ERR) {
System.out.println(" OK");
} else {
e.printStackTrace();
System.out.println(" FAILED. Expression = " + FileUtil.loadFile(new File(getTestDataPath(), name)));
if (myOut.size() > 0) {
String line;
final BufferedReader reader = new BufferedReader(new StringReader(myOut.toString()));
do {
line = reader.readLine();
} while (line != null && (line.trim().length() == 0 || line.trim().equals("ERROR:")));
if (line != null) {
if (line.matches(".*java.lang.Error: junit.framework.AssertionFailedError:.*")) {
System.out.println("ERROR: " + line.replace("java.lang.Error: junit.framework.AssertionFailedError:", ""));
}
} else {
System.out.println("ERROR: " + myOut.toString());
}
}
failed++;
}
}
myOut.reset();
private void doTest(String prefix) throws IOException {
int n = 0;
int failed = 0;
for (String name : myMap.keySet()) {
if (prefix == null && name.contains("/")) {
continue;
}
if (prefix != null && !name.startsWith(prefix)) {
continue;
}
System.out.print("filename = " + name);
n++;
final MainParseTest.Test test = myMap.get(name);
try {
myFixture.configureByText(RegExpFileType.INSTANCE, test.pattern);
myFixture.testHighlighting(test.showWarnings, true, test.showInfo);
if (test.expectedResult == Result.ERR) {
System.out.println(" FAILED. Expression incorrectly parsed OK: " + test.pattern);
failed++;
}
System.out.println("");
System.out.println(n + " Tests executed, " + failed + " failed");
assertFalse(failed > 0);
else {
System.out.println(" OK");
}
}
catch (Throwable e) {
if (test.expectedResult == Result.ERR) {
System.out.println(" OK");
}
else {
e.printStackTrace();
System.out.println(" FAILED. Expression = " + test.pattern);
if (myOut.size() > 0) {
String line;
final BufferedReader reader = new BufferedReader(new StringReader(myOut.toString()));
do {
line = reader.readLine();
}
while (line != null && (line.trim().length() == 0 || line.trim().equals("ERROR:")));
if (line != null) {
if (line.matches(".*java.lang.Error: junit.framework.AssertionFailedError:.*")) {
System.out.println("ERROR: " + line.replace("java.lang.Error: junit.framework.AssertionFailedError:", ""));
}
}
else {
System.out.println("ERROR: " + myOut.toString());
}
}
failed++;
}
}
myOut.reset();
}
System.out.println("");
System.out.println(n + " Tests executed, " + failed + " failed");
assertFalse(failed > 0);
}
}
@@ -1 +0,0 @@
^*
@@ -1 +0,0 @@
$*
@@ -1 +0,0 @@
^abc
@@ -1 +0,0 @@
^abc$
@@ -1 +0,0 @@
abc$
@@ -1 +0,0 @@
^
@@ -1 +0,0 @@
$
@@ -1 +0,0 @@
$b
@@ -1 +0,0 @@
^(ab|cd)e
@@ -1 +0,0 @@
^a(bc+|b[eh])g|.h$
@@ -1 +0,0 @@
(ac*)c*d[ac]*\1
@@ -1 +0,0 @@
(.)=\1
@@ -1 +0,0 @@
([ab])=\1
@@ -1 +0,0 @@
([ab]+)=\1
@@ -1 +0,0 @@
([ab]+)=\2
@@ -1 +0,0 @@
([ab]+)=\3
@@ -1 +0,0 @@
([ab]+=<warning descr="Backreference is nested into the capturing group it refers to">\1</warning>)
@@ -1 +0,0 @@
a[bc]d
@@ -1 +0,0 @@
a[b-d]e
@@ -1 +0,0 @@
a[b-d]
@@ -1 +0,0 @@
a[b-a]
@@ -1 +0,0 @@
a[-b]
@@ -1 +0,0 @@
a[b-]
@@ -1 +0,0 @@
[a-[b]]
@@ -1 +0,0 @@
a[b&&[cd]]
@@ -1 +0,0 @@
a[b-&&[cd]]
@@ -1 +0,0 @@
a[b&&-]
@@ -1 +0,0 @@
a[b&&-b]
@@ -1 +0,0 @@
[&&]
@@ -1 +0,0 @@
a[b&&c&&d]
@@ -1 +0,0 @@
a[b&&c&&d-e&&f]
@@ -1 +0,0 @@
a[a[b][c]]
@@ -1 +0,0 @@
[a-[]]
@@ -1 +0,0 @@
[a-[b
@@ -1 +0,0 @@
[a[^b]]
@@ -1 +0,0 @@
a[a[b[c]][d]]
@@ -1 +0,0 @@
a[\t--]
@@ -1 +0,0 @@
a[\t--]
@@ -1 +0,0 @@
a[\t---]
@@ -1 +0,0 @@
a[-]?c
@@ -1 +0,0 @@
a[
@@ -1 +0,0 @@
a]
@@ -1 +0,0 @@
[a-[
@@ -1 +0,0 @@
a[]]
@@ -1 +0,0 @@
a[^bc]d
@@ -1 +0,0 @@
a[^bc]
@@ -1 +0,0 @@
a[]b
@@ -1 +0,0 @@
[abhgefdc]ij
@@ -1 +0,0 @@
[a-zA-Z_][a-zA-Z0-9_]*
@@ -1 +0,0 @@
([a-c]+?)c
@@ -1 +0,0 @@
([ab]*?)b
@@ -1 +0,0 @@
([ab]*)b
@@ -1 +0,0 @@
([ab]??)b
@@ -1 +0,0 @@
(c[ab]?)b
@@ -1 +0,0 @@
(c[ab]??)b
@@ -1 +0,0 @@
(c[ab]*?)b
@@ -1 +0,0 @@
a[bcd]+dcdcde
@@ -1 +0,0 @@
[k]
@@ -1 +0,0 @@
a[bcd]*dcdcde
@@ -1 +0,0 @@
[^ab]*
@@ -1 +0,0 @@
a[.]b
@@ -1 +0,0 @@
a[+*?]b
@@ -1 +0,0 @@
a[\p{IsDigit}\p{IsAlpha}]b
@@ -1 +0,0 @@
[\p{L}&&[^\p{Lu}]]
@@ -1 +0,0 @@
a\p
@@ -1 +0,0 @@
a\p{}
@@ -1 +0,0 @@
a\p}
@@ -1 +0,0 @@
a\p{123}
@@ -1 +0,0 @@
a\p{<error descr="Character family name expected">*</error>}b
@@ -1 +0,0 @@
[<warning descr="Redundant character range">\w-\w</warning>]
@@ -1 +0,0 @@
[a-\w]
@@ -1,3 +0,0 @@
(?x)abc #foo \q bar
# foo
(?-xi)xyz(?i:ABC)
@@ -1 +0,0 @@
z(\w\s+(?:\w\s+\w)+)z
@@ -1 +0,0 @@
(([hH][tT]{2}[pP]|[fF][tT][pP]):\/\/)?[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]+)*
@@ -1 +0,0 @@
((?:[hH][tT]{2}[pP]|[fF][tT][pP]):\/\/)?[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]+)*
@@ -1 +0,0 @@
(([hH][tT]{2}[pP]|[fF][tT][pP]):\/\/)?[a-zA-Z0-9\-]+(?:\.[a-zA-Z0-9\-]+)*
@@ -1 +0,0 @@
(?:([hH][tT]{2}[pP]|[fF][tT][pP]):\/\/)?[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]+)*
@@ -1 +0,0 @@
^(?:([hH][tT]{2}[pP]|[fF][tT][pP]):\/\/)?[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]+)*$
@@ -1 +0,0 @@
^(?:(?:[hH][tT]{2}[pP]|[fF][tT][pP]):\/\/)?[a-zA-Z0-9\-]+(?:\.[a-zA-Z0-9\-]+)*$
@@ -1 +0,0 @@
\q
@@ -1 +0,0 @@
\#
@@ -1 +0,0 @@
a\
@@ -1 +0,0 @@
a\(b
@@ -1 +0,0 @@
a\(*b
@@ -1 +0,0 @@
a\\b
@@ -1 +0,0 @@
\u004a
@@ -1 +0,0 @@
\0123
@@ -1 +0,0 @@
\0
@@ -1 +0,0 @@
\x4a
@@ -1 +0,0 @@
[\x4a-\x4b]
@@ -1 +0,0 @@
[<warning descr="Redundant character range">a-a</warning>]
@@ -1 +0,0 @@
[\x4a-\x3f]
@@ -1 +0,0 @@
a\Qabc?*+.))]][]\Eb
@@ -1 +0,0 @@
(a\Qabc?*+.))]][]\Eb)
@@ -1 +0,0 @@
[\Qabc?*+.))]][]\E]
@@ -1 +0,0 @@
a\Qabc?*+.))]][]\E)
@@ -1 +0,0 @@
()*
@@ -1 +0,0 @@
<warning descr="Empty group">()</warning>

Some files were not shown because too many files have changed in this diff Show More