diff --git a/src/main/java/org/scijava/script/process/ParameterScriptProcessor.java b/src/main/java/org/scijava/script/process/ParameterScriptProcessor.java index fb73cdc16..0ed4d7212 100644 --- a/src/main/java/org/scijava/script/process/ParameterScriptProcessor.java +++ b/src/main/java/org/scijava/script/process/ParameterScriptProcessor.java @@ -129,7 +129,7 @@ public void begin(final ScriptInfo scriptInfo) { @Override public String process(final String line) { - // parse new-style parameters starting with @# anywhere in the script. + // parse new-style parameters starting with #@ anywhere in the script. if (line.matches("^#@.*")) { final int at = line.indexOf('@'); return process(line, line.substring(at + 1)); @@ -140,7 +140,9 @@ public String process(final String line) { // NB: Check if line contains an '@' with no prior alphameric // characters. This assumes that only non-alphanumeric characters can // be used as comment line markers. - if (line.matches("^[^\\w]*@.*")) { + // NB: In addition, to allow for commented-out new-style parameters, we exclude + // lines that have the new-style #@ preceded by non-alphanumeric characters. + if (line.matches("^[^\\w]*[^\\w#]@.*")) { final int at = line.indexOf('@'); return process(line, line.substring(at + 1)); } diff --git a/src/test/java/org/scijava/script/process/ParameterScriptProcessorTest.java b/src/test/java/org/scijava/script/process/ParameterScriptProcessorTest.java new file mode 100644 index 000000000..3e29007bb --- /dev/null +++ b/src/test/java/org/scijava/script/process/ParameterScriptProcessorTest.java @@ -0,0 +1,54 @@ +package org.scijava.script.process; + +import static org.junit.Assert.*; + +import java.io.StringReader; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.scijava.Context; +import org.scijava.script.ScriptInfo; + +public class ParameterScriptProcessorTest { + + private Context context; + + @Before + public void setUp() { + context = new Context(); + } + + @After + public void tearDown() { + context.dispose(); + } + + @Test + public void testScriptParameterParsing() { + String script = "" + // + "% @String legacyStyleParameter\n" + + "% #@ String commentedHeaderParameter\n" + + "% ############## Some Comment ###########\n" + + "#@ String implicitInputParameter\n" + + "#@input String explicitInputParameter\n" + + "\n" + + "% @String legacyStyleBodyParameter\n" + + "% #@ String commentedBodyParameter\n" + + "\n" + + "#@output implicitlyTypedOutputParameter\n" + + "#@output String explicitlyTypedOutputParameter\n"; + final ScriptInfo info = new ScriptInfo(context, ".bsizes", new StringReader(script)); + assertEquals("legacyStyleParameter", info.getInput("legacyStyleParameter").getName()); + assertEquals("implicitInputParameter", info.getInput("implicitInputParameter").getName()); + assertEquals("explicitInputParameter", info.getInput("explicitInputParameter").getName()); + + assertEquals("implicitlyTypedOutputParameter", info.getOutput("implicitlyTypedOutputParameter").getName()); + assertEquals("explicitlyTypedOutputParameter", info.getOutput("explicitlyTypedOutputParameter").getName()); + + assertNull(info.getInput("commentedHeaderParameter")); + assertNull(info.getInput("legacyStyleBodyParameter")); + assertNull(info.getInput("commentedBodyParameter")); + } + +}