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) + } + + }