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