|
11 | 11 | import picocli.CommandLine.ParameterException;
|
12 | 12 | import picocli.CommandLine.Parameters;
|
13 | 13 |
|
| 14 | +import java.util.Arrays; |
14 | 15 | import java.util.Collection;
|
15 | 16 | import java.util.Collections;
|
16 | 17 | import java.util.List;
|
@@ -185,4 +186,45 @@ public void testIssue1904CollectionFallback_positional_map() {
|
185 | 186 | assertEquals(Collections.singletonList(Issue1904.DebugFacility.DEFAULT), obj.facilities);
|
186 | 187 | assertEquals(Collections.singletonMap(Issue1904.DebugFacility.FALLBACK, "1"), obj.map);
|
187 | 188 | }
|
| 189 | + |
| 190 | + @Command |
| 191 | + static class Issue1993 { |
| 192 | + @Option(names = {"--list"}, arity = "0..1", fallbackValue = CommandLine.Option.NULL_VALUE) |
| 193 | + List<String> list; |
| 194 | + |
| 195 | + @Option(names = {"--array"}, arity = "0..1", fallbackValue = CommandLine.Option.NULL_VALUE) |
| 196 | + String[] array; |
| 197 | + |
| 198 | + @Option(names = {"--map"}, arity = "0..1", fallbackValue = "KEY="+CommandLine.Option.NULL_VALUE) |
| 199 | + Map<String, String> map; |
| 200 | + } |
| 201 | + |
| 202 | + @Test |
| 203 | + public void testIssue1993List() { |
| 204 | + Issue1993 main = new Issue1993(); |
| 205 | + CommandLine commandLine = new CommandLine(main); |
| 206 | + commandLine.parseArgs("--list", "--list", "pepa"); |
| 207 | + |
| 208 | + assertEquals(Arrays.asList(null, "pepa"), main.list); |
| 209 | + } |
| 210 | + |
| 211 | + @Test |
| 212 | + public void testIssue1993Array() { |
| 213 | + Issue1993 main = new Issue1993(); |
| 214 | + CommandLine commandLine = new CommandLine(main); |
| 215 | + commandLine.parseArgs("--array", "--array", "FOO"); |
| 216 | + |
| 217 | + assertArrayEquals(new String[]{null, "FOO"}, main.array); |
| 218 | + } |
| 219 | + |
| 220 | + @Test |
| 221 | + public void testIssue1993Map() { |
| 222 | + Issue1993 main = new Issue1993(); |
| 223 | + CommandLine commandLine = new CommandLine(main); |
| 224 | + commandLine.parseArgs("--map", "--map", "FOO=123"); |
| 225 | + |
| 226 | + // Should this sentinel value be replaced with Java `null`? |
| 227 | + Map<String, String> expected = TestUtil.mapOf("KEY", CommandLine.Option.NULL_VALUE, "FOO", "123"); |
| 228 | + assertEquals(expected, main.map); |
| 229 | + } |
188 | 230 | }
|
0 commit comments