mirror of
https://github.com/processing/processing4.git
synced 2026-01-29 19:31:16 +01:00
Add tests and fix for package name override.
This commit is contained in:
@@ -88,8 +88,12 @@ public class ParserTests {
|
||||
}
|
||||
|
||||
static void expectGood(final String id, boolean ignoreWhitespace) {
|
||||
expectGood(id, ignoreWhitespace, Optional.empty());
|
||||
}
|
||||
|
||||
static void expectGood(final String id, boolean ignoreWhitespace, Optional<String> packageName) {
|
||||
try {
|
||||
final String program = preprocess(id, res(id + ".pde"));
|
||||
final String program = preprocess(id, res(id + ".pde"), packageName);
|
||||
boolean successful = compile(id, program);
|
||||
if (successful) {
|
||||
System.err.println("----------------------------");
|
||||
@@ -368,6 +372,11 @@ public class ParserTests {
|
||||
expectGood("typeinference");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPackage() {
|
||||
expectGood("packageTest", true, Optional.of("test.subtest"));
|
||||
}
|
||||
|
||||
private static boolean compile(String id, String program) {
|
||||
// Create compilable AST to get syntax problems
|
||||
CompilationUnit compilableCU = JdtCompilerUtil.makeAST(
|
||||
|
||||
@@ -5,6 +5,8 @@ import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.StringWriter;
|
||||
import java.util.Optional;
|
||||
|
||||
import processing.app.Preferences;
|
||||
import processing.app.SketchException;
|
||||
import processing.mode.java.preproc.PdePreprocessor;
|
||||
@@ -37,13 +39,23 @@ public class ProcessingTestUtil {
|
||||
|
||||
static String preprocess(final String name, final File resource)
|
||||
throws SketchException {
|
||||
return preprocess(name, resource, Optional.empty());
|
||||
}
|
||||
static String preprocess(final String name, final File resource, Optional<String> optionalPackage)
|
||||
throws SketchException {
|
||||
|
||||
final String program = read(resource);
|
||||
final StringWriter out = new StringWriter();
|
||||
|
||||
PdePreprocessor preprocessor = PdePreprocessor.builderFor(name)
|
||||
.setTabSize(4)
|
||||
.setIsTesting(true)
|
||||
.build();
|
||||
|
||||
PdePreprocessor.PdePreprocessorBuilder builder = PdePreprocessor.builderFor(name);
|
||||
builder.setTabSize(4);
|
||||
builder.setIsTesting(true);
|
||||
|
||||
if (optionalPackage.isPresent()) {
|
||||
builder.setDestinationPackage(optionalPackage.get());
|
||||
}
|
||||
|
||||
PdePreprocessor preprocessor = builder.build();
|
||||
|
||||
PreprocessorResult result = preprocessor.write(out, program);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user