diff --git a/src/main/kotlin/git/semver/plugin/semver/SemverSettings.kt b/src/main/kotlin/git/semver/plugin/semver/SemverSettings.kt index 2162974..2f19343 100644 --- a/src/main/kotlin/git/semver/plugin/semver/SemverSettings.kt +++ b/src/main/kotlin/git/semver/plugin/semver/SemverSettings.kt @@ -4,14 +4,14 @@ import git.semver.plugin.gradle.ChangeLogFormatter open class SemverSettings { - var defaultPreRelease: String = "SNAPSHOT" - var releasePattern: String = "\\Arelease(?:\\(\\w+\\))?:" - var patchPattern: String = "\\Afix(?:\\([^()]+\\))?:" - var minorPattern: String = "\\Afeat(?:\\([^()]+\\))?:" - var majorPattern: String = "\\A\\w+(?:\\([^()]+\\))?!:|^BREAKING[ -]CHANGE:" + var defaultPreRelease = "SNAPSHOT" + var releasePattern = "\\Arelease(?:\\(\\w+\\))?:" + var patchPattern = "\\Afix(?:\\([^()]+\\))?:" + var minorPattern = "\\Afeat(?:\\([^()]+\\))?:" + var majorPattern = "\\A\\w+(?:\\([^()]+\\))?!:|^BREAKING[ -]CHANGE:" - var changeLogPattern: String = "\\A(?\\w+)(?:\\((?[^()]+)\\))?:(?(?:.|\n)*)" - var changeLogTexts: Map = mutableMapOf( + var changeLogPattern = "\\A(?\\w+)(?:\\((?[^()]+)\\))?:(?(?:.|\n)*)" + var changeLogTexts = mutableMapOf( ChangeLogFormatter.OTHER_TYPE to "## Other Changes \uD83D\uDCA1", ChangeLogFormatter.MISSING_TYPE to "## Other Changes \uD83D\uDCA1", ChangeLogFormatter.BREAKING_CHANGE to "## Breaking Changes \uD83D\uDEE0", diff --git a/src/test/kotlin/git/semver/plugin/gradle/ChangeLogFormatterTest.kt b/src/test/kotlin/git/semver/plugin/gradle/ChangeLogFormatterTest.kt index fa26a99..35b97f8 100644 --- a/src/test/kotlin/git/semver/plugin/gradle/ChangeLogFormatterTest.kt +++ b/src/test/kotlin/git/semver/plugin/gradle/ChangeLogFormatterTest.kt @@ -11,7 +11,6 @@ import kotlin.test.assertNotNull class ChangeLogFormatterTest { @Test fun format_log_empty() { - val settings = SemverSettings() val actual = ChangeLogFormatter(settings).formatLog(listOf()) @@ -20,24 +19,11 @@ class ChangeLogFormatterTest { } @Test fun format_log_with_breaking_changes() { - val settings = SemverSettings() - val changeLog = listOf( - "fix(#1): Bugfix 1", - "fix(#1): Bugfix 1", - "fix(deps): Bugfix broken deps", - "feat(#2): A feature", - "fix(#5)!: A breaking change", - "build(deps): A build change", - "release: 1.2.3-alpha", - "test: Added some tests", - "ci: A CI change", - "xyz: Some other change", - "An uncategorized change" - ) + val changeLog = createChangeLog() val actual = ChangeLogFormatter(settings).formatLog(changeLog) - println(actual) + assertThat(actual) .startsWith("# What's Changed") .containsOnlyOnce("Bugfix 1") @@ -53,5 +39,33 @@ class ChangeLogFormatterTest { .contains("- xyz: Some other change") .contains("- An uncategorized change") .doesNotContain("1.2.3") + println(actual) + } + + @Test fun format_log_with_cleared_settings() { + val settings = SemverSettings() + settings.changeLogTexts.clear(); + val changeLog = createChangeLog() + + val actual = ChangeLogFormatter(settings).formatLog(changeLog) + + assertThat(actual).isEmpty() + } + + private fun createChangeLog(): List { + val changeLog = listOf( + "fix(#1): Bugfix 1", + "fix(#1): Bugfix 1", + "fix(deps): Bugfix broken deps", + "feat(#2): A feature", + "fix(#5)!: A breaking change", + "build(deps): A build change", + "release: 1.2.3-alpha", + "test: Added some tests", + "ci: A CI change", + "xyz: Some other change", + "An uncategorized change" + ) + return changeLog } }