Package com.pogofish.jadt.source

Examples of com.pogofish.jadt.source.StringSource


    @Test
    public void testExceptionHandling() {
        final Throwable thrown1 = new RuntimeException("oh yeah");
        try {
            final Parser parser = new StandardParser(new ThrowingParserImplFactory(thrown1));
            final ParseResult result = parser.parse(new StringSource("whatever", "whatever"));
            fail("did not get exception, got " + result);
        } catch (RuntimeException caught) {
            assertSame("got wrong exception", thrown1, caught);
        }
       
        final Throwable thrown2 = new Error("oh yeah");
        try {
            final Parser parser = new StandardParser(new ThrowingParserImplFactory(thrown2));
            final ParseResult result = parser.parse(new StringSource("whatever", "whatever"));
            fail("did not get exception, got " + result);
        } catch (Error caught) {
            assertSame("got wrong exception", thrown2, caught);
        }
       
        final Throwable thrown3 = new Exception("oh yeah");
        try {
            final Parser parser = new StandardParser(new ThrowingParserImplFactory(thrown3));
            final ParseResult result = parser.parse(new StringSource("whatever", "whatever"));
            fail("did not get exception, got " + result);
        } catch (RuntimeException caught) {
            assertSame("got wrong exception", thrown3, caught.getCause());
        }
    }
View Full Code Here


    @Test
    public void testHappy() {
        final ParseResult testResult = new ParseResult(new Doc("some source", EMPTY_PKG, NO_IMPORTS,Collections.<DataType>emptyList()), Util.<SyntaxError>list());

        final Parser parser = new DummyParser(testResult, "some source", "some string");
        final ParseResult result = parser.parse(new StringSource("some source", "some string"));
        assertSame(testResult, result);
    }
View Full Code Here

    public void testWrongSourceString() {
        final ParseResult testResult = new ParseResult(new Doc("some source", EMPTY_PKG, NO_IMPORTS,Collections.<DataType>emptyList()), Util.<SyntaxError>list());

        final Parser parser = new DummyParser(testResult, "some source", "some string");
        try {
            final ParseResult result = parser.parse(new StringSource("some source", "some other string"));
            fail("did not get exception, got " + result);
        } catch (RuntimeException e) {
            // yay
        }
    }
View Full Code Here

    public void testWrongSourceInfo() {
        final ParseResult testResult = new ParseResult(new Doc("some source", EMPTY_PKG, NO_IMPORTS,Collections.<DataType>emptyList()), Util.<SyntaxError>list());

        final Parser parser = new DummyParser(testResult, "some source", "some string");
        try {
            final ParseResult result = parser.parse(new StringSource("some other source", "some string"));
            fail("did not get exception, got " + result);
        } catch (RuntimeException e) {
            // yay
        }
    }
View Full Code Here

    public void testWrongExtraSource() {
        final ParseResult testResult = new ParseResult(new Doc("some source", EMPTY_PKG, NO_IMPORTS,Collections.<DataType>emptyList()), Util.<SyntaxError>list());

        final Parser parser = new DummyParser(testResult, "some source", "some string");
        try {
            final ParseResult result = parser.parse(new StringSource("some source", "some string\nmore string"));
            fail("did not get exception, got " + result);
        } catch (RuntimeException e) {
            // yay
        }
    }
View Full Code Here

     *
     * @param text
     * @return
     */
    private JavaCCParserImpl parserImpl(final String text) {
        final StringSource source = new StringSource("ParserTest", text);
        return PARSER_IMPL_FACTORY.create(source.getSrcInfo(), source.createReader());
    }
View Full Code Here

     * Test the whole shebang with a minimal document
     */
    @Test
    public void testMinimal() {
        final Parser parser = new StandardParser(PARSER_IMPL_FACTORY);
        final ParseResult result = parser.parse(new StringSource("ParserTest",
                "Foo = Foo"));

        assertEquals(new ParseResult(new Doc("ParserTest", EMPTY_PKG, NO_IMPORTS, list(_DataType(NO_COMMENTS, NO_ANNOTATIONS, "Foo", NO_FORMAL_TYPE_ARGUMENTS, NO_EXTENDS, NO_IMPLEMENTS,
                list(_Constructor(NO_COMMENTS, "Foo", Util.<Arg> list()))))), Util.<SyntaxError>list()), result);
    }
View Full Code Here

    @Test
    public void testFull() {
        final Parser parser = new StandardParser(PARSER_IMPL_FACTORY);
        final String source = "//a pre-start comment\n//a start comment\npackage hello.world /* here are some imports */import wow.man import flim.flam "
                + "//an annotation comment\n@foo\n@foo(@bar)\n//datatype comment\nFooBar //equal comment\n= //constructor comment\nfoo //bar comment\n| //really a bar comment\nbar(int hey, final String[] yeah) whatever = whatever";
        final ParseResult result = parser.parse(new StringSource("ParserTest",
                source));

        assertEquals(
                new ParseResult(new Doc(
                        "ParserTest",
View Full Code Here

    @Test
   public void testError() {
        final Parser parser = new StandardParser(PARSER_IMPL_FACTORY);
        final String source = "//a start comment\npackage hello.world /* here are some imports */import wow.man import flim.flam "
                + "FooBar = foo | bar(int hey, final String[] yeah) whatever = int";
        final ParseResult result = parser.parse(new StringSource("ParserTest",
                source));

        assertEquals(
                new ParseResult(new Doc(
                        "ParserTest",
View Full Code Here

    @Test
    public void testNonsense() throws Exception {
        // the old parser would get stuck in a loop with this extraneous >
        final Parser parser = new StandardParser(PARSER_IMPL_FACTORY);
       
        final ParseResult result = parser.parse(new StringSource("whatever", "FormalParameter = FormalParameter(final List<Modifier> modifiers>, final TypeRef type, final String name)"));
        assertEquals(ParseResult._ParseResult(Doc._Doc("whatever", EMPTY_PKG, NO_IMPORTS,
                list(_DataType(NO_COMMENTS, NO_ANNOTATIONS, "FormalParameter", NO_FORMAL_TYPE_ARGUMENTS, NO_EXTENDS, NO_IMPLEMENTS,
                        list(_Constructor(NO_COMMENTS, "FormalParameter",
                                list(_Arg(list(_Final()), _Ref(_ClassType("List", list(_ClassType("Modifier", NO_ACTUAL_TYPE_ARGUMENTS)))), "modifiers") /*,
                                     _Arg(list(_Final()), _Ref(_ClassType("TypeRef", Util.<RefType>list())), "type"),
View Full Code Here

TOP

Related Classes of com.pogofish.jadt.source.StringSource

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.