Package

Source Code of ArgParserTest

import junit.framework.TestCase;
import dijjer.util.ArgParser;

public class ArgParserTest extends TestCase {

  public static final String VERSION = "$Id: ArgParserTest.java,v 1.7 2005/04/12 13:04:16 sanity Exp $";

  String arg1Val = null;
  String arg2Val = null;
  boolean arg3Called = false;
  boolean unmatchedCalled = false;

    public void testParse() throws Exception {
      ArgParser parser = new ArgParser("NAME", false);
      parser.addArgument("arg1", "desc1", new ArgParser.ArgumentAction() {
        public void performAction(String arg) throws Exception {
          arg1Val = arg;
        }
      });
      parser.addArgument("arg2", "desc2", new ArgParser.ArgumentAction() {
        public void performAction(String arg) throws Exception {
          arg2Val = arg;
        }
      });
      parser.addArgument("arg3", "desc3", new ArgParser.ArgumentAction() {
        public void performAction(String arg) throws Exception {
          arg3Called = true;
        }
      });
      parser.addUnmatchedKeyArgument("xxx","yyy", new ArgParser.ArgumentAction() {
        public void performAction(String arg) throws Exception {
          unmatchedCalled = true;
        }
      });
      parser.parse(new String[] {"arg1=foo", "arg2=bar"});
      assertEquals("foo", arg1Val);
      assertEquals("bar", arg2Val);
      assertFalse(arg3Called);
      parser.parse(new String[]{"arg3=foo", "arg1=bar"});
      assertEquals("bar", arg1Val);
      assertEquals("bar", arg2Val);
      assertTrue(arg3Called);
      parser.parse(new String[]{"xxx"});
      assertTrue(unmatchedCalled);
    }

}
TOP

Related Classes of ArgParserTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.