|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2024 the original author or authors. |
|
|
|
* Copyright 2002-2025 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -46,7 +46,7 @@ class SimpleCommandLineArgsParserTests { |
|
|
|
void withSingleOptionAndNoValue() { |
|
|
|
void withSingleOptionAndNoValue() { |
|
|
|
CommandLineArgs args = parser.parse("--o1"); |
|
|
|
CommandLineArgs args = parser.parse("--o1"); |
|
|
|
assertThat(args.containsOption("o1")).isTrue(); |
|
|
|
assertThat(args.containsOption("o1")).isTrue(); |
|
|
|
assertThat(args.getOptionValues("o1")).isEqualTo(Collections.EMPTY_LIST); |
|
|
|
assertThat(args.getOptionValues("o1")).isEmpty(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@ -56,6 +56,20 @@ class SimpleCommandLineArgsParserTests { |
|
|
|
assertThat(args.getOptionValues("o1")).containsExactly("v1"); |
|
|
|
assertThat(args.getOptionValues("o1")).containsExactly("v1"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
void withRepeatedOptionAndSameValues() { |
|
|
|
|
|
|
|
CommandLineArgs args = parser.parse("--o1=v1", "--o1=v1", "--o1=v1"); |
|
|
|
|
|
|
|
assertThat(args.containsOption("o1")).isTrue(); |
|
|
|
|
|
|
|
assertThat(args.getOptionValues("o1")).containsExactly("v1", "v1", "v1"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
void withRepeatedOptionAndDifferentValues() { |
|
|
|
|
|
|
|
CommandLineArgs args = parser.parse("--o1=v1", "--o1=v2", "--o1=v3"); |
|
|
|
|
|
|
|
assertThat(args.containsOption("o1")).isTrue(); |
|
|
|
|
|
|
|
assertThat(args.getOptionValues("o1")).containsExactly("v1", "v2", "v3"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
void withMixOfOptionsHavingValueAndOptionsHavingNoValue() { |
|
|
|
void withMixOfOptionsHavingValueAndOptionsHavingNoValue() { |
|
|
|
CommandLineArgs args = parser.parse("--o1=v1", "--o2"); |
|
|
|
CommandLineArgs args = parser.parse("--o1=v1", "--o2"); |
|
|
|
@ -95,17 +109,17 @@ class SimpleCommandLineArgsParserTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
void assertOptionNamesIsUnmodifiable() { |
|
|
|
void optionNamesSetIsUnmodifiable() { |
|
|
|
CommandLineArgs args = new SimpleCommandLineArgsParser().parse(); |
|
|
|
CommandLineArgs args = new SimpleCommandLineArgsParser().parse(); |
|
|
|
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> |
|
|
|
assertThatExceptionOfType(UnsupportedOperationException.class) |
|
|
|
args.getOptionNames().add("bogus")); |
|
|
|
.isThrownBy(() -> args.getOptionNames().add("bogus")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
void assertNonOptionArgsIsUnmodifiable() { |
|
|
|
void nonOptionArgsListIsUnmodifiable() { |
|
|
|
CommandLineArgs args = new SimpleCommandLineArgsParser().parse(); |
|
|
|
CommandLineArgs args = new SimpleCommandLineArgsParser().parse(); |
|
|
|
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> |
|
|
|
assertThatExceptionOfType(UnsupportedOperationException.class) |
|
|
|
args.getNonOptionArgs().add("foo")); |
|
|
|
.isThrownBy(() -> args.getNonOptionArgs().add("foo")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
|