mirror of
https://github.com/InsanusMokrassar/krontab.git
synced 2024-11-25 11:38:54 +00:00
Compare commits
No commits in common. "4afebd8b7e0aa751d75ac9034b258d0060ab880b" and "5ef6134d9f3fbd50c566916b3a268fbc5a910af3" have entirely different histories.
4afebd8b7e
...
5ef6134d9f
@ -1,9 +1,5 @@
|
||||
# Changelog
|
||||
|
||||
## 2.6.1
|
||||
|
||||
* Fixes in parsing of string parts
|
||||
|
||||
## 2.6.0
|
||||
|
||||
* Fix of `doOnceTz` behaviour: now it will use local time as utc time to get next waking up time
|
||||
|
@ -36,5 +36,5 @@ androidx_work_version=2.10.0
|
||||
|
||||
## Common
|
||||
|
||||
version=2.6.1
|
||||
android_code_version=45
|
||||
version=2.6.0
|
||||
android_code_version=44
|
||||
|
@ -41,80 +41,53 @@ private fun <T> createSimpleScheduler(from: String, dataRange: IntRange, dataCon
|
||||
* FSM for parsing of incoming data. If at the end of parsing it have non-null state and string is not empty, data passed check
|
||||
*
|
||||
* 1.
|
||||
* * "\\d" -> 2
|
||||
* * "\\*" -> 4
|
||||
* * "f" -> 7
|
||||
* * "l" -> 7
|
||||
* * "/" -> 6
|
||||
* * \\d -> 1
|
||||
* * \\* -> 2
|
||||
* * \\- -> 5
|
||||
* * , -> 1
|
||||
* * m -> 6
|
||||
* * o -> 7
|
||||
* * w -> 7
|
||||
* 2.
|
||||
* * "\\d" -> 2
|
||||
* * "/" -> 6
|
||||
* * "," -> 1
|
||||
* * "-" -> 3
|
||||
* * "m" -> 9
|
||||
* * "o" -> 10
|
||||
* * "w" -> 10
|
||||
* * / -> 3
|
||||
* 3.
|
||||
* * "l" -> 7
|
||||
* * "\\d" -> 8
|
||||
* * \\d -> 3
|
||||
* * \\* -> 4
|
||||
* 4.
|
||||
* * "/" -> 6
|
||||
* * "," -> 1
|
||||
* * , -> 1
|
||||
* 5.
|
||||
* * "/" -> 6
|
||||
* * \\d -> 5
|
||||
* * , -> 1
|
||||
* 6.
|
||||
* * "\\d" -> 8
|
||||
* * "\\*" -> 7
|
||||
* 7.
|
||||
* * "," -> 1
|
||||
* 8.
|
||||
* * "\\d" -> 8
|
||||
* * "," -> 1
|
||||
* 9.
|
||||
* * "s" -> 10 // end of ms
|
||||
* 10. Empty, end of parse
|
||||
* * s -> 7
|
||||
* 7. Empty, end of parse
|
||||
*/
|
||||
private val checkIncomingPartTransitionsMap = listOf(
|
||||
listOf( // 0
|
||||
Regex("\\d") to 1,
|
||||
listOf(
|
||||
Regex("\\d") to 0,
|
||||
Regex("\\*") to 1,
|
||||
Regex("-") to 4,
|
||||
Regex(",") to 0,
|
||||
Regex("m") to 5,
|
||||
Regex("o") to 6,
|
||||
Regex("w") to 6,
|
||||
),
|
||||
listOf(
|
||||
Regex("/") to 2,
|
||||
),
|
||||
listOf(
|
||||
Regex("\\d") to 2,
|
||||
Regex("\\*") to 3,
|
||||
Regex("f") to 6,
|
||||
Regex("l") to 6,
|
||||
Regex("/") to 5,
|
||||
),
|
||||
listOf( // 1
|
||||
Regex("\\d") to 1,
|
||||
Regex("/") to 5,
|
||||
Regex(",") to 0,
|
||||
Regex("-") to 2,
|
||||
Regex("m") to 8,
|
||||
Regex("o") to 9,
|
||||
Regex("w") to 9,
|
||||
),
|
||||
listOf( // 2
|
||||
Regex("l") to 6,
|
||||
Regex("\\d") to 7,
|
||||
),
|
||||
listOf( // 3
|
||||
Regex("/") to 5,
|
||||
listOf(
|
||||
Regex(",") to 0,
|
||||
),
|
||||
listOf( // 4
|
||||
Regex("/") to 5,
|
||||
),
|
||||
listOf( // 5
|
||||
Regex("\\d") to 7,
|
||||
Regex("\\*") to 6,
|
||||
),
|
||||
listOf( // 6
|
||||
listOf(
|
||||
Regex("\\d") to 4,
|
||||
Regex(",") to 0,
|
||||
),
|
||||
listOf( // 7
|
||||
Regex("\\d") to 7,
|
||||
Regex(",") to 0,
|
||||
),
|
||||
listOf( // 8
|
||||
Regex("s") to 9, // end of ms
|
||||
listOf(
|
||||
Regex("s") to 6, // end of ms
|
||||
),
|
||||
listOf(), // empty state, end of parsing
|
||||
)
|
||||
|
@ -2,7 +2,6 @@ package dev.inmo.krontab.utils
|
||||
|
||||
import korlibs.time.*
|
||||
import dev.inmo.krontab.KronSchedulerTz
|
||||
import dev.inmo.krontab.KrontabTemplate
|
||||
import dev.inmo.krontab.buildSchedule
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.flow.takeWhile
|
||||
@ -12,51 +11,73 @@ import kotlin.test.*
|
||||
@ExperimentalCoroutinesApi
|
||||
@FlowPreview
|
||||
class StringParseTest {
|
||||
private fun makeSimpleEverySecondTest(template: KrontabTemplate) {
|
||||
val kronScheduler = buildSchedule(template)
|
||||
@Test
|
||||
fun testThatFlowIsCorrectlyWorkEverySecondBuiltOnString() {
|
||||
val kronScheduler = buildSchedule("*/1 * * * *")
|
||||
|
||||
val flow = kronScheduler.asFlowWithoutDelays()
|
||||
|
||||
runTest {
|
||||
val mustBeCollected = 10
|
||||
var collected = 0
|
||||
var previousTime: DateTime? = null
|
||||
flow.takeWhile {
|
||||
collected < mustBeCollected
|
||||
}.collect {
|
||||
previousTime ?.let { previousTime ->
|
||||
assertEquals(previousTime + 1.seconds, it)
|
||||
}
|
||||
previousTime = it
|
||||
collected++
|
||||
}
|
||||
assertEquals(mustBeCollected, collected)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testThatFlowIsCorrectlyWorkEverySecondBuiltOnString() {
|
||||
makeSimpleEverySecondTest("*/1 * * * *")
|
||||
}
|
||||
@Test
|
||||
fun testThatFlowIsCorrectlyWorkEverySecondBuiltOnStringWithWrongAmountOfSpaces() {
|
||||
val templatesFirstReplacers = listOf(
|
||||
"*/1",
|
||||
"*",
|
||||
"/1",
|
||||
"f,/1",
|
||||
)
|
||||
templatesFirstReplacers.forEach { replacer ->
|
||||
makeSimpleEverySecondTest("$replacer * * * * ")
|
||||
val kronScheduler = buildSchedule("*/1 * * * * ")
|
||||
|
||||
val flow = kronScheduler.asFlowWithoutDelays()
|
||||
|
||||
runTest {
|
||||
val mustBeCollected = 10
|
||||
var collected = 0
|
||||
flow.takeWhile {
|
||||
collected < mustBeCollected
|
||||
}.collect {
|
||||
collected++
|
||||
}
|
||||
assertEquals(mustBeCollected, collected)
|
||||
}
|
||||
}
|
||||
@Test
|
||||
fun testThatFlowIsCorrectlyWorkEverySecondBuiltOnStringWithGarbageInTemplate() {
|
||||
makeSimpleEverySecondTest(" sdf */1 * * * oo * ")
|
||||
val kronScheduler = buildSchedule(" sdf */1 * * * oo * ")
|
||||
|
||||
val flow = kronScheduler.asFlowWithoutDelays()
|
||||
|
||||
runTest {
|
||||
val mustBeCollected = 10
|
||||
var collected = 0
|
||||
flow.takeWhile {
|
||||
collected < mustBeCollected
|
||||
}.collect {
|
||||
collected++
|
||||
}
|
||||
assertEquals(mustBeCollected, collected)
|
||||
}
|
||||
}
|
||||
@Test
|
||||
fun testThatFlowIsCorrectlyWorkEverySecondBuiltOnStringWithInsufficientArgsInTemplate() {
|
||||
makeSimpleEverySecondTest(" sdf */1 ")
|
||||
val kronScheduler = buildSchedule(" sdf */1 ")
|
||||
|
||||
val flow = kronScheduler.asFlowWithoutDelays()
|
||||
|
||||
runTest {
|
||||
val mustBeCollected = 10
|
||||
var collected = 0
|
||||
flow.takeWhile {
|
||||
collected < mustBeCollected
|
||||
}.collect {
|
||||
collected++
|
||||
}
|
||||
assertEquals(mustBeCollected, collected)
|
||||
}
|
||||
}
|
||||
@Test
|
||||
fun testThatFlowIsCorrectlyWorkEverySecondWhenMillisIsHalfOfSecondBuiltOnString() {
|
||||
@ -67,14 +88,9 @@ class StringParseTest {
|
||||
runTest {
|
||||
val mustBeCollected = 10
|
||||
var collected = 0
|
||||
var previousTime: DateTime? = null
|
||||
flow.takeWhile {
|
||||
collected < mustBeCollected
|
||||
}.collect {
|
||||
previousTime ?.let { previousTime ->
|
||||
assertEquals(previousTime.copy(milliseconds = 500) + 1.seconds, it)
|
||||
}
|
||||
previousTime = it
|
||||
collected++
|
||||
}
|
||||
assertEquals(mustBeCollected, collected)
|
||||
|
Loading…
Reference in New Issue
Block a user