Package org.jnode.shell

Examples of org.jnode.shell.CommandLine


    public void testOneToTwo() throws Exception {
        TestShell shell = new TestShell();
        shell.addAlias("cmd", "org.jnode.test.shell.syntax.RepeatSyntaxTest$Test");
        shell.addSyntax("cmd", new RepeatSyntax(new ArgumentSyntax("arg1"), 1, 2));

        CommandLine cl;
        CommandInfo cmdInfo;
        Command cmd;

        try {
            cl = new CommandLine(new Token("cmd"), new Token[] {}, null);
            cl.parseCommandLine(shell);
            Assert.fail("no exception");
        } catch (CommandSyntaxException ex) {
            // expected
        }

        cl = new CommandLine(new Token("cmd"), new Token[] {new Token("F1")}, null);
        cmdInfo = cl.parseCommandLine(shell);
        cmd = cmdInfo.createCommandInstance();
        Assert.assertEquals(1, cmd.getArgumentBundle().getArgument("arg1").getValues().length);

        cl =
                new CommandLine(new Token("cmd"), new Token[] {new Token("F1"), new Token("F1")},
                        null);
        cmdInfo = cl.parseCommandLine(shell);
        cmd = cmdInfo.createCommandInstance();
        Assert.assertEquals(2, cmd.getArgumentBundle().getArgument("arg1").getValues().length);

        try {
            cl =
                    new CommandLine(new Token("cmd"), new Token[] {new Token("F1"),
                        new Token("F1"), new Token("F1")}, null);
            cl.parseCommandLine(shell);
            Assert.fail("no exception");
        } catch (CommandSyntaxException ex) {
            // expected
        }
    }
View Full Code Here


    public void testThreeToSix() throws Exception {
        TestShell shell = new TestShell();
        shell.addAlias("cmd", "org.jnode.test.shell.syntax.RepeatSyntaxTest$Test");
        shell.addSyntax("cmd", new RepeatSyntax(new ArgumentSyntax("arg1"), 3, 6));

        CommandLine cl;
        CommandInfo cmdInfo;
        @SuppressWarnings("unused")
        Command cmd;

        try {
            cl = new CommandLine(new Token("cmd"), new Token[] {}, null);
            cl.parseCommandLine(shell);
            Assert.fail("no exception");
        } catch (CommandSyntaxException ex) {
            // expected
        }

        try {
            cl = new CommandLine(new Token("cmd"), new Token[] {new Token("F1")}, null);
            cl.parseCommandLine(shell);
        } catch (CommandSyntaxException ex) {
            // expected
        }

        try {
            cl = new CommandLine(new Token("cmd"), new Token[] {new Token("F1"), new Token("F1")}, null);
            cl.parseCommandLine(shell);
        } catch (CommandSyntaxException ex) {
            // expected
        }

        cl = new CommandLine(new Token("cmd"), new Token[] {new Token("F1"), new Token("F1"), new Token("F1")}, null);
        cmdInfo = cl.parseCommandLine(shell);
        cmd = cmdInfo.createCommandInstance();

        cl = new CommandLine(new Token("cmd"), new Token[] {new Token("F1"), new Token("F1"), new Token("F1"),
            new Token("F1")}, null);
        cmdInfo = cl.parseCommandLine(shell);
        cmd = cmdInfo.createCommandInstance();

        cl = new CommandLine(new Token("cmd"), new Token[] {new Token("F1"), new Token("F1"), new Token("F1"),
            new Token("F1"), new Token("F1")}, null);
        cmdInfo = cl.parseCommandLine(shell);
        cmd = cmdInfo.createCommandInstance();

        cl = new CommandLine(new Token("cmd"), new Token[] {new Token("F1"), new Token("F1"), new Token("F1"),
            new Token("F1"), new Token("F1"), new Token("F1")}, null);
        cmdInfo = cl.parseCommandLine(shell);
        cmd = cmdInfo.createCommandInstance();

        try {
            cl = new CommandLine(new Token("cmd"), new Token[] {new Token("F1"), new Token("F1"), new Token("F1"),
                new Token("F1"), new Token("F1"), new Token("F1"), new Token("F1")}, null);
            cl.parseCommandLine(shell);
            Assert.fail("no exception");
        } catch (CommandSyntaxException ex) {
            // expected
        }
    }
View Full Code Here

        TestShell shell = new TestShell();
        shell.addAlias("cmd", "org.jnode.test.shell.syntax.RepeatSyntaxTest$Test");
        shell.addSyntax("cmd", new SequenceSyntax(new RepeatSyntax(new ArgumentSyntax("arg1")),
                new RepeatSyntax(new ArgumentSyntax("arg2"))));

        CommandLine cl = new CommandLine(new Token("cmd"), new Token[] {}, null);
        CommandInfo cmdInfo = cl.parseCommandLine(shell);
        Command cmd = cmdInfo.createCommandInstance();
        Assert.assertEquals(0, cmd.getArgumentBundle().getArgument("arg1").getValues().length);
        Assert.assertEquals(0, cmd.getArgumentBundle().getArgument("arg2").getValues().length);

        cl = new CommandLine(new Token("cmd"), new Token[] {new Token("F1")}, null);
        cmdInfo = cl.parseCommandLine(shell);
        cmd = cmdInfo.createCommandInstance();
        Assert.assertEquals(0, cmd.getArgumentBundle().getArgument("arg1").getValues().length);
        Assert.assertEquals(1, cmd.getArgumentBundle().getArgument("arg2").getValues().length);

        cl = new CommandLine(new Token("cmd"), new Token[] {new Token("F1"), new Token("F1")}, null);
        cmdInfo = cl.parseCommandLine(shell);
        cmd = cmdInfo.createCommandInstance();
        Assert.assertEquals(0, cmd.getArgumentBundle().getArgument("arg1").getValues().length);
        Assert.assertEquals(2, cmd.getArgumentBundle().getArgument("arg2").getValues().length);
    }
View Full Code Here

        TestShell shell = new TestShell();
        shell.addAlias("cmd", "org.jnode.test.shell.syntax.RepeatSyntaxTest$Test");
        shell.addSyntax("cmd", new SequenceSyntax(new RepeatSyntax(null, new ArgumentSyntax("arg1"), 0,
            Integer.MAX_VALUE, true, null), new RepeatSyntax(new ArgumentSyntax("arg2"))));

        CommandLine cl = new CommandLine(new Token("cmd"), new Token[] {}, null);
        CommandInfo cmdInfo = cl.parseCommandLine(shell);
        Command cmd = cmdInfo.createCommandInstance();
        Assert.assertEquals(0, cmd.getArgumentBundle().getArgument("arg1").getValues().length);
        Assert.assertEquals(0, cmd.getArgumentBundle().getArgument("arg2").getValues().length);

        cl = new CommandLine(new Token("cmd"), new Token[] {new Token("F1")}, null);
        cmdInfo = cl.parseCommandLine(shell);
        cmd = cmdInfo.createCommandInstance();
        Assert.assertEquals(1, cmd.getArgumentBundle().getArgument("arg1").getValues().length);
        Assert.assertEquals(0, cmd.getArgumentBundle().getArgument("arg2").getValues().length);

        cl = new CommandLine(new Token("cmd"), new Token[] {new Token("F1"), new Token("F1")}, null);
        cmdInfo = cl.parseCommandLine(shell);
        cmd = cmdInfo.createCommandInstance();
        Assert.assertEquals(2, cmd.getArgumentBundle().getArgument("arg1").getValues().length);
        Assert.assertEquals(0, cmd.getArgumentBundle().getArgument("arg2").getValues().length);
    }
View Full Code Here

    @Test
    public void testOptionalArgument() throws Exception {
        TestShell shell = new TestShell();
        shell.addAlias("cmd", "org.jnode.test.shell.syntax.ArgumentMultiplicityTest$Optional");
        shell.addSyntax("cmd", new ArgumentSyntax("arg1"));
        CommandLine cl = new CommandLine(new Token("cmd"), new Token[] {new Token("F1")}, null);
        CommandInfo cmdInfo = cl.parseCommandLine(shell);
        Command cmd = cmdInfo.createCommandInstance();
        Assert.assertEquals("F1", cmd.getArgumentBundle().getArgument("arg1").getValue().toString());

        try {
            cl = new CommandLine(new Token("cmd"), new Token[] {new Token("")}, null);
            cl.parseCommandLine(shell);
            Assert.fail("parse didn't fail");
        } catch (CommandSyntaxException ex) {
            // expected
        }
    }
View Full Code Here

    @Test
    public void testMandatoryArgument() throws Exception {
        TestShell shell = new TestShell();
        shell.addAlias("cmd", "org.jnode.test.shell.syntax.ArgumentMultiplicityTest$Mandatory");
        shell.addSyntax("cmd", new ArgumentSyntax("arg1"));
        CommandLine cl = new CommandLine(new Token("cmd"), new Token[] {new Token("F1")}, null);
        CommandInfo cmdInfo = cl.parseCommandLine(shell);
        Command cmd = cmdInfo.createCommandInstance();
        Assert.assertEquals("F1", cmd.getArgumentBundle().getArgument("arg1").getValue().toString());

        try {
            cl = new CommandLine(new Token("cmd"), new Token[] {}, null);
            cl.parseCommandLine(shell);
            Assert.fail("parse didn't fail");
        } catch (CommandSyntaxException ex) {
            // expected
        }
    }
View Full Code Here

    @Test
    public void testOptionalMultiArgument() throws Exception {
        TestShell shell = new TestShell();
        shell.addAlias("cmd", "org.jnode.test.shell.syntax.ArgumentMultiplicityTest$OptionalMulti");
        shell.addSyntax("cmd", new RepeatSyntax(new ArgumentSyntax("arg1")));
        CommandLine cl = new CommandLine(new Token("cmd"), new Token[] {new Token("F1")}, null);
        CommandInfo cmdInfo = cl.parseCommandLine(shell);
        Command cmd = cmdInfo.createCommandInstance();
        Assert.assertEquals("F1", cmd.getArgumentBundle().getArgument("arg1").getValue().toString());

        cl = new CommandLine(new Token("cmd"), new Token[] {}, null);
        cmdInfo = cl.parseCommandLine(shell);

        cl =
                new CommandLine(new Token("cmd"), new Token[] {new Token("F1"), new Token("F2")},
                        null);
        cmdInfo = cl.parseCommandLine(shell);
    }
View Full Code Here

    @Test
    public void testMandatoryMultiArgument() throws Exception {
        TestShell shell = new TestShell();
        shell.addAlias("cmd", "org.jnode.test.shell.syntax.ArgumentMultiplicityTest$MandatoryMulti");
        shell.addSyntax("cmd", new RepeatSyntax(new ArgumentSyntax("arg1")));
        CommandLine cl = new CommandLine(new Token("cmd"), new Token[] {new Token("F1")}, null);
        CommandInfo cmdInfo = cl.parseCommandLine(shell);
        Command cmd = cmdInfo.createCommandInstance();
        Assert.assertEquals("F1", cmd.getArgumentBundle().getArgument("arg1").getValue().toString());

        try {
            cl = new CommandLine(new Token("cmd"), new Token[] {}, null);
            cl.parseCommandLine(shell);
            Assert.fail("parse didn't fail");
        } catch (CommandSyntaxException ex) {
            // expected
        }

        cl =
                new CommandLine(new Token("cmd"), new Token[] {new Token("F1"), new Token("F2")},
                        null);
        cl.parseCommandLine(shell);
    }
View Full Code Here

        PathnamePattern.clearCache();
        BjorneContext context = new TestBjorneContext();
        Assert.assertEquals(true, context.isGlobbing());
        Assert.assertEquals(true, context.isTildeExpansion());
        if (new File("../README.txt").exists()) {
            CommandLine expansion = context.buildCommandLine(new BjorneToken("../README.*"));
            checkExpansion(expansion, new String[] {"../README.txt"});
            expansion = context.buildCommandLine(new BjorneToken("../README.\\*"));
            checkExpansion(expansion, new String[] {"../README.*"});
            expansion = context.buildCommandLine(new BjorneToken("\"../README.*\""));
            checkExpansion(expansion, new String[] {"../README.*"});
 
View Full Code Here

    @Test
    public void testExpand16() throws Exception {
        BjorneContext context = new TestBjorneContext();
        Assert.assertEquals(true, context.isGlobbing());
        Assert.assertEquals(true, context.isTildeExpansion());
        CommandLine expansion = context.buildCommandLine(new BjorneToken("~"));
        checkExpansion(expansion, new String[] {System.getProperty("user.home")});
        context.setTildeExpansion(false);
        expansion = context.buildCommandLine(new BjorneToken("~"));
        checkExpansion(expansion, new String[] {"~"});
    }
View Full Code Here

TOP

Related Classes of org.jnode.shell.CommandLine

Copyright © 2018 www.massapicom. 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.