Skip to content

Commit

Permalink
[#2342] Add example
Browse files Browse the repository at this point in the history
  • Loading branch information
remkop committed Oct 19, 2024
1 parent a856a14 commit 87ee24a
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions src/test/java/picocli/Issue2342.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package picocli;

import org.junit.Test;
import picocli.CommandLine.Option;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import static org.junit.Assert.*;

public class Issue2342 {
static class CompileOptions {
@Option(names = { "--compiler-arguments" }, split = " ", arity = "*",
description = "Compiler arguments to use to compile generated sources.")
private List<String> compilerArguments;
}

@Test
public void testArgsWithSpaces() {
CompileOptions co = new CompileOptions();
String[] args = new String[] {
"--compiler-arguments",
"\"--a-param with space\"",
"--parameters",
"\"--release 21\"",
"--nowarn"
};
new CommandLine(co)
.setAllowOptionsAsOptionParameters(true)
.parseArgs(args);
List<String> expected = new ArrayList<String>(Arrays.asList(args));
expected.remove(0);
assertEquals(expected, co.compilerArguments);
}

@Test
public void testArgsWithSpacesQuotesTrimmed() {
CompileOptions co = new CompileOptions();
String[] args = new String[] {
"--compiler-arguments",
"\"--a-param with space\"",
"--parameters",
"\"--release 21\"",
"--nowarn"
};
new CommandLine(co)
.setAllowOptionsAsOptionParameters(true)
.setTrimQuotes(true)
.parseArgs(args);
List<String> expected = Arrays.asList(
"--a-param", "with", "space", "--parameters", "--release", "21", "--nowarn");
assertEquals(expected, co.compilerArguments);
}

@Test
public void testArgsSeparateReleaseFrom21() {
CompileOptions co = new CompileOptions();
String[] args = new String[] {
"--compiler-arguments",
"\"--a-param with space\"",
"--parameters",
"--release",
"21",
"--nowarn"
};
new CommandLine(co)
.setAllowOptionsAsOptionParameters(true)
.parseArgs(args);
List<String> expected = new ArrayList<String>(Arrays.asList(args));
expected.remove(0);
assertEquals(expected, co.compilerArguments);
}
}

0 comments on commit 87ee24a

Please sign in to comment.