Skip to content

Commit

Permalink
[#2342] updated example
Browse files Browse the repository at this point in the history
  • Loading branch information
remkop committed Oct 19, 2024
1 parent 87ee24a commit 4c9045f
Showing 1 changed file with 44 additions and 4 deletions.
48 changes: 44 additions & 4 deletions src/test/java/picocli/Issue2342.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,33 @@ public void testArgsWithSpaces() {
"\"--release 21\"",
"--nowarn"
};
new CommandLine(co)
.setAllowOptionsAsOptionParameters(true)
.parseArgs(args);
new CommandLine(co).parseArgs(args);
List<String> expected = new ArrayList<String>(Arrays.asList(args));
expected.remove(0);

// spaces are preserved, quotes are preserved
System.out.println(co.compilerArguments);
assertEquals(expected, co.compilerArguments);
}

@Test
public void testSingleQuotesAreNotSupported() {
CompileOptions co = new CompileOptions();
String[] args = new String[] {
"--compiler-arguments",
"'--a-param with space'",
"--parameters",
"'--release 21'",
"--nowarn"
};
new CommandLine(co).parseArgs(args);

String[] expected = new String[] {
"'--a-param", "with", "space'", "--parameters", "'--release", "21'", "--nowarn"
};
assertArrayEquals(expected, co.compilerArguments.toArray());
}

@Test
public void testArgsWithSpacesQuotesTrimmed() {
CompileOptions co = new CompileOptions();
Expand All @@ -45,9 +64,11 @@ public void testArgsWithSpacesQuotesTrimmed() {
"--nowarn"
};
new CommandLine(co)
.setAllowOptionsAsOptionParameters(true)
.setTrimQuotes(true)
.parseArgs(args);

// note: .setTrimQuotes(true)
// results in "--a-param with space" being treated as 3 separate values
List<String> expected = Arrays.asList(
"--a-param", "with", "space", "--parameters", "--release", "21", "--nowarn");
assertEquals(expected, co.compilerArguments);
Expand All @@ -64,6 +85,25 @@ public void testArgsSeparateReleaseFrom21() {
"21",
"--nowarn"
};
new CommandLine(co).parseArgs(args);
List<String> expected = new ArrayList<String>(Arrays.asList(args));
expected.remove(0);
assertEquals(expected, co.compilerArguments);
}

@Test
public void testArgsWithOptionLikeValues() {
CompileOptions co = new CompileOptions();
String[] args = new String[] {
"--compiler-arguments",
// need to set .setAllowOptionsAsOptionParameters(true)
// if we want an option to consume other options as parameters
"--compiler-arguments", // <-- value that looks like an option
"\"--a-param with space\"",
"--parameters=--parameters",
"\"--release 21\"",
"--nowarn"
};
new CommandLine(co)
.setAllowOptionsAsOptionParameters(true)
.parseArgs(args);
Expand Down

0 comments on commit 4c9045f

Please sign in to comment.