Skip to content

Commit 10ac353

Browse files
authored
Merge pull request #403 from scijava/fix-commented-parameters
Always ignore commented script parameters
2 parents 3d64e2a + b1bab69 commit 10ac353

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

src/main/java/org/scijava/script/process/ParameterScriptProcessor.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public void begin(final ScriptInfo scriptInfo) {
129129

130130
@Override
131131
public String process(final String line) {
132-
// parse new-style parameters starting with @# anywhere in the script.
132+
// parse new-style parameters starting with #@ anywhere in the script.
133133
if (line.matches("^#@.*")) {
134134
final int at = line.indexOf('@');
135135
return process(line, line.substring(at + 1));
@@ -140,7 +140,9 @@ public String process(final String line) {
140140
// NB: Check if line contains an '@' with no prior alphameric
141141
// characters. This assumes that only non-alphanumeric characters can
142142
// be used as comment line markers.
143-
if (line.matches("^[^\\w]*@.*")) {
143+
// NB: In addition, to allow for commented-out new-style parameters, we exclude
144+
// lines that have the new-style #@ preceded by non-alphanumeric characters.
145+
if (line.matches("^[^\\w]*[^\\w#]@.*")) {
144146
final int at = line.indexOf('@');
145147
return process(line, line.substring(at + 1));
146148
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package org.scijava.script.process;
2+
3+
import static org.junit.Assert.*;
4+
5+
import java.io.StringReader;
6+
7+
import org.junit.After;
8+
import org.junit.Before;
9+
import org.junit.Test;
10+
import org.scijava.Context;
11+
import org.scijava.script.ScriptInfo;
12+
13+
public class ParameterScriptProcessorTest {
14+
15+
private Context context;
16+
17+
@Before
18+
public void setUp() {
19+
context = new Context();
20+
}
21+
22+
@After
23+
public void tearDown() {
24+
context.dispose();
25+
}
26+
27+
@Test
28+
public void testScriptParameterParsing() {
29+
String script = "" + //
30+
"% @String legacyStyleParameter\n" +
31+
"% #@ String commentedHeaderParameter\n" +
32+
"% ############## Some Comment ###########\n" +
33+
"#@ String implicitInputParameter\n" +
34+
"#@input String explicitInputParameter\n" +
35+
"\n" +
36+
"% @String legacyStyleBodyParameter\n" +
37+
"% #@ String commentedBodyParameter\n" +
38+
"\n" +
39+
"#@output implicitlyTypedOutputParameter\n" +
40+
"#@output String explicitlyTypedOutputParameter\n";
41+
final ScriptInfo info = new ScriptInfo(context, ".bsizes", new StringReader(script));
42+
assertEquals("legacyStyleParameter", info.getInput("legacyStyleParameter").getName());
43+
assertEquals("implicitInputParameter", info.getInput("implicitInputParameter").getName());
44+
assertEquals("explicitInputParameter", info.getInput("explicitInputParameter").getName());
45+
46+
assertEquals("implicitlyTypedOutputParameter", info.getOutput("implicitlyTypedOutputParameter").getName());
47+
assertEquals("explicitlyTypedOutputParameter", info.getOutput("explicitlyTypedOutputParameter").getName());
48+
49+
assertNull(info.getInput("commentedHeaderParameter"));
50+
assertNull(info.getInput("legacyStyleBodyParameter"));
51+
assertNull(info.getInput("commentedBodyParameter"));
52+
}
53+
54+
}

0 commit comments

Comments
 (0)