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 @@ + + + + + + +
+ + +