Skip to content

Commit

Permalink
Added test cases for wiki toc checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Rd4dev committed Jul 5, 2024
1 parent 3e74a99 commit 5a8b4b9
Showing 1 changed file with 90 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ import java.io.PrintStream
class WikiTableOfContentsCheckTest {
private val outContent: ByteArrayOutputStream = ByteArrayOutputStream()
private val originalOut: PrintStream = System.out
private val WIKI_TOC_CHECK_PASSED_OUTPUT_INDICATOR = "WIKI TABLE OF CONTENTS CHECK PASSED"
private val WIKI_TOC_CHECK_FAILED_OUTPUT_INDICATOR = "WIKI TABLE OF CONTENTS CHECK FAILED"

@field:[Rule JvmField] val tempFolder = TemporaryFolder()

@Before
fun setUp() {
tempFolder.newFolder("wiki")
System.setOut(PrintStream(outContent))
}

Expand All @@ -28,9 +31,8 @@ class WikiTableOfContentsCheckTest {
}

@Test
fun testValidToCWithMatchingHeaders() {
tempFolder.newFolder("wiki")
val file = tempFolder.newFile("wiki/ValidToCWithMatchingHeaders.md")
fun testWikiTOCCheck_validWikiTOC_checkPass() {
val file = tempFolder.newFile("wiki/wiki.md")
file.writeText("""
## Table of Contents
Expand All @@ -46,7 +48,91 @@ class WikiTableOfContentsCheckTest {

runScript()

assertThat(outContent.toString().trim()).contains("WIKI TABLE OF CONTENTS CHECK PASSED")
assertThat(outContent.toString().trim()).contains(WIKI_TOC_CHECK_PASSED_OUTPUT_INDICATOR)
}

@Test
fun testWikiTOCCheck_missingWikiTOC_returnsNoTOCFound() {
val file = tempFolder.newFile("wiki/wiki.md")
file.writeText("""
- [Introduction](#introduction)
- [Usage](#usage)
## Introduction
Content
## Usage
Content
""".trimIndent())

runScript()

assertThat(outContent.toString().trim()).contains("No Table of Contents found")
}

@Test
fun testWikiTOCCheck_mismatchWikiTOC_checkFail() {
val file = tempFolder.newFile("wiki/wiki.md")
file.writeText("""
## Table of Contents
- [Introduction](#introductions)
- [Usage](#usage)
## Introduction
Content
## Usage
Content
""".trimIndent())

val exception = assertThrows<IllegalStateException>() {
runScript()
}

assertThat(exception).hasMessageThat().contains(WIKI_TOC_CHECK_FAILED_OUTPUT_INDICATOR)
}

@Test
fun testWikiTOCCheck_validWikiTOCWithSeparator_checkPass() {
val file = tempFolder.newFile("wiki/wiki.md")
file.writeText("""
## Table of Contents
- [Introduction To Wiki](#introduction-to-wiki)
- [Usage Wiki-Content](#usage-wiki-content)
## Introduction
Content
## Usage
Content
""".trimIndent())

runScript()

assertThat(outContent.toString().trim()).contains(WIKI_TOC_CHECK_PASSED_OUTPUT_INDICATOR)
}

@Test
fun testWikiTOCCheck_validWikiTOCWithSpecialCharacter_checkPass() {
val file = tempFolder.newFile("wiki/wiki.md")
file.writeText("""
## Table of Contents
- [Introduction](#introduction?)
- [Usage?](#usage)
## Introduction
Content
## Usage
Content
""".trimIndent())

runScript()

assertThat(outContent.toString().trim()).contains(WIKI_TOC_CHECK_PASSED_OUTPUT_INDICATOR)
}

private fun runScript() {
Expand Down

0 comments on commit 5a8b4b9

Please sign in to comment.