From e47b72646777358867e47a0cca62a1ead41b1d50 Mon Sep 17 00:00:00 2001 From: ByrmGkcn Date: Wed, 6 Dec 2023 17:43:52 +0100 Subject: [PATCH] change the parser to manage accent, add splitlanguages tests (to test if html css and js are seperated) and test if the parsing works great --- src/main/kotlin/main/parser.kt | 2 +- src/test/kotlin/ParserTest.kt | 39 ++++- src/test/resources/ExpectedParsingResult.txt | 10 ++ src/test/resources/puissance4.html | 150 +++++++++++++++++++ 4 files changed, 198 insertions(+), 3 deletions(-) create mode 100644 src/test/resources/ExpectedParsingResult.txt create mode 100644 src/test/resources/puissance4.html diff --git a/src/main/kotlin/main/parser.kt b/src/main/kotlin/main/parser.kt index 585d2be..7744535 100644 --- a/src/main/kotlin/main/parser.kt +++ b/src/main/kotlin/main/parser.kt @@ -49,7 +49,7 @@ fun splitLanguages(file : String){ fun parser(fileName : String) { val delimiter1 = " " - val regex = "[^a-zA-Z]".toRegex() + val regex = "[^a-zA-Z^é^à]".toRegex() val array = mutableListOf() val line = delStrings(takeOnlyJs(fileName)).toString().replace(regex, " ").toString() diff --git a/src/test/kotlin/ParserTest.kt b/src/test/kotlin/ParserTest.kt index b922dd0..11dbd24 100644 --- a/src/test/kotlin/ParserTest.kt +++ b/src/test/kotlin/ParserTest.kt @@ -3,15 +3,17 @@ package main import junit.framework.TestCase.assertEquals import junit.framework.TestCase.assertTrue import org.junit.Test +import java.io.ByteArrayOutputStream import java.io.File +import java.io.PrintStream class ParserTest { @Test fun testDelStrings() { - val input = "This is a \"sample\" string." + val input = "This is a \"sample\"string." val output = delStrings(input) - assertEquals("This is a string.", output) + assertEquals("This is a string.", output) } @Test @@ -55,4 +57,37 @@ class ParserTest { assertTrue(actualHtmlCode.contains("")) } + @Test + fun testParser() { + // Assume you have a sample HTML file for testing + val puissance4File = "src/test/resources/puissance4.html" + + // Call the parser function + parser(puissance4File) + + // Verify the output by capturing the printed content + val printedContent = captureStandardOutput { + parser(puissance4File) + } + + // Assert the expected output based on the content of your sample HTML file + val expectedOutput =File("src/test/resources/ExpectedParsingResult.txt").readText().trimIndent() + + assertEquals(expectedOutput, printedContent.trimIndent()) + } + + // Function to capture standard output + private fun captureStandardOutput(block: () -> Unit): String { + val standardOut = System.out + val outputStream = ByteArrayOutputStream() + System.setOut(PrintStream(outputStream)) + + try { + block() + } finally { + System.setOut(standardOut) + } + + return outputStream.toString().trim() + } } diff --git a/src/test/resources/ExpectedParsingResult.txt b/src/test/resources/ExpectedParsingResult.txt new file mode 100644 index 0000000..1586e92 --- /dev/null +++ b/src/test/resources/ExpectedParsingResult.txt @@ -0,0 +1,10 @@ +plateau : 2 +creercell : 2 +numcolonnes : 3 +coupsJoues : 3 +numrangées : 4 +joueurActuel : 5 +cells : 9 +colonne : 16 +rangée : 18 +cell : 21 \ No newline at end of file diff --git a/src/test/resources/puissance4.html b/src/test/resources/puissance4.html new file mode 100644 index 0000000..5bca5d4 --- /dev/null +++ b/src/test/resources/puissance4.html @@ -0,0 +1,150 @@ + + + + + + +
+ + +