예제 #1
0
 public void testInnerQuotesMultipleSet() {
   String argId = "-Dtest";
   String folder = "my folder";
   String args = argId + EQ + QUOTE + folder + QUOTE;
   String args2 = ArgsUtil.setArg(args, null, argId, folder + "2");
   assertTrue(args2.trim().equals(argId + EQ + QUOTE + folder + "2" + QUOTE));
   args2 = ArgsUtil.setArg(args2, null, argId, folder + "3");
   assertTrue(args2.trim().equals(argId + EQ + QUOTE + folder + "3" + QUOTE));
 }
예제 #2
0
  public void testOuterQuoteMultipleSet() {
    String argId = "-Dtest";
    String folder = "my folder";
    String args = QUOTE + argId + EQ + folder + QUOTE;
    String args2 = ArgsUtil.setArg(args, null, argId, folder);
    assertTrue(args2.trim().equals(args));

    String args3 = ArgsUtil.setArg(args2, null, argId, folder + "2");
    assertTrue(args3.trim().equals(QUOTE + argId + EQ + folder + "2" + QUOTE));
  }
예제 #3
0
  public void testSetToNulLWithQuotes() {
    String argId = "-Dtest";
    String folder = "my folder";

    String args = QUOTE + argId + EQ + folder + QUOTE;
    String args2 = ArgsUtil.setArg(args, null, argId, null, true);
    assertTrue(args2.trim().equals(""));
  }
예제 #4
0
  public void testReplace() {
    String allArgs = "";
    allArgs = ArgsUtil.setArg(allArgs, "-h", null, "new");
    assertTrue(ArgsUtil.parse(allArgs).length == 2);
    assertTrue(ArgsUtil.getValue(allArgs, "-h", null).equals("new"));
    allArgs = ArgsUtil.setArg(allArgs, "-h", null, "correct");
    assertTrue(ArgsUtil.parse(allArgs).length == 2);
    assertTrue(ArgsUtil.getValue(allArgs, "-h", null).equals("correct"));

    allArgs = ArgsUtil.setArg(allArgs, null, "--two", "newtwo");
    assertTrue(ArgsUtil.parse(allArgs).length == 3);

    // opt was set as long opt,  --two=newtwo.   Search for short opt fails
    assertTrue(ArgsUtil.getValue(allArgs, "--two", null) == null);

    // clear long opt
    allArgs = ArgsUtil.setArg(allArgs, null, "--two", null);
    assertTrue(ArgsUtil.parse(allArgs).length == 2);

    // test replacement of short args
    allArgs = ArgsUtil.setArg(allArgs, new String[] {"-h", "-o"}, new String[] {}, "twoOpt", false);
    assertTrue(ArgsUtil.parse(allArgs).length == 2); // no change

    assertTrue(ArgsUtil.getValue(allArgs, "-h", null).equals("twoOpt"));
    assertTrue(ArgsUtil.getValue(allArgs, new String[] {"-h", "-o"}, null).equals("twoOpt"));
    assertTrue(ArgsUtil.getValue(allArgs, new String[] {"-o", "-h"}, null).equals("twoOpt"));

    // test clear of short arg
    allArgs = ArgsUtil.setArg(allArgs, new String[] {"-h", "-o"}, new String[] {}, null, false);
    assertTrue(ArgsUtil.parse(allArgs).length == 1); // no change

    allArgs = ArgsUtil.setArg(allArgs, null, "--three", "three");
    assertTrue(ArgsUtil.getValue(allArgs, null, "--three").equals("three"));

    allArgs = ArgsUtil.setArg(allArgs, null, "--three", "threea");
    assertTrue(ArgsUtil.getValue(allArgs, null, "--three").equals("threea"));

    // already has --three,  test replace, ensure --four is the new arg
    // since it is the first of the two acceptable replacements
    assertTrue(allArgs.contains("--three"));
    allArgs = ArgsUtil.setArg(allArgs, null, new String[] {"--four", "--three"}, "three_b", false);
    assertTrue(allArgs.contains("--four"));
    assertTrue(ArgsUtil.getValue(allArgs, null, "--three") == null);
    assertTrue(ArgsUtil.getValue(allArgs, null, "--four").equals("three_b"));
    assertTrue(
        ArgsUtil.getValue(allArgs, null, new String[] {"--three", "--four"}).equals("three_b"));
  }