forked from jasder/antlr
Fix writing Unicode values in runtime tests
This commit is contained in:
parent
93f916745d
commit
77067674b9
|
@ -224,7 +224,7 @@ public abstract class BaseRuntimeTest {
|
|||
String... extraOptions)
|
||||
{
|
||||
mkdir(workdir);
|
||||
BaseJavaTest.writeFile(workdir, grammarFileName, grammarStr);
|
||||
writeFile(workdir, grammarFileName, grammarStr);
|
||||
return antlrOnString(workdir, targetName, grammarFileName, defaultListener, extraOptions);
|
||||
}
|
||||
|
||||
|
|
|
@ -47,9 +47,7 @@ import org.stringtemplate.v4.STGroup;
|
|||
import org.stringtemplate.v4.STGroupString;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
@ -70,6 +68,7 @@ import java.util.Set;
|
|||
import java.util.TreeMap;
|
||||
|
||||
import static org.antlr.v4.test.runtime.BaseRuntimeTest.antlrOnString;
|
||||
import static org.antlr.v4.test.runtime.BaseRuntimeTest.writeFile;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
@ -869,21 +868,6 @@ public class BaseCppTest implements RuntimeTestSupport {
|
|||
}
|
||||
}
|
||||
|
||||
public static void writeFile(String dir, String fileName, String content) {
|
||||
try {
|
||||
File f = new File(dir, fileName);
|
||||
FileWriter w = new FileWriter(f);
|
||||
BufferedWriter bw = new BufferedWriter(w);
|
||||
bw.write(content);
|
||||
bw.close();
|
||||
w.close();
|
||||
}
|
||||
catch (IOException ioe) {
|
||||
System.err.println("can't write file");
|
||||
ioe.printStackTrace(System.err);
|
||||
}
|
||||
}
|
||||
|
||||
protected void mkdir(String dir) {
|
||||
File f = new File(dir);
|
||||
f.mkdirs();
|
||||
|
|
|
@ -49,6 +49,7 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
|
||||
import static org.antlr.v4.test.runtime.BaseRuntimeTest.antlrOnString;
|
||||
import static org.antlr.v4.test.runtime.BaseRuntimeTest.writeFile;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
@ -611,16 +612,6 @@ public class BaseCSharpTest implements RuntimeTestSupport /*, SpecialRuntimeTest
|
|||
}
|
||||
}
|
||||
|
||||
public static void writeFile(String dir, String fileName, String content) {
|
||||
try {
|
||||
Utils.writeFile(dir+"/"+fileName, content, "UTF-8");
|
||||
}
|
||||
catch (IOException ioe) {
|
||||
System.err.println("can't write file");
|
||||
ioe.printStackTrace(System.err);
|
||||
}
|
||||
}
|
||||
|
||||
protected void mkdir(String dir) {
|
||||
File f = new File(dir);
|
||||
f.mkdirs();
|
||||
|
|
|
@ -70,6 +70,7 @@ import static junit.framework.TestCase.assertFalse;
|
|||
import static junit.framework.TestCase.assertNotNull;
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
import static org.antlr.v4.test.runtime.BaseRuntimeTest.antlrOnString;
|
||||
import static org.antlr.v4.test.runtime.BaseRuntimeTest.writeFile;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
|
||||
public class BaseGoTest implements RuntimeTestSupport {
|
||||
|
@ -309,7 +310,7 @@ public class BaseGoTest implements RuntimeTestSupport {
|
|||
boolean success = rawGenerateAndBuildRecognizer(grammarFileName,
|
||||
grammarStr, null, lexerName, "-no-listener");
|
||||
assertTrue(success);
|
||||
writeFile(overall_tmpdir, "input", input);
|
||||
writeFile(overall_tmpdir.toString(), "input", input);
|
||||
writeLexerTestFile(lexerName, showDFA);
|
||||
String output = execModule("Test.go");
|
||||
return output;
|
||||
|
@ -338,7 +339,7 @@ public class BaseGoTest implements RuntimeTestSupport {
|
|||
boolean success = rawGenerateAndBuildRecognizer(grammarFileName,
|
||||
grammarStr, parserName, lexerName, "-visitor");
|
||||
assertTrue(success);
|
||||
writeFile(overall_tmpdir, "input", input);
|
||||
writeFile(overall_tmpdir.toString(), "input", input);
|
||||
rawBuildRecognizerTestFile(parserName, lexerName, listenerName,
|
||||
visitorName, startRuleName, showDiagnosticErrors);
|
||||
return execRecognizer();
|
||||
|
@ -700,35 +701,6 @@ public class BaseGoTest implements RuntimeTestSupport {
|
|||
}
|
||||
}
|
||||
|
||||
public static void writeFile(File dir, String fileName, String content) {
|
||||
try {
|
||||
File f = new File(dir, fileName);
|
||||
FileWriter w = new FileWriter(f);
|
||||
BufferedWriter bw = new BufferedWriter(w);
|
||||
bw.write(content);
|
||||
bw.close();
|
||||
w.close();
|
||||
} catch (IOException ioe) {
|
||||
System.err.println("can't write file");
|
||||
ioe.printStackTrace(System.err);
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeFile(String dir, String fileName, InputStream content) {
|
||||
try {
|
||||
File f = new File(dir, fileName);
|
||||
OutputStream output = new FileOutputStream(f);
|
||||
while(content.available()>0) {
|
||||
int b = content.read();
|
||||
output.write(b);
|
||||
}
|
||||
output.close();
|
||||
} catch (IOException ioe) {
|
||||
System.err.println("can't write file");
|
||||
ioe.printStackTrace(System.err);
|
||||
}
|
||||
}
|
||||
|
||||
protected void mkdir(File dir) {
|
||||
dir.mkdirs();
|
||||
}
|
||||
|
@ -785,7 +757,7 @@ public class BaseGoTest implements RuntimeTestSupport {
|
|||
outputFileST.add("listenerName", listenerName);
|
||||
outputFileST.add("visitorName", visitorName);
|
||||
outputFileST.add("parserStartRuleName", parserStartRuleName.substring(0, 1).toUpperCase() + parserStartRuleName.substring(1) );
|
||||
writeFile(overall_tmpdir, "Test.go", outputFileST.render());
|
||||
writeFile(overall_tmpdir.toString(), "Test.go", outputFileST.render());
|
||||
}
|
||||
|
||||
|
||||
|
@ -813,7 +785,7 @@ public class BaseGoTest implements RuntimeTestSupport {
|
|||
+ "}\n"
|
||||
+ "\n");
|
||||
outputFileST.add("lexerName", lexerName);
|
||||
writeFile(overall_tmpdir, "Test.go", outputFileST.render());
|
||||
writeFile(overall_tmpdir.toString(), "Test.go", outputFileST.render());
|
||||
}
|
||||
|
||||
public void writeRecognizer(String parserName, String lexerName,
|
||||
|
|
|
@ -81,6 +81,7 @@ import static junit.framework.TestCase.assertEquals;
|
|||
import static junit.framework.TestCase.assertFalse;
|
||||
import static junit.framework.TestCase.assertNotNull;
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
import static org.antlr.v4.test.runtime.BaseRuntimeTest.writeFile;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
|
||||
public class BaseJavaTest implements RuntimeTestSupport {
|
||||
|
@ -941,16 +942,6 @@ public class BaseJavaTest implements RuntimeTestSupport {
|
|||
}
|
||||
}
|
||||
|
||||
public static void writeFile(String dir, String fileName, String content) {
|
||||
try {
|
||||
Utils.writeFile(dir+"/"+fileName, content, "UTF-8");
|
||||
}
|
||||
catch (IOException ioe) {
|
||||
System.err.println("can't write file");
|
||||
ioe.printStackTrace(System.err);
|
||||
}
|
||||
}
|
||||
|
||||
protected void writeTestFile(String parserName,
|
||||
String lexerName,
|
||||
String parserStartRuleName,
|
||||
|
|
|
@ -72,6 +72,7 @@ import java.util.Set;
|
|||
import java.util.TreeMap;
|
||||
|
||||
import static org.antlr.v4.test.runtime.BaseRuntimeTest.antlrOnString;
|
||||
import static org.antlr.v4.test.runtime.BaseRuntimeTest.writeFile;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
@ -646,21 +647,6 @@ public abstract class BaseBrowserTest implements RuntimeTestSupport {
|
|||
}
|
||||
}
|
||||
|
||||
public static void writeFile(String dir, String fileName, String content) {
|
||||
try {
|
||||
File f = new File(dir, fileName);
|
||||
FileWriter w = new FileWriter(f);
|
||||
BufferedWriter bw = new BufferedWriter(w);
|
||||
bw.write(content);
|
||||
bw.close();
|
||||
w.close();
|
||||
}
|
||||
catch (IOException ioe) {
|
||||
System.err.println("can't write file");
|
||||
ioe.printStackTrace(System.err);
|
||||
}
|
||||
}
|
||||
|
||||
protected void mkdir(String dir) {
|
||||
File f = new File(dir);
|
||||
f.mkdirs();
|
||||
|
|
|
@ -64,6 +64,7 @@ import java.util.Set;
|
|||
import java.util.TreeMap;
|
||||
|
||||
import static org.antlr.v4.test.runtime.BaseRuntimeTest.antlrOnString;
|
||||
import static org.antlr.v4.test.runtime.BaseRuntimeTest.writeFile;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
@ -653,35 +654,6 @@ public class BaseNodeTest implements RuntimeTestSupport {
|
|||
}
|
||||
}
|
||||
|
||||
public static void writeFile(String dir, String fileName, String content) {
|
||||
try {
|
||||
File f = new File(dir, fileName);
|
||||
FileWriter w = new FileWriter(f);
|
||||
BufferedWriter bw = new BufferedWriter(w);
|
||||
bw.write(content);
|
||||
bw.close();
|
||||
w.close();
|
||||
} catch (IOException ioe) {
|
||||
System.err.println("can't write file");
|
||||
ioe.printStackTrace(System.err);
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeFile(String dir, String fileName, InputStream content) {
|
||||
try {
|
||||
File f = new File(dir, fileName);
|
||||
OutputStream output = new FileOutputStream(f);
|
||||
while(content.available()>0) {
|
||||
int b = content.read();
|
||||
output.write(b);
|
||||
}
|
||||
output.close();
|
||||
} catch (IOException ioe) {
|
||||
System.err.println("can't write file");
|
||||
ioe.printStackTrace(System.err);
|
||||
}
|
||||
}
|
||||
|
||||
protected void mkdir(String dir) {
|
||||
File f = new File(dir);
|
||||
f.mkdirs();
|
||||
|
|
|
@ -70,6 +70,7 @@ import java.util.Set;
|
|||
import java.util.TreeMap;
|
||||
|
||||
import static org.antlr.v4.test.runtime.BaseRuntimeTest.antlrOnString;
|
||||
import static org.antlr.v4.test.runtime.BaseRuntimeTest.writeFile;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
@ -769,21 +770,6 @@ public abstract class BasePythonTest implements RuntimeTestSupport {
|
|||
}
|
||||
}
|
||||
|
||||
public static void writeFile(String dir, String fileName, String content) {
|
||||
try {
|
||||
File f = new File(dir, fileName);
|
||||
FileWriter w = new FileWriter(f);
|
||||
BufferedWriter bw = new BufferedWriter(w);
|
||||
bw.write(content);
|
||||
bw.close();
|
||||
w.close();
|
||||
}
|
||||
catch (IOException ioe) {
|
||||
System.err.println("can't write file");
|
||||
ioe.printStackTrace(System.err);
|
||||
}
|
||||
}
|
||||
|
||||
protected void mkdir(String dir) {
|
||||
File f = new File(dir);
|
||||
f.mkdirs();
|
||||
|
|
|
@ -9,6 +9,8 @@ package org.antlr.v4.test.runtime.python2;
|
|||
import org.antlr.v4.test.runtime.python.BasePythonTest;
|
||||
import org.stringtemplate.v4.ST;
|
||||
|
||||
import static org.antlr.v4.test.runtime.BaseRuntimeTest.writeFile;
|
||||
|
||||
public class BasePython2Test extends BasePythonTest {
|
||||
|
||||
@Override
|
||||
|
|
|
@ -8,6 +8,8 @@ package org.antlr.v4.test.runtime.python3;
|
|||
import org.antlr.v4.test.runtime.python.BasePythonTest;
|
||||
import org.stringtemplate.v4.ST;
|
||||
|
||||
import static org.antlr.v4.test.runtime.BaseRuntimeTest.writeFile;
|
||||
|
||||
public class BasePython3Test extends BasePythonTest {
|
||||
|
||||
@Override
|
||||
|
|
|
@ -27,6 +27,7 @@ import java.util.List;
|
|||
import java.util.Set;
|
||||
|
||||
import static org.antlr.v4.test.runtime.BaseRuntimeTest.antlrOnString;
|
||||
import static org.antlr.v4.test.runtime.BaseRuntimeTest.writeFile;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class BaseSwiftTest implements RuntimeTestSupport {
|
||||
|
@ -364,20 +365,6 @@ public class BaseSwiftTest implements RuntimeTestSupport {
|
|||
return execTest();
|
||||
}
|
||||
|
||||
public static void writeFile(String dir, String fileName, String content) {
|
||||
try {
|
||||
File f = new File(dir, fileName);
|
||||
FileWriter w = new FileWriter(f);
|
||||
BufferedWriter bw = new BufferedWriter(w);
|
||||
bw.write(content);
|
||||
bw.close();
|
||||
w.close();
|
||||
} catch (IOException ioe) {
|
||||
System.err.println("can't write file");
|
||||
ioe.printStackTrace(System.err);
|
||||
}
|
||||
}
|
||||
|
||||
protected void writeParserTestFile(String parserName,
|
||||
String lexerName,
|
||||
String parserStartRuleName,
|
||||
|
|
Loading…
Reference in New Issue