Package org.jnode.shell

Examples of org.jnode.shell.CommandLine$Escape


        TestShell shell = new TestShell();
        shell.addAlias("cmd", "org.jnode.test.shell.syntax.AlternativesSyntaxTest$Test");
        shell.addSyntax("cmd", new AlternativesSyntax(new OptionSyntax("intArg", 'i'),
                new OptionSyntax("fileArg", 'f'), new OptionSyntax("flagArg", "xxx")));

        CommandLine cl;
        CommandInfo cmdInfo;
        Command cmd;

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

        cl =
                new CommandLine(new Token("cmd"), new Token[] {new Token("-f"), new Token("F1")},
                        null);
        cmdInfo = cl.parseCommandLine(shell);
        cmd = cmdInfo.createCommandInstance();
        Assert.assertEquals(1, cmd.getArgumentBundle().getArgument("fileArg").getValues().length);
        Assert.assertEquals("F1", cmd.getArgumentBundle().getArgument("fileArg").getValue()
                .toString());
        Assert.assertEquals(0, cmd.getArgumentBundle().getArgument("intArg").getValues().length);
        Assert.assertEquals(0, cmd.getArgumentBundle().getArgument("flagArg").getValues().length);

        cl =
                new CommandLine(new Token("cmd"), new Token[] {new Token("-i"), new Token("41")},
                        null);
        cmdInfo = cl.parseCommandLine(shell);
        cmd = cmdInfo.createCommandInstance();
        Assert.assertEquals(0, cmd.getArgumentBundle().getArgument("fileArg").getValues().length);
        Assert.assertEquals(1, cmd.getArgumentBundle().getArgument("intArg").getValues().length);
        Assert.assertEquals("41", cmd.getArgumentBundle().getArgument("intArg").getValue()
                .toString());
        Assert.assertEquals(0, cmd.getArgumentBundle().getArgument("flagArg").getValues().length);

        cl = new CommandLine(new Token("cmd"), new Token[] {new Token("--xxx")}, null);
        cmdInfo = cl.parseCommandLine(shell);
        cmd = cmdInfo.createCommandInstance();
        Assert.assertEquals(0, cmd.getArgumentBundle().getArgument("fileArg").getValues().length);
        Assert.assertEquals(0, cmd.getArgumentBundle().getArgument("intArg").getValues().length);
        Assert.assertEquals(1, cmd.getArgumentBundle().getArgument("flagArg").getValues().length);

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


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

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

    @Test
    public void testFileArgument() throws Exception {
        TestShell shell = new TestShell();
        shell.addAlias("command", "org.jnode.test.shell.syntax.ArgumentTypesTest$TestFileCommand");
        shell.addSyntax("command", new ArgumentSyntax("arg1"));
        CommandLine cl = new CommandLine(new Token("command"), 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("command"), 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 testStatelessParsing1() throws NoTokensAvailableException, CommandSyntaxException {
        // <start> ::= 'a'
        MuSyntax syntax = new MuSymbol("a");
        MuParser parser = new MuParser();
        CommandLine cl;

        cl = new CommandLine(new String[] {"a"});

        parser.parse(syntax, null, cl.tokenIterator(), null);

        try {
            cl = new CommandLine(new String[] {"b"});
            parser.parse(syntax, null, cl.tokenIterator(), null);
            Assert.fail("parse didn't fail");
        } catch (CommandSyntaxException ex) {
            // expected
        }

        try {
            cl = new CommandLine(new String[] {"a", "a"});
            parser.parse(syntax, null, cl.tokenIterator(), null);
            Assert.fail("parse didn't fail");
        } catch (CommandSyntaxException ex) {
            // expected
        }
    }
View Full Code Here

    @Test
    public void testStatelessParsing2() throws NoTokensAvailableException, CommandSyntaxException {
        // <start> ::= 'a' 'b'
        MuSyntax syntax = new MuSequence(new MuSymbol("a"), new MuSymbol("b"));
        MuParser parser = new MuParser();
        CommandLine cl;

        cl = new CommandLine(new String[] {"a", "b"});
        parser.parse(syntax, null, cl.tokenIterator(), null);
        try {
            cl = new CommandLine(new String[] {"a"});
            parser.parse(syntax, null, cl.tokenIterator(), null);
            Assert.fail("parse didn't fail");
        } catch (CommandSyntaxException ex) {
            // expected
        }
        try {
            cl = new CommandLine(new String[] {"a"});
            parser.parse(syntax, null, cl.tokenIterator(), null);
            Assert.fail("parse didn't fail");
        } catch (CommandSyntaxException ex) {
            // expected
        }
    }
View Full Code Here

    @Test
    public void testStatelessParsing3() throws NoTokensAvailableException, CommandSyntaxException {
        // <start> :: = 'a' | 'b'
        MuSyntax syntax = new MuAlternation(new MuSymbol("a"), new MuSymbol("b"));
        MuParser parser = new MuParser();
        CommandLine cl;

        cl = new CommandLine(new String[] {"a"});
        parser.parse(syntax, null, cl.tokenIterator(), null);

        cl = new CommandLine(new String[] {"b"});
        parser.parse(syntax, null, cl.tokenIterator(), null);

        try {
            cl = new CommandLine(new String[] {"c"});
            parser.parse(syntax, null, cl.tokenIterator(), null);
            Assert.fail("parse didn't fail");
        } catch (CommandSyntaxException ex) {
            // expected
        }
    }
View Full Code Here

        // <root> ::= 'b' | ( 'a' <root> )
        MuSyntax syntax =
                new MuAlternation("root", new MuSymbol("b"), new MuSequence(new MuSymbol("a"),
                        new MuBackReference("root")));
        MuParser parser = new MuParser();
        CommandLine cl;

        cl = new CommandLine(new String[] {"b"});

        parser.parse(syntax, null, cl.tokenIterator(), null);

        try {
            cl = new CommandLine(new String[] {"a", "b"});
            parser.parse(syntax, null, cl.tokenIterator(), null);
            Assert.fail("expected SFE");
        } catch (SyntaxFailureException ex) {
            // expected
        }

        syntax.resolveBackReferences();
        cl = new CommandLine(new String[] {"a", "b"});
        parser.parse(syntax, null, cl.tokenIterator(), null);

        cl = new CommandLine(new String[] {"a", "a", "b"});
        parser.parse(syntax, null, cl.tokenIterator(), null);

        try {
            cl = new CommandLine(new String[] {"a", "a", "c"});
            parser.parse(syntax, null, cl.tokenIterator(), null);
            Assert.fail("expected SEE");
        } catch (CommandSyntaxException ex) {
            // expected
        }
    }
View Full Code Here

        // <root> ::= ( 'a' <root> ) | 'b'
        MuSyntax syntax =
                new MuAlternation("root", new MuSequence(new MuSymbol("a"), new MuBackReference(
                        "root")), new MuSymbol("b"));
        MuParser parser = new MuParser();
        CommandLine cl;

        syntax.resolveBackReferences();

        cl = new CommandLine(new String[] {"b"});

        parser.parse(syntax, null, cl.tokenIterator(), null);

        syntax.resolveBackReferences();
        cl = new CommandLine(new String[] {"a", "b"});
        parser.parse(syntax, null, cl.tokenIterator(), null);

        cl = new CommandLine(new String[] {"a", "a", "b"});
        parser.parse(syntax, null, cl.tokenIterator(), null);

        try {
            cl = new CommandLine(new String[] {"a", "a", "c"});
            parser.parse(syntax, null, cl.tokenIterator(), null);
            Assert.fail("expected SEE");
        } catch (CommandSyntaxException ex) {
            // expected
        }
    }
View Full Code Here

        // ) )
        MuSyntax syntax = new MuAlternation("root", new MuAlternation(new MuSequence(new MuSymbol("a"),
            new MuBackReference("root")), new MuSequence(new MuSymbol("b"), new MuSymbol("c"))),
            new MuAlternation(new MuSequence(new MuSymbol("a"), new MuBackReference("root")), new MuSymbol("b")));
        MuParser parser = new MuParser();
        CommandLine cl;

        syntax.resolveBackReferences();

        cl = new CommandLine(new String[] {"b"});

        parser.parse(syntax, null, cl.tokenIterator(), null);

        syntax.resolveBackReferences();
        cl = new CommandLine(new String[] {"a", "b"});
        parser.parse(syntax, null, cl.tokenIterator(), null);

        cl = new CommandLine(new String[] {"a", "a", "b"});
        parser.parse(syntax, null, cl.tokenIterator(), null);

        cl = new CommandLine(new String[] {"a", "a", "b", "c"});
        parser.parse(syntax, null, cl.tokenIterator(), null);

        try {
            cl = new CommandLine(new String[] {"a", "a", "c"});
            parser.parse(syntax, null, cl.tokenIterator(), null);
            Assert.fail("expected SEE");
        } catch (CommandSyntaxException ex) {
            // expected
        }
    }
View Full Code Here

        // <root> ::= 'b' | ( <root> <root> )
        MuSyntax syntax =
                new MuAlternation("root", new MuSymbol("b"), new MuSequence(new MuBackReference(
                        "root"), new MuBackReference("root")));
        MuParser parser = new MuParser();
        CommandLine cl;

        syntax.resolveBackReferences();

        // This doesn't hit the infinite loop ...
        cl = new CommandLine(new String[] {"b"});
        parser.parse(syntax, null, cl.tokenIterator(), null);

        // But this does ...
        cl = new CommandLine(new String[] {"a"});
        try {
            parser.parse(syntax, null, cl.tokenIterator(), null);
            Assert.fail("expected SFE");
        } catch (SyntaxFailureException ex) {
            Assert.assertEquals(
                    "Parse exceeded the step limit (" + MuParser.DEFAULT_STEP_LIMIT + "). " +
                            "Either the command line is too large, or the syntax is too complex (or pathological)",
View Full Code Here

TOP

Related Classes of org.jnode.shell.CommandLine$Escape

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.