Package org.jnode.shell.syntax

Examples of org.jnode.shell.syntax.IntegerArgument


@Ignore
public class MuParserTest2 {

    @Test
    public void testStatefullParsing1() throws NoTokensAvailableException, CommandSyntaxException {
        IntegerArgument intArg = new IntegerArgument("intArg", Argument.MULTIPLE);
        ArgumentBundle bundle = new ArgumentBundle(intArg);

        // <start> ::= <<intArg>>
        MuSyntax syntax = new MuArgument("intArg");
        MuParser parser = new MuParser();
        CommandLine cl;

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

        parser.parse(syntax, null, cl.tokenIterator(), bundle);
        Assert.assertEquals(new Integer(1), intArg.getValue());

        try {
            cl = new CommandLine(new String[] {"X"});
            parser.parse(syntax, null, cl.tokenIterator(), bundle);
            Assert.fail("parse didn't fail");
View Full Code Here


        }
    }

    @Test
    public void testStatefullParsing2() throws NoTokensAvailableException, CommandSyntaxException {
        IntegerArgument intArg = new IntegerArgument("intArg", Argument.MULTIPLE);
        FileArgument fileArg = new FileArgument("fileArg", Argument.MULTIPLE);
        ArgumentBundle bundle = new ArgumentBundle(intArg, fileArg);

        // <start> ::= <<intArg>> <<fileArg>>
        MuSyntax syntax = new MuSequence(new MuArgument("intArg"), new MuArgument("fileArg"));
        MuParser parser = new MuParser();
        CommandLine cl;

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

        Assert.assertEquals(new Integer(1), intArg.getValue());
        Assert.assertEquals(new File("x"), fileArg.getValue());

        try {
            cl = new CommandLine(new String[] {"1"});
            parser.parse(syntax, null, cl.tokenIterator(), bundle);
View Full Code Here

    }

    @Test
    public void testStatefullParsing3() throws NoTokensAvailableException, CommandSyntaxException {
        IntegerArgument intArg = new IntegerArgument("intArg", Argument.MULTIPLE);
        FileArgument fileArg = new FileArgument("fileArg", Argument.MULTIPLE);
        ArgumentBundle bundle = new ArgumentBundle(intArg, fileArg);

        // <start> :: = <<intArg>> | <<fileArg>>
        MuSyntax syntax = new MuAlternation(new MuArgument("intArg"), new MuArgument("fileArg"));
        MuParser parser = new MuParser();
        CommandLine cl;

        cl = new CommandLine(new String[] {"1"});
        parser.parse(syntax, null, cl.tokenIterator(), bundle);
        Assert.assertEquals(new Integer(1), intArg.getValue());
        Assert.assertEquals(false, fileArg.isSet());

        cl = new CommandLine(new String[] {"x"});
        parser.parse(syntax, null, cl.tokenIterator(), bundle);
        Assert.assertEquals(new File("x"), fileArg.getValue());
        Assert.assertEquals(false, intArg.isSet());

    }
View Full Code Here

    }

    @Test
    public void testStatefullParsing4() throws NoTokensAvailableException, CommandSyntaxException {
        IntegerArgument intArg = new IntegerArgument("intArg", Argument.MULTIPLE);
        FileArgument fileArg = new FileArgument("fileArg", Argument.MULTIPLE);
        ArgumentBundle bundle = new ArgumentBundle(intArg, fileArg);

        // <root> ::= <<fileArg>> | ( <<intArg>> <root> )
        MuSyntax syntax =
                new MuAlternation("root", new MuArgument("fileArg"), new MuSequence(new MuArgument(
                        "intArg"), new MuBackReference("root")));
        syntax.resolveBackReferences();

        MuParser parser = new MuParser();
        CommandLine cl;

        cl = new CommandLine(new String[] {"x"});
        parser.parse(syntax, null, cl.tokenIterator(), bundle);
        Assert.assertEquals(1, fileArg.getValues().length);
        Assert.assertEquals(0, intArg.getValues().length);

        cl = new CommandLine(new String[] {"1", "x"});
        parser.parse(syntax, null, cl.tokenIterator(), bundle);
        Assert.assertEquals(1, fileArg.getValues().length);
        Assert.assertEquals(1, intArg.getValues().length);

        cl = new CommandLine(new String[] {"1", "2", "x"});
        parser.parse(syntax, null, cl.tokenIterator(), bundle);
        Assert.assertEquals(1, fileArg.getValues().length);
        Assert.assertEquals(2, intArg.getValues().length);

        try {
            cl = new CommandLine(new String[] {"1", "2", ""});
            parser.parse(syntax, null, cl.tokenIterator(), bundle);
            Assert.fail("expected SEE");
View Full Code Here

        }
    }

    @Test
    public void testStatefullParsing5() throws NoTokensAvailableException, CommandSyntaxException {
        IntegerArgument intArg = new IntegerArgument("intArg", Argument.MULTIPLE);
        FileArgument fileArg = new FileArgument("fileArg", Argument.MULTIPLE);
        ArgumentBundle bundle = new ArgumentBundle(intArg, fileArg);

        // <root> ::= ( <<intArg>> <root> ) | <<fileArg>>
        MuSyntax syntax =
                new MuAlternation("root", new MuSequence(new MuArgument("intArg"),
                        new MuBackReference("root")), new MuArgument("fileArg"));
        syntax.resolveBackReferences();
        MuParser parser = new MuParser();
        CommandLine cl;

        cl = new CommandLine(new String[] {"x"});
        parser.parse(syntax, null, cl.tokenIterator(), bundle);
        Assert.assertEquals(1, fileArg.getValues().length);
        Assert.assertEquals(0, intArg.getValues().length);

        cl = new CommandLine(new String[] {"1", "x"});
        parser.parse(syntax, null, cl.tokenIterator(), bundle);
        Assert.assertEquals(1, fileArg.getValues().length);
        Assert.assertEquals(1, intArg.getValues().length);

        cl = new CommandLine(new String[] {"1", "1", "x"});
        parser.parse(syntax, null, cl.tokenIterator(), bundle);
        Assert.assertEquals(1, fileArg.getValues().length);
        Assert.assertEquals(2, intArg.getValues().length);

        try {
            cl = new CommandLine(new String[] {"1", "1", ""});
            parser.parse(syntax, null, cl.tokenIterator(), bundle);
            Assert.fail("expected SEE");
View Full Code Here

    @Test
    public void testStatefullParsing6() throws NoTokensAvailableException, CommandSyntaxException {
        EnumArgument<Big> bigArg = new BigArgument("bigArg", Argument.MULTIPLE);
        EnumArgument<Small> smallArg = new SmallArgument("smallArg", Argument.MULTIPLE);
        IntegerArgument intArg = new IntegerArgument("intArg", Argument.MULTIPLE);
        ArgumentBundle bundle = new ArgumentBundle(intArg, smallArg, bigArg);

        // <root> ::= ( ( <<intArg>> <root> ) | ( <<bigArg>> <<smallArg>> ) ) |
        // ( ( <<intArg>> <root> ) | <<bigArg>> ) )
        MuSyntax syntax = new MuAlternation("root", new MuAlternation(new MuSequence(new MuArgument("intArg"),
            new MuBackReference("root")), new MuSequence(new MuArgument("bigArg"), new MuArgument("smallArg"))),
            new MuAlternation(new MuSequence(new MuArgument("intArg"), new MuBackReference("root")),
                new MuArgument("bigArg")));
        syntax.resolveBackReferences();

        MuParser parser = new MuParser();
        CommandLine cl;

        cl = new CommandLine(new String[] {"BIG"});
        parser.parse(syntax, null, cl.tokenIterator(), bundle);
        Assert.assertEquals(1, bigArg.getValues().length);
        Assert.assertEquals(0, smallArg.getValues().length);
        Assert.assertEquals(0, intArg.getValues().length);

        cl = new CommandLine(new String[] {"1", "LARGE"});
        parser.parse(syntax, null, cl.tokenIterator(), bundle);
        Assert.assertEquals(1, bigArg.getValues().length);
        Assert.assertEquals(0, smallArg.getValues().length);
        Assert.assertEquals(1, intArg.getValues().length);

        cl = new CommandLine(new String[] {"1", "2", "BIG"});
        parser.parse(syntax, null, cl.tokenIterator(), bundle);
        Assert.assertEquals(1, bigArg.getValues().length);
        Assert.assertEquals(0, smallArg.getValues().length);
        Assert.assertEquals(2, intArg.getValues().length);

        cl = new CommandLine(new String[] {"1", "2", "3", "BIG", "SMALL"});
        parser.parse(syntax, null, cl.tokenIterator(), bundle);
        Assert.assertEquals(1, bigArg.getValues().length);
        Assert.assertEquals(1, smallArg.getValues().length);
        Assert.assertEquals(3, intArg.getValues().length);

        try {
            cl = new CommandLine(new String[] {"1", "2", "TINY"});
            parser.parse(syntax, null, cl.tokenIterator(), bundle);
            Assert.fail("expected SEE");
View Full Code Here

        Files        = new FileArgument("files", Argument.OPTIONAL | Argument.MULTIPLE, help_files);
        Bytes        = new StringArgument("bytes", Argument.EXISTING | Argument.OPTIONAL, help_bytes);
        Lines        = new StringArgument("lines", Argument.EXISTING | Argument.OPTIONAL, help_lines);
        Follow       = new FlagArgument("follow", Argument.OPTIONAL, help_follow);
        FollowR      = new FlagArgument("followr", Argument.OPTIONAL, help_follow_retry);
        MaxUnchanged = new IntegerArgument("unchanged", Argument.OPTIONAL, help_unchanged);
        Sleep        = new IntegerArgument("sleep", Argument.OPTIONAL, help_sleep);
        Retry        = new FlagArgument("retry", Argument.OPTIONAL, help_retry);
        Quiet        = new FlagArgument("quiet", Argument.OPTIONAL, help_quiet);
        Verbose      = new FlagArgument("verbose", Argument.OPTIONAL, help_verbose);
        registerArguments(Files, Bytes, Lines, Follow, Retry, FollowR, MaxUnchanged, Sleep, Quiet, Verbose);
    }
View Full Code Here

        argPath    = new FileArgument("path", Argument.EXISTING, help_path);
        argReadDec = new FlagArgument("human-read-dec", 0, help_read_dec);
        argReadBin = new FlagArgument("human-read-bin", 0, help_read_bin);
        argAll     = new FlagArgument("show-all", 0, help_all);
        argBlock1k = new FlagArgument("block-size-1k", 0, help_block_1k);
        argBlock   = new IntegerArgument("block-size", 0, help_block);
        registerArguments(argDevice, argPath, argReadDec, argReadBin, argAll, argBlock1k, argBlock);
    }
View Full Code Here

    private final IntegerArgument argThreadID;
    private final FlagArgument argDebug;

    public KillCommand() {
        super(help_super);
        argThreadID = new IntegerArgument("threadId", Argument.MANDATORY, help_tid);
        argDebug    = new FlagArgument("debug", Argument.OPTIONAL, help_debug);
        registerArguments(argThreadID, argDebug);
    }
View Full Code Here

    private final FlagArgument argTest;

    public CompileCommand() {
        super(help_super);
        argClass = new ClassNameArgument("className", Argument.MANDATORY, help_class);
        argLevel = new IntegerArgument("level", Argument.OPTIONAL, 0, maxLevel, help_level);
        argTest  = new FlagArgument("test", Argument.OPTIONAL, help_test);
        registerArguments(argClass, argLevel, argTest);
    }
View Full Code Here

TOP

Related Classes of org.jnode.shell.syntax.IntegerArgument

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.