You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
Sorry if it's a known bug or if I'm missing someting.
Here is my test file below: Arity is 2.
It bugs when the VALUE contains a json string.
import com.beust.jcommander.*;
import java.util.*;
class Test
{
private static final String KEY="key";
private static final String VALUE="{\"a\":1,\"b\":[],\"c\":null}";
@Parameter(names = "-e",arity=2, description = "test")
private List<String> vals = new ArrayList<>();
private void check(boolean b,String msg) {
if(!b) throw new RuntimeException(msg);
}
private void run(final String args[]) {
new JCommander(this).parse(args);
check(vals.size()==2,"args size==2 got "+vals.size()+" "+vals);
check(vals.get(0).equals(KEY),"test k="+KEY);
check(vals.get(1).equals(VALUE),"test v="+VALUE);
System.err.println("OK");
}
public static void main(String[] args) {
args =new String[]{"-e",KEY,VALUE};
new Test().run(args);
}
}
when compiled and executed with 1.72 i've got the following error:
Exception in thread "main" java.lang.RuntimeException: args size==2 got 4 [key, {"a":1, "b":[], "c":null}]
at Test.check(Test.java:13)
at Test.run(Test.java:18)
at Test.main(Test.java:26)
if I replace VALUE with :
private static final String VALUE="A B C D E";
the output is
OK
The text was updated successfully, but these errors were encountered:
FYI:
changing pair1 in the test arityString() produces an error:
diff --git a/src/test/java/com/beust/jcommander/JCommanderTest.java b/src/test/java/com/beust/jcommander/JCommanderTest.java
index a9360ea..877238b 100644
--- a/src/test/java/com/beust/jcommander/JCommanderTest.java+++ b/src/test/java/com/beust/jcommander/JCommanderTest.java@@ -189,13 +189,14 @@ public class JCommanderTest {
public void arityString() {
ArgsArityString args = new ArgsArityString();
- String[] argv = {"-pairs", "pair0", "pair1", "rest"};+ final String PAIR1="{\"a\":1,\"b\":[],\"c\":null}";+ String[] argv = {"-pairs", "pair0", PAIR1, "rest"};
JCommander.newBuilder().addObject(args).build().parse(argv);
Assert.assertEquals(args.pairs.size(), 2);
Assert.assertEquals(args.pairs.get(0), "pair0");
- Assert.assertEquals(args.pairs.get(1), "pair1");+ Assert.assertEquals(args.pairs.get(1), PAIR1);
Assert.assertEquals(args.rest.size(), 1);
Assert.assertEquals(args.rest.get(0), "rest");
}
error:
java.lang.AssertionError: expected [2] but found [4]
at org.testng.Assert.fail(Assert.java:94)
at org.testng.Assert.failNotEquals(Assert.java:513)
at org.testng.Assert.assertEqualsImpl(Assert.java:135)
at org.testng.Assert.assertEquals(Assert.java:116)
at org.testng.Assert.assertEquals(Assert.java:389)
at org.testng.Assert.assertEquals(Assert.java:399)
at com.beust.jcommander.JCommanderTest.arityString(JCommanderTest.java:197)
Hi,
Sorry if it's a known bug or if I'm missing someting.
Here is my test file below: Arity is 2.
It bugs when the VALUE contains a json string.
when compiled and executed with 1.72 i've got the following error:
if I replace VALUE with :
private static final String VALUE="A B C D E";
the output is
OK
The text was updated successfully, but these errors were encountered: