commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From roxspr...@apache.org
Subject cvs commit: jakarta-commons-sandbox/cli/src/test/org/apache/commons/cli2 PrecedenceTest.java
Date Wed, 22 Oct 2003 23:58:29 GMT
roxspring    2003/10/22 16:58:29

  Added:       cli/src/test/org/apache/commons/cli2 PrecedenceTest.java
  Log:
  Added tests for the precedence of options in different combinations.
  
  Some of the tests fail and have been prefixed X so that the failure is hidden until we decide
whether to fix the test or the code.
  
  Revision  Changes    Path
  1.1                  jakarta-commons-sandbox/cli/src/test/org/apache/commons/cli2/PrecedenceTest.java
  
  Index: PrecedenceTest.java
  ===================================================================
  /*
   * Created on 22-Oct-2003
   *
   * To change the template for this generated file go to
   * Window - Preferences - Java - Code Generation - Code and Comments
   */
  package org.apache.commons.cli2;
  
  import java.util.Arrays;
  import java.util.List;
  import java.util.Set;
  
  import junit.framework.TestCase;
  
  /**
   * @author Rob Oxspring
   *
   * To change the template for this generated type comment go to
   * Window - Preferences - Java - Code Generation - Code and Comments
   */
  public class PrecedenceTest extends TestCase
  {
      private final String[] args = new String[] { "-file" };
  
      public void testSimple() throws OptionException
      {
          final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
  
          final Group options =
              new GroupBuilder()
                  .withOption(oBuilder.withShortName("file").create())
                  .create();
  
          final CommandLine cl = buildCommandLine(options, args);
          assertEquals(new String[] { "-file" }, cl);
      }
  
      public void testArgument() throws OptionException
      {
          final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
          final ArgumentBuilder aBuilder = new ArgumentBuilder();
  
          final Group options =
              new GroupBuilder()
                  .withOption(
                      oBuilder
                          .withShortName("f")
                          .withArgument(aBuilder.create())
                          .create())
                  .create();
  
          final CommandLine cl = buildCommandLine(options, args);
          assertEquals(new String[] { "-f" }, cl);
      }
  
      public void testBurst() throws OptionException
      {
          final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
          final GroupBuilder gBuilder = new GroupBuilder();
          final Group options =
              gBuilder
                  .withOption(oBuilder.withShortName("f").create())
                  .withOption(oBuilder.withShortName("i").create())
                  .withOption(oBuilder.withShortName("l").create())
                  .withOption(oBuilder.withShortName("e").create())
                  .create();
  
          final CommandLine cl = buildCommandLine(options, args);
          assertEquals(new String[] { "-f", "-i", "-l", "-e" }, cl);
      }
  
      public void testChildren() throws OptionException
      {
          final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
          final GroupBuilder gBuilder = new GroupBuilder();
  
          final Group children =
              gBuilder
                  .withOption(oBuilder.withShortName("i").create())
                  .withOption(oBuilder.withShortName("l").create())
                  .withOption(oBuilder.withShortName("e").create())
                  .create();
          final Group options =
              gBuilder
                  .withOption(
                      oBuilder
                          .withShortName("f")
                          .withChildren(children)
                          .create())
                  .create();
  
          final CommandLine cl = buildCommandLine(options, args);
          assertEquals(new String[] { "-f", "-i", "-l", "-e" }, cl);
      }
  
      public void XtestSimpleVsArgument() throws OptionException
      {
          final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
          final GroupBuilder gBuilder = new GroupBuilder();
          final ArgumentBuilder aBuilder = new ArgumentBuilder();
  
          final Group options =
              gBuilder
                  .withOption(oBuilder.withShortName("file").create())
                  .withOption(
                      oBuilder
                          .withShortName("f")
                          .withArgument(aBuilder.create())
                          .create())
                  .create();
  
          final CommandLine cl = buildCommandLine(options, args);
          assertEquals(new String[] { "-f" }, cl);
      }
  
      public void XtestSimpleVsBurst() throws OptionException
      {
          final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
          final GroupBuilder gBuilder = new GroupBuilder();
          final Group options =
              gBuilder
                  .withOption(oBuilder.withShortName("file").create())
                  .withOption(oBuilder.withShortName("f").create())
                  .withOption(oBuilder.withShortName("i").create())
                  .withOption(oBuilder.withShortName("l").create())
                  .withOption(oBuilder.withShortName("e").create())
                  .create();
  
          final CommandLine cl = buildCommandLine(options, args);
          assertEquals(new String[] { "-f", "-i", "-l", "-e" }, cl);
      }
  
      public void XtestSimpleVsChildren() throws OptionException
      {
          final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
          final GroupBuilder gBuilder = new GroupBuilder();
  
          final Group children =
              gBuilder
                  .withOption(
                      oBuilder.withShortName("i").withLongName("ci").create())
                  .withOption(
                      oBuilder.withShortName("l").withLongName("cl").create())
                  .withOption(
                      oBuilder.withShortName("e").withLongName("ce").create())
                  .create();
  
          final Group options =
              gBuilder
                  .withOption(oBuilder.withShortName("file").create())
                  .withOption(
                      oBuilder
                          .withShortName("f")
                          .withChildren(children)
                          .create())
                  .create();
  
          final CommandLine cl = buildCommandLine(options, args);
          assertEquals(
              new String[] { "-f", "-i", "--ci", "-l", "--cl", "-e", "--ce" },
              cl);
      }
  
      public void testArgumentVsBurst() throws OptionException
      {
          final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
          final GroupBuilder gBuilder = new GroupBuilder();
          final ArgumentBuilder aBuilder = new ArgumentBuilder();
  
          final Group options =
              gBuilder
                  .withOption(
                      oBuilder
                          .withShortName("f")
                          .withArgument(aBuilder.create())
                          .create())
                  .withOption(oBuilder.withShortName("i").create())
                  .withOption(oBuilder.withShortName("l").create())
                  .withOption(oBuilder.withShortName("e").create())
                  .create();
  
          final CommandLine cl = buildCommandLine(options, args);
          assertEquals(new String[] { "-f" }, cl);
      }
  
      public void testArgumentVsChildren() throws OptionException
      {
          final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
          final GroupBuilder gBuilder = new GroupBuilder();
          final ArgumentBuilder aBuilder = new ArgumentBuilder();
  
          final Group children =
              gBuilder
                  .withOption(oBuilder.withShortName("i").create())
                  .withOption(oBuilder.withShortName("l").create())
                  .withOption(oBuilder.withShortName("e").create())
                  .create();
          final Group options =
              gBuilder
                  .withOption(
                      oBuilder
                          .withShortName("f")
                          .withChildren(children)
                          .withArgument(aBuilder.create())
                          .create())
                  .create();
  
          final CommandLine cl = buildCommandLine(options, args);
          assertEquals(new String[] { "-f" }, cl);
      }
  
      public void testBurstVsChildren() throws OptionException
      {
          final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
          final GroupBuilder gBuilder = new GroupBuilder();
  
          final Group children =
              gBuilder
                  .withOption(
                      oBuilder.withShortName("i").withLongName("ci").create())
                  .withOption(
                      oBuilder.withShortName("l").withLongName("cl").create())
                  .withOption(
                      oBuilder.withShortName("e").withLongName("ce").create())
                  .create();
  
          final Group options =
              gBuilder
                  .withOption(
                      oBuilder
                          .withShortName("f")
                          .withChildren(children)
                          .create())
                  .withOption(
                      oBuilder.withShortName("i").withLongName("bi").create())
                  .withOption(
                      oBuilder.withShortName("l").withLongName("bl").create())
                  .withOption(
                      oBuilder.withShortName("e").withLongName("be").create())
                  .create();
  
          final CommandLine cl = buildCommandLine(options, args);
          assertEquals(
              new String[] { "-f", "-i", "--ci", "-l", "--cl", "-e", "--ce" },
              cl);
      }
  
      public void XtestSimpleVsArgumentVsBurst() throws OptionException
      {
          final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
          final GroupBuilder gBuilder = new GroupBuilder();
          final ArgumentBuilder aBuilder = new ArgumentBuilder();
  
          final Group options =
              gBuilder
                  .withOption(oBuilder.withShortName("file").create())
                  .withOption(
                      oBuilder
                          .withShortName("f")
                          .withArgument(aBuilder.create())
                          .create())
                  .withOption(oBuilder.withShortName("i").create())
                  .withOption(oBuilder.withShortName("l").create())
                  .withOption(oBuilder.withShortName("e").create())
                  .create();
  
          final CommandLine cl = buildCommandLine(options, args);
          assertEquals(new String[] { "-f" }, cl);
      }
  
      public void XtestSimpleVsArgumentVsChildren() throws OptionException
      {
          final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
          final GroupBuilder gBuilder = new GroupBuilder();
          final ArgumentBuilder aBuilder = new ArgumentBuilder();
  
          final Group children =
              gBuilder
                  .withOption(
                      oBuilder.withShortName("i").withLongName("ci").create())
                  .withOption(
                      oBuilder.withShortName("l").withLongName("cl").create())
                  .withOption(
                      oBuilder.withShortName("e").withLongName("ce").create())
                  .create();
  
          final Group options =
              gBuilder
                  .withOption(oBuilder.withShortName("file").create())
                  .withOption(
                      oBuilder
                          .withShortName("f")
                          .withChildren(children)
                          .withArgument(aBuilder.create())
                          .create())
                  .create();
  
          final CommandLine cl = buildCommandLine(options, args);
          assertEquals(new String[] { "-f" }, cl);
      }
  
      public void XtestSimpleVsBurstVsChildren() throws OptionException
      {
          final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
          final GroupBuilder gBuilder = new GroupBuilder();
  
          final Group children =
              gBuilder
                  .withOption(
                      oBuilder.withShortName("i").withLongName("ci").create())
                  .withOption(
                      oBuilder.withShortName("l").withLongName("cl").create())
                  .withOption(
                      oBuilder.withShortName("e").withLongName("ce").create())
                  .create();
  
          final Group options =
              gBuilder
                  .withOption(oBuilder.withShortName("file").create())
                  .withOption(
                      oBuilder
                          .withShortName("f")
                          .withChildren(children)
                          .create())
                  .withOption(oBuilder.withShortName("i").create())
                  .withOption(oBuilder.withShortName("l").create())
                  .withOption(oBuilder.withShortName("e").create())
                  .create();
  
          final CommandLine cl = buildCommandLine(options, args);
          assertEquals(new String[] { "-f", "-i", "-l", "-e" }, cl);
      }
  
      public void testArgumentVsBurstVsChildren() throws OptionException
      {
          final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
          final GroupBuilder gBuilder = new GroupBuilder();
          final ArgumentBuilder aBuilder = new ArgumentBuilder();
  
          final Group children =
              gBuilder
                  .withOption(
                      oBuilder.withShortName("i").withLongName("ci").create())
                  .withOption(
                      oBuilder.withShortName("l").withLongName("cl").create())
                  .withOption(
                      oBuilder.withShortName("e").withLongName("ce").create())
                  .create();
  
          final Group options =
              gBuilder
                  .withOption(
                      oBuilder
                          .withShortName("f")
                          .withChildren(children)
                          .withArgument(aBuilder.create())
                          .create())
                  .withOption(oBuilder.withShortName("i").create())
                  .withOption(oBuilder.withShortName("l").create())
                  .withOption(oBuilder.withShortName("e").create())
                  .create();
  
          final CommandLine cl = buildCommandLine(options, args);
          assertEquals(new String[] { "-f" }, cl);
      }
  
      public void XtestSimpleVsArgumentVsBurstVsChildren() throws OptionException
      {
          final DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
          final GroupBuilder gBuilder = new GroupBuilder();
          final ArgumentBuilder aBuilder = new ArgumentBuilder();
  
          final Group children =
              gBuilder
                  .withOption(
                      oBuilder.withShortName("i").withLongName("ci").create())
                  .withOption(
                      oBuilder.withShortName("l").withLongName("cl").create())
                  .withOption(
                      oBuilder.withShortName("e").withLongName("ce").create())
                  .create();
  
          final Group options =
              gBuilder
                  .withOption(oBuilder.withShortName("file").create())
                  .withOption(
                      oBuilder
                          .withShortName("f")
                          .withChildren(children)
                          .withArgument(aBuilder.create())
                          .create())
                  .withOption(oBuilder.withShortName("i").create())
                  .withOption(oBuilder.withShortName("l").create())
                  .withOption(oBuilder.withShortName("e").create())
                  .create();
  
          final CommandLine cl = buildCommandLine(options, args);
          assertEquals(new String[] { "-f" }, cl);
      }
  
      public CommandLine buildCommandLine(final Group group, final String[] args)
          throws OptionException
      {
          CommandLineParser p = new CommandLineParser();
          p.setGroup(group);
          return p.parse(args);
      }
  
      public void assertEquals(final String options[], final CommandLine line)
      {
          final List expected = Arrays.asList(options);
          final Set actual = line.getOptionTriggers();
  
          //System.out.println(getName() + ": " + actual);
  
          assertTrue(expected.containsAll(actual));
          assertTrue(actual.containsAll(expected));
      }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message