From 40d32a5d54936401cd7c49901ab0ef1e5593114f Mon Sep 17 00:00:00 2001 From: h7x4 Date: Mon, 26 Apr 2021 00:02:45 +0200 Subject: [PATCH] Add MarkdownTest --- .../java/app/model/languages/Markdown.java | 3 +- .../app/model/languages/MarkdownTest.java | 91 +++++++++++++++++++ 2 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 src/test/java/app/model/languages/MarkdownTest.java diff --git a/src/main/java/app/model/languages/Markdown.java b/src/main/java/app/model/languages/Markdown.java index dd3a726..4acc047 100644 --- a/src/main/java/app/model/languages/Markdown.java +++ b/src/main/java/app/model/languages/Markdown.java @@ -1,6 +1,5 @@ package app.model.languages; -import java.net.URL; import java.util.AbstractMap; import java.util.Arrays; import java.util.LinkedHashMap; @@ -69,7 +68,7 @@ public class Markdown implements ProgrammingLanguage { String cStart = ""; String cStartRegex = "\\s{0,}"; + String cEndRegex = " ?-->\\s{0,}$"; public String commentLine(String line) { return cStart + line + cEnd; diff --git a/src/test/java/app/model/languages/MarkdownTest.java b/src/test/java/app/model/languages/MarkdownTest.java new file mode 100644 index 0000000..a0a6059 --- /dev/null +++ b/src/test/java/app/model/languages/MarkdownTest.java @@ -0,0 +1,91 @@ +package app.model.languages; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import app.model.ProgrammingLanguage; + +public class MarkdownTest { + + private ProgrammingLanguage lang = new Markdown(); + + @Test + @DisplayName("Test commentLine") + public void testCommentLine() { + String line = "test"; + + assertEquals("", lang.commentLine(line)); + assertEquals(" -->", lang.commentLine(lang.commentLine(line))); + } + + @Test + @DisplayName("Test unCommentLine") + public void testUnCommentLine() { + String line = " -->"; + + assertEquals("", lang.unCommentLine(line)); + assertEquals("test", lang.unCommentLine(lang.unCommentLine(line))); + assertEquals("test", lang.unCommentLine("test")); + } + + @Test + @DisplayName("Test combination of commentLine and unCommentLine") + public void testCommentUnCommentLine() { + String line = "test"; + String wrapped1 = lang.unCommentLine(lang.commentLine(line)); + String wrapped2 = lang.unCommentLine(lang.commentLine(wrapped1)); + + assertEquals(line, wrapped1); + assertEquals(line, wrapped2); + } + + + @Test + @DisplayName("Test commentSelection") + public void testCommentSelection() { + String selection = "This\nis a multiline\nstring"; + + assertEquals("", lang.commentSelection(selection)); + assertEquals( + " -->", + lang.commentSelection(lang.commentSelection(selection)) + ); + } + + @Test + @DisplayName("Test unCommentSelection") + public void testUnCommentSelection() { + String selection = " -->"; + + assertEquals("", lang.unCommentSelection(selection)); + assertEquals("This\nis a multiline\nstring", lang.unCommentSelection(lang.unCommentSelection(selection))); + assertEquals("This\nis a multiline\nstring", lang.unCommentLine("This\nis a multiline\nstring")); + } + + @Test + @DisplayName("Test isCommentedLine") + public void testIsCommentedLine() { + String commentedLine = ""; + String unCommentedLine = "test"; + + assertTrue(lang.isCommentedLine(commentedLine)); + assertFalse(lang.isCommentedLine(unCommentedLine)); + } + + @Test + @DisplayName("Test isCommentedSelection") + public void testIsCommentedSelection() { + String commentedSelection = ""; + String halfwayCommentedSelection = "