⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 parsertest.java

📁 Jamon是一个Java文本模板引擎
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                        AFTER)),                parse(BEFORE + escapedEmit + AFTER));    }    @Test public void testEmitWithGreaterThan() throws Exception    {       String emitExpr = "foo > bar";       String emit = EMIT_START + emitExpr + EMIT_END;       assertEquals(           topNode()               .addSubNode(new TextNode(START_LOC, BEFORE))               .addSubNode(                   new EmitNode(                       location(1, 1 + BEFORE.length()),                       emitExpr,                       new DefaultEscapeNode(                           location(1, (BEFORE + emit).length()))))               .addSubNode(                   new TextNode(                       location(1, 1 + (BEFORE + emit).length()),                       AFTER)),           parse(BEFORE + emit + AFTER));    }    @Test public void testClassTag() throws Exception    {        assertEquals(            topNode().addSubNode(                new ClassNode(location(1,1), "foo")),            parse("<%class>foo</%class>"));    }    @Test public void testExtendsTag() throws Exception    {        String path = "/foo/bar";        String extendsTagStart = "<%extends ";        assertEquals(            topNode().addSubNode(                new ExtendsNode(                    location(1,1),                    buildPath(                        location(1, extendsTagStart.length() + 2),                        new AbsolutePathNode(                            location(1, extendsTagStart.length() + 1)),                        path))),            parse(extendsTagStart + path + ">"));    }    @Test public void testEmptyImplementsTag() throws Exception    {        assertEquals(            topNode().addSubNode(new ImplementsNode(START_LOC)),            parse("<%implements></%implements>"));    }    @Test public void testSingleImplementsTag() throws Exception    {        assertEquals(            topNode().addSubNode(               new ImplementsNode(location(1,1))                   .addImplement(new ImplementNode(location(2,1), "a.b"))),            parse("<%implements>\na.b;\n</%implements>"));    }    @Test public void testMultiImplementsTag() throws Exception    {        assertEquals(            topNode().addSubNode(               new ImplementsNode(location(1,1))                   .addImplement(new ImplementNode(location(2,1), "aa.bb"))                   .addImplement(new ImplementNode(location(3,1), "c.d"))),            parse("<%implements>\naa.bb;\nc.d;\n</%implements>"));    }    @Test public void testImplementsWhitespaceTag() throws Exception    {        assertEquals(            topNode().addSubNode(               new ImplementsNode(location(1,1))                   .addImplement(new ImplementNode(location(2,1), "a.b"))),            parse("<%implements>\na . b ;\n</%implements>"));    }    @Test public void testEmptyImportsTag() throws Exception    {        assertEquals(            topNode().addSubNode(new ImportsNode(START_LOC)),            parse("<%import></%import>"));    }    @Test public void testSingleImportsTag() throws Exception    {        assertEquals(            topNode().addSubNode(               new ImportsNode(location(1,1))                   .addImport(new ImportNode(location(2,1), "a.b"))),            parse("<%import>\na.b;\n</%import>"));    }    @Test public void testMultiImportsTag() throws Exception    {        assertEquals(            topNode().addSubNode(               new ImportsNode(location(1,1))                   .addImport(new ImportNode(location(2,1), "aa.bb"))                   .addImport(new ImportNode(location(3,1), "c.*"))),            parse("<%import>\naa.bb;\nc.*;\n</%import>"));    }    @Test public void testImportsWhitespace() throws Exception    {        assertEquals(            topNode().addSubNode(               new ImportsNode(location(1,1))                   .addImport(new ImportNode(location(2,1), "aa.bb"))                   .addImport(new ImportNode(location(3,1), "c.*"))),            parse("<%import>\naa . bb ;\nc . * ;\n</%import>"));    }    @Test public void testEmptyParentArgsTag() throws Exception    {        assertEquals(            topNode().addSubNode(new ParentArgsNode(START_LOC)),            parse("<%xargs></%xargs>"));    }    @Test public void testParentArgsTag() throws Exception    {        assertEquals(            topNode().addSubNode(                new ParentArgsNode(START_LOC)                    .addArg(new ParentArgNode(                        location(2,1),                        new ArgNameNode(location(2, 1), "a")))                    .addArg(new ParentArgWithDefaultNode(                        location(3,1),                        new ArgNameNode(location(3,1), "b"),                        new ArgValueNode(location(3, 6), "x")))),            parse("<%xargs>\na;\nb => x;</%xargs>"));    }    @Test public void testParentArgsInOverrideTag() throws Exception    {        assertEquals(            topNode().addSubNode(                new OverrideNode(START_LOC, "m").addSubNode(                    new ParentArgsNode(location(2, 1))                        .addArg(new ParentArgNode(                            location(3,1),                            new ArgNameNode(location(3, 1), "a")))                        .addArg(new ParentArgWithDefaultNode(                            location(4,1),                            new ArgNameNode(location(4,1), "b"),                            new ArgValueNode(location(4, 6), "x"))))),            parse("<%override m>\n<%xargs>\na;\nb => x;</%xargs></%override>"));    }    @Test public void testDocTag() throws Exception    {        String begining = BEFORE + "<%doc>some docs</%doc>";        assertEquals(            topNode()                .addSubNode(new TextNode(START_LOC, BEFORE))                .addSubNode(                    new DocNode(location(1, BEFORE.length() + 1), "some docs"))                .addSubNode(new TextNode(location(1, begining.length() + 1),                                         "after")),            parse(begining + "after"));    }    @Test public void testParentMarkerTag() throws Exception    {        assertEquals(            topNode().addSubNode(new ParentMarkerNode(location(1,1))),            parse("<%abstract>"));    }    @Test public void testEscapeTag() throws Exception    {        assertEquals(            topNode()                .addSubNode(new EscapeDirectiveNode(location(1,1), "u")),            parse("<%escape #u>"));    }    @Test public void testWhileTag() throws Exception    {        final String whileTag = "<%while cond%>";        assertEquals(            topNode()            .addSubNode(new WhileNode(location(1,1), "cond")                .addSubNode(new TextNode(                    location(1, 1 + whileTag.length()), "text"))),            parse(whileTag + "text</%while>"));    }    @Test public void testForTag() throws Exception    {        final String forTag = "<%for loop : baz%>";        assertEquals(            topNode()            .addSubNode(new ForNode(location(1,1), "loop : baz")                .addSubNode(new EmitNode(                    location(                        1,                        1 + forTag.length()), "x ",                        new DefaultEscapeNode(location(                            1, 1 + forTag.length() + "<% x %".length()))))                .addSubNode(new TextNode(                    location(1, 1 + forTag.length() + "<% x %>".length()),                    "text"))),            parse(forTag + "<% x %>text</%for>"));    }    @Test public void testIfTag() throws Exception    {        final String ifTag = "<%if cond%>";        assertEquals(            topNode()            .addSubNode(new IfNode(location(1,1), "cond")                .addSubNode(new TextNode(                    location(1, 1 + ifTag.length()), "text"))),            parse(ifTag + "text</%if>"));    }    @Test public void testIfElseTags() throws Exception    {        final String ifTag = "<%if cond%>";        assertEquals(            topNode()            .addSubNode(new IfNode(location(1,1), "cond")                .addSubNode(new TextNode(                    location(1, 1 + ifTag.length()), "text\n")))            .addSubNode(new ElseNode(location(2,1))                .addSubNode(new TextNode(location(2, 8), "other"))),            parse(ifTag + "text\n<%else>other</%if>"));    }    @Test public void testIfElseIfTags() throws Exception    {        final String ifTag = "<%if cond%>";        final String elseIfTag = "<%elseif cond2%>";        assertEquals(            topNode()            .addSubNode(new IfNode(location(1,1), "cond")                .addSubNode(new TextNode(                    location(1, 1 + ifTag.length()), "text\n")))            .addSubNode(new ElseIfNode(location(2,1), "cond2")                .addSubNode(                    new TextNode(location(2, 1 + elseIfTag.length()), "other"))),            parse(ifTag + "text\n" + elseIfTag + "other</%if>"));    }    @Test public void testIfElseIfElseTags() throws Exception    {        final String ifTag = "<%if cond%>";        final String elseIfTag = "<%elseif cond2%>";        assertEquals(            topNode()            .addSubNode(new IfNode(location(1,1), "cond")                .addSubNode(new TextNode(                    location(1, 1 + ifTag.length()), "text\n")))            .addSubNode(new ElseIfNode(location(2,1), "cond2")                .addSubNode(new TextNode(                    location(2, 1 + elseIfTag.length()), "other\n")))            .addSubNode(new ElseNode(location(3, 1))                .addSubNode(new TextNode(location(3, 8), "third"))),            parse(ifTag + "text\n" + elseIfTag + "other\n<%else>third</%if>"));    }    @Test public void testMultipleElseIfTags() throws Exception    {        final String ifTag = "<%if cond%>";        final String elseIfTag1 = "<%elseif cond1%>";        final String elseIfTag2 = "<%elseif cond2%>";        assertEquals(            topNode()            .addSubNode(new IfNode(location(1,1), "cond")                .addSubNode(new TextNode(                    location(1, 1 + ifTag.length()), "text\n")))            .addSubNode(new ElseIfNode(location(2,1), "cond1")                .addSubNode(new TextNode(                    location(2, 1 + elseIfTag1.length()), "one\n")))            .addSubNode(new ElseIfNode(location(3,1), "cond2")                .addSubNode(                    new TextNode(location(3, 1 + elseIfTag2.length()), "two"))),            parse(                ifTag + "text\n"                + elseIfTag1 + "one\n"                + elseIfTag2 + "two</%if>"));    }    @Test public void testParseAnnotateBoth() throws Exception    {        assertEquals(            topNode()            .addSubNode(new AnnotationNode(location(1,1), SAMPLE_ANNOTATION, AnnotationType.BOTH))            .addSubNode(new TextNode(location(2,1), "a")),            parse("<%annotate " + SAMPLE_ANNOTATION + "%>\na"));    }    @Test public void testParseAnnotateProxy() throws Exception    {        assertEquals(            topNode()            .addSubNode(new AnnotationNode(location(1,1), SAMPLE_ANNOTATION, AnnotationType.PROXY))            .addSubNode(new TextNode(location(2,1), "a")),            parse("<%annotate " + SAMPLE_ANNOTATION + "#proxy %>\na"));    }    @Test public void testParseAnnotateImpl() throws Exception    {        assertEquals(            topNode()            .addSubNode(new AnnotationNode(location(1,1), SAMPLE_ANNOTATION, AnnotationType.IMPL))            .addSubNode(new TextNode(location(2,1), "a")),            parse("<%annotate " + SAMPLE_ANNOTATION + "#impl%>\na"));    }    public static junit.framework.Test suite()    {        return new junit.framework.JUnit4TestAdapter(ParserTest.class);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -