diff --git a/src/test/java/org/codiki/core/services/ParserServiceTest.java b/src/test/java/org/codiki/core/services/ParserServiceTest.java new file mode 100644 index 0000000..ce0e3c3 --- /dev/null +++ b/src/test/java/org/codiki/core/services/ParserServiceTest.java @@ -0,0 +1,330 @@ +package org.codiki.core.services; + +import org.apache.commons.lang.StringEscapeUtils; +import org.junit.Before; +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +public class ParserServiceTest { + + private ParserService parserService; + + @Before + public void setUp() { + parserService = new ParserService(); + } + + /* *********************************************************** */ + /* H E A D E R S P A R S I N G */ + /* *********************************************************** */ + + @Test + public void testParseHeaders_h1() { + final String strInit = "[h1]Header[/h1]"; + final String strExpected = "
def foo():\n return "Hello world!"\n";
+
+ assertThat(parserService.parseCode(strInit)).isEqualTo(strExpected);
+ }
+
+ @Test
+ public void testParseCode_multipleCodes() {
+ final String strInit = parserService.parseBackSpaces(StringEscapeUtils.escapeHtml("[code lg=\"python\"]\n" +
+ "def foo():\n" +
+ " return \"Hello world!\"\n" +
+ "[/code]\n" +
+ "\n" +
+ "[code lg=\"java\"]\n" +
+ "public static void main(final String... pArgs) {\n" +
+ " System.out.println(\"Hello world!\");\n" +
+ "}\n" +
+ "[/code]\n" +
+ "\n"));
+ final String strExpected = "def foo():\n return "Hello world!"\npublic static void main(final String... pArgs) {\n System.out.println("Hello world!");\n}\n";
+
+ assertThat(parserService.parseCode(strInit)).isEqualTo(strExpected);
+ }
+
+ @Test
+ public void testParseLinks_backSlashAndCodeParsing() {
+ final String strInit = parserService.parseBackSpaces(StringEscapeUtils.escapeHtml("[code lg=\"python\"]\n" +
+ "def foo():\n" +
+ " return \"Hello world!\"\n" +
+ "[/code]\n" +
+ "\n"));
+ final String strExpected = "def foo():\n return "Hello world!"\n";
+
+ assertThat(parserService.parseCode(strInit)).isEqualTo(strExpected);
+ }
+
+ @Test
+ public void testParseLinks_backSlashAndCodeParsing_multiple() {
+ final String strInit = parserService.parseBackSpaces(StringEscapeUtils.escapeHtml("[code lg=\"python\"]\n" +
+ "def foo():\n" +
+ " return \"Hello world!\"\n" +
+ "[/code]\n" +
+ "\n" +
+ "[code lg=\"java\"]\n" +
+ "public static void main(final String... pArgs) {\n" +
+ " System.out.println(\"Hello world!\");\n" +
+ "}\n" +
+ "[/code]\n" +
+ "\n"));
+ final String strExpected = "def foo():\n return "Hello world!"\npublic static void main(final String... pArgs) {\n System.out.println("Hello world!");\n}\n";
+
+ assertThat(parserService.parseCode(strInit)).isEqualTo(strExpected);
+ }
+
+ @Test
+ public void testParse() {
+ final String strInit = "\n" +
+ "[h1]Title 1[/h1]\n" +
+ "[h2]Title 2[/h2]\n" +
+ "[h3]Title 3[/h3]\n" +
+ "Some text on multiple\n" +
+ "lines\n" +
+ "like\n" +
+ "here!\n" +
+ "\n" +
+ "[img src=\"pathToImage\" alt=\"alternativeOfImage\" /]\n" +
+ "\n" +
+ "[code lg=\"java\"]\n" +
+ "public static void main(final String... pArgs) {\n" +
+ " System.out.println(\"Hello world!\");\n" +
+ "}\n" +
+ "[/code]\n" +
+ "\n" +
+ "\n" +
+ "[link href=\"pathToLink1\" txt=\"textOfLink1\" /]\n" +
+ "\n" +
+ "[img src=\"pathToImage2\" alt=\"alternativeOfImage2\" lgd=\"legendOfImage2\" /]\n" +
+ "[link href=\"pathToLink2\" txt=\"textOfLink2\" /]\n" +
+ "\n" +
+ "[code lg=\"python\"]\n" +
+ "def foo():\n" +
+ " return \"Hello world!\"\n" +
+ "[/code]\n" +
+ "\n" +
+ "";
+
+ final String strExpected = "" +
+ "public static void main(final String... pArgs) {\n" +
+ " System.out.println("Hello world!");\n" +
+ "}\n" +
+ "" +
+ "def foo():\n" +
+ " return "Hello world!"\n" +
+ "";
+
+ assertThat(parserService.parse(strInit)).isEqualTo(strExpected);
+ }
+}