From 50a381a1c30ce4a2e19c51475f2304b9f3c7c3dc Mon Sep 17 00:00:00 2001 From: ByrmGkcn Date: Wed, 6 Dec 2023 15:50:49 +0100 Subject: [PATCH] add splitlanguages tests (to test if html css and js are seperated) --- src/test/kotlin/ParserTest.kt | 43 ++++++++++++++++--- .../FileWithScript.html} | 0 .../resources/FileWithStyleAndScript.html | 23 ++++++++++ .../{kotlin => resources}/OnlyTheScript.txt | 1 + 4 files changed, 60 insertions(+), 7 deletions(-) rename src/test/{kotlin/HTMLFileWithScript.html => resources/FileWithScript.html} (100%) create mode 100644 src/test/resources/FileWithStyleAndScript.html rename src/test/{kotlin => resources}/OnlyTheScript.txt (72%) diff --git a/src/test/kotlin/ParserTest.kt b/src/test/kotlin/ParserTest.kt index 66067c4..b922dd0 100644 --- a/src/test/kotlin/ParserTest.kt +++ b/src/test/kotlin/ParserTest.kt @@ -1,7 +1,9 @@ package main import junit.framework.TestCase.assertEquals +import junit.framework.TestCase.assertTrue import org.junit.Test +import java.io.File class ParserTest { @@ -14,16 +16,43 @@ class ParserTest { @Test fun testTakeOnlyJs() { - val fileToTest = "src/test/kotlin/HTMLFileWithScript.html" - val expectedJsCode = """ - function greet() { - return "Hello from JavaScript!"; - } - console.log(greet());""".trimIndent().replace("\\s+".toRegex(), " ") - + val fileToTest = "src/test/resources/FileWithScript.html" + val expectedJsCode = File("src/test/resources/OnlyTheScript.txt").readText().trimIndent().replace("\\s+".toRegex(), " ") val output = takeOnlyJs(fileToTest).trimIndent().replace("\\s+".toRegex(), " ") assertEquals(expectedJsCode, output) } + @Test + fun testJsWords() { + // Assume you have a sample code map + val codeMap = mapOf("word1" to 2, "word2" to 3, "javascript" to 5) + val output = jsWords(codeMap) + // Assert the expected output based on the filtering logic + assertEquals(mapOf("word1" to 2, "word2" to 3, "javascript" to 5), output) + } + + @Test + fun testSplitLanguages() { + // Assume you have a sample HTML file with ")) + assertTrue(actualHtmlCode.contains("")) + } } diff --git a/src/test/kotlin/HTMLFileWithScript.html b/src/test/resources/FileWithScript.html similarity index 100% rename from src/test/kotlin/HTMLFileWithScript.html rename to src/test/resources/FileWithScript.html diff --git a/src/test/resources/FileWithStyleAndScript.html b/src/test/resources/FileWithStyleAndScript.html new file mode 100644 index 0000000..46f6393 --- /dev/null +++ b/src/test/resources/FileWithStyleAndScript.html @@ -0,0 +1,23 @@ + + + + + + Sample HTML with Script and Style + + + +

Hello, World!

+ + + \ No newline at end of file diff --git a/src/test/kotlin/OnlyTheScript.txt b/src/test/resources/OnlyTheScript.txt similarity index 72% rename from src/test/kotlin/OnlyTheScript.txt rename to src/test/resources/OnlyTheScript.txt index 9076a20..eb8fdd7 100644 --- a/src/test/kotlin/OnlyTheScript.txt +++ b/src/test/resources/OnlyTheScript.txt @@ -1,3 +1,4 @@ + function greet() { return "Hello from JavaScript!"; }