Skip to content

Always ignore commented script parameters #403

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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"));
}

}