From 466a9176987c525b2bc5a0687a4c5768eb103646 Mon Sep 17 00:00:00 2001 From: ByrmGkcn Date: Wed, 6 Dec 2023 15:26:13 +0100 Subject: [PATCH] add other Tests --- src/test/kotlin/HTMLFileWithScript.html | 18 ++++++++++++++++++ src/test/kotlin/OnlyTheScript.txt | 5 +++++ src/test/kotlin/ParserTest.kt | 14 ++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 src/test/kotlin/HTMLFileWithScript.html create mode 100644 src/test/kotlin/OnlyTheScript.txt diff --git a/src/test/kotlin/HTMLFileWithScript.html b/src/test/kotlin/HTMLFileWithScript.html new file mode 100644 index 0000000..2e548d3 --- /dev/null +++ b/src/test/kotlin/HTMLFileWithScript.html @@ -0,0 +1,18 @@ + + + + + + Sample Test + + +

Hello, World!

+ + + \ No newline at end of file diff --git a/src/test/kotlin/OnlyTheScript.txt b/src/test/kotlin/OnlyTheScript.txt new file mode 100644 index 0000000..9076a20 --- /dev/null +++ b/src/test/kotlin/OnlyTheScript.txt @@ -0,0 +1,5 @@ +function greet() { + return "Hello from JavaScript!"; +} + +console.log(greet()); \ No newline at end of file diff --git a/src/test/kotlin/ParserTest.kt b/src/test/kotlin/ParserTest.kt index b210713..66067c4 100644 --- a/src/test/kotlin/ParserTest.kt +++ b/src/test/kotlin/ParserTest.kt @@ -12,4 +12,18 @@ class ParserTest { assertEquals("This is a string.", output) } + @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 output = takeOnlyJs(fileToTest).trimIndent().replace("\\s+".toRegex(), " ") + assertEquals(expectedJsCode, output) + } + + }