/** * Copyright 2011 Oliver Buchtala * * This file is part of ndogen. * * ndogen is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ndogen is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ndogen. If not, see <http://www.gnu.org/licenses/>. */ package org.ndogen.markdown; import static org.junit.Assert.*; import org.antlr.runtime.RecognitionException; import org.antlr.runtime.tree.Tree; import org.junit.Test; import org.ndogen.Fixture; import org.ndogen.TestUtils; import org.ndogen.markdown.MarkdownParser.document_return; public class MarkdownParserTest { public static String normalizeOutput(String output) { output = output.replace("\n", "") .replace("\r", "") .replace("\t", "") .replace(" ", " ") .trim(); return output; } public void test(String fixtureName) { Fixture fixture = TestUtils.getFixture("fixtures/markdown/parser", fixtureName); MarkdownParser parser = TestUtils.createParser(fixture, MarkdownScanner.class, MarkdownParser.class); String output; try { document_return doc = parser.document(); output = ((Tree)doc.getTree()).toStringTree(); } catch (RecognitionException e) { throw new RuntimeException(e); } assertEquals(normalizeOutput(fixture.getOutput()), normalizeOutput(output)); } @Test public void testTwoSections() throws Exception { test("two_sections"); } @Test public void testFormattedText() throws Exception { test("formatted_text"); } @Test public void testSimpleList() throws Exception { test("simple_list"); } @Test public void testSpecialLists() throws Exception { test("special_lists"); } @Test public void testNestedSections() throws Exception { test("nested_sections"); } @Test public void testSectionsHashes() throws Exception { test("sections_hashes"); } @Test public void testNestedList() throws Exception { test("nested_list"); } @Test public void testSimpleQuote() throws Exception { test("simple_quote"); } @Test public void testParagraphAfterQuote() throws Exception { test("paragraph_after_quote"); } @Test public void testCodeBlock() throws Exception { test("code_block"); } @Test public void testLinks() throws Exception { test("links"); } @Test public void testNoEmptyLines() throws Exception { test("no_empty_lines"); } @Test public void testIntro() throws Exception { test("intro"); } @Test public void testNestedQuotes() throws Exception { test("nested_quotes"); } }