-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Switch Builder Test on Kotest * Switch Parser Tests on Kotest * Add Versions support * Cover versions by tests * Increase Version * Update README * Fix code smells
- Loading branch information
Showing
23 changed files
with
377 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
src/commonMain/kotlin/com/ucasoft/kcron/exceptions/WrongCronExpression.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
package com.ucasoft.kcron.exceptions | ||
|
||
class WrongCronExpression(expression: String) : Throwable("Expression $expression is not Cron one!") | ||
import com.ucasoft.kcron.settings.Version | ||
|
||
class WrongCronExpression(expression: String, version: Version) : Throwable("Expression $expression is not ${if (version != Version.Auto) "$version " else ""}Cron one!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.ucasoft.kcron.settings | ||
|
||
import com.ucasoft.kcron.common.WeekDays | ||
|
||
data class Settings(var firstDayOfWeek: WeekDays = WeekDays.Monday, var version: Version = Version.Auto) |
10 changes: 10 additions & 0 deletions
10
src/commonMain/kotlin/com/ucasoft/kcron/settings/Version.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.ucasoft.kcron.settings | ||
|
||
enum class Version { | ||
|
||
Auto, | ||
|
||
Classic, | ||
|
||
Modern | ||
} |
70 changes: 70 additions & 0 deletions
70
src/commonTest/kotlin/com/ucasoft/kcron/BuildAndParseTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package com.ucasoft.kcron | ||
|
||
import com.ucasoft.kcron.exceptions.WrongCronExpression | ||
import com.ucasoft.kcron.settings.Version | ||
import io.kotest.assertions.throwables.shouldThrowWithMessage | ||
import io.kotest.matchers.nulls.shouldNotBeNull | ||
import io.kotest.matchers.shouldBe | ||
import kotlinx.datetime.Clock | ||
import kotlinx.datetime.TimeZone | ||
import kotlinx.datetime.toLocalDateTime | ||
import kotlin.test.BeforeTest | ||
import kotlin.test.Test | ||
|
||
class BuildAndParseTests { | ||
|
||
private var currentYear : Int = 2023 | ||
|
||
private val modernCronExpression = "30 * * ? * * 2050" | ||
|
||
@BeforeTest | ||
fun setupOnce() { | ||
currentYear = Clock.System.now().toLocalDateTime(TimeZone.currentSystemDefault()).year | ||
} | ||
|
||
@Test | ||
fun parseAndBuildAuto() { | ||
var builder = KCron.parseAndBuild("* 12 ? * *") | ||
builder.expression.shouldBe("0 * 12 ? * * *") | ||
builder.nextRun.shouldNotBeNull() | ||
.year.shouldBe(currentYear) | ||
builder = KCron.parseAndBuild(modernCronExpression) | ||
builder.expression.shouldBe(modernCronExpression) | ||
builder.nextRun.shouldNotBeNull() | ||
.year.shouldBe(2050) | ||
shouldThrowWithMessage<WrongCronExpression>("Expression * * * ? * * is not Cron one!") { | ||
KCron.parseAndBuild("* * * ? * *") | ||
} | ||
} | ||
|
||
@Test | ||
fun parseAndBuildClassic() { | ||
val builder = KCron.parseAndBuild("* 12 ? * *") { | ||
it.version = Version.Classic | ||
} | ||
builder.expression.shouldBe("0 * 12 ? * * *") | ||
builder.nextRun.shouldNotBeNull() | ||
.year.shouldBe(currentYear) | ||
shouldThrowWithMessage<WrongCronExpression>("Expression * * * ? * * * is not Classic Cron one!") { | ||
KCron.parseAndBuild("* * * ? * * *") { | ||
it.version = Version.Classic | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun parseAndBuildModern() { | ||
val builder = KCron.parseAndBuild(modernCronExpression) { | ||
it.version = Version.Modern | ||
} | ||
builder.expression.shouldBe(modernCronExpression) | ||
builder.nextRun.shouldNotBeNull() | ||
.year.shouldBe(2050) | ||
shouldThrowWithMessage<WrongCronExpression>("Expression * * ? * * is not Modern Cron one!") { | ||
KCron.parseAndBuild("* * ? * *") { | ||
it.version = Version.Modern | ||
} | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.