-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Valentin Rocher
authored
Feb 28, 2022
1 parent
46740fb
commit baed32d
Showing
10 changed files
with
2,095 additions
and
17 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
77 changes: 77 additions & 0 deletions
77
ktoml-core/src/commonTest/kotlin/com/akuleshov7/ktoml/decoders/DateTimeDecoderTest.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,77 @@ | ||
package com.akuleshov7.ktoml.decoders | ||
|
||
import com.akuleshov7.ktoml.Toml | ||
import com.akuleshov7.ktoml.exceptions.ParseException | ||
import kotlinx.datetime.* | ||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.decodeFromString | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertFailsWith | ||
|
||
class DateTimeDecoderTest { | ||
|
||
@Serializable | ||
data class TimeTable( | ||
val instants: List<Instant>, | ||
val localDateTimes: List<LocalDateTime>, | ||
val localDate: LocalDate, | ||
val dateInString: String | ||
) | ||
|
||
@Test | ||
fun testDateParsing() { | ||
val toml = """ | ||
instants = [1979-05-27T07:32:00Z, 1979-05-27T00:32:00-07:00, 1979-05-27T00:32:00.999999-07:00, 1979-05-27 07:32:00Z] | ||
localDateTimes = [1979-05-27T07:32:00, 1979-05-27T00:32:00.999999] | ||
localDate = 1979-05-27 | ||
dateInString = "1979-05-27T00:32:00-07:00" | ||
""".trimIndent() | ||
val expectedInstants = listOf( | ||
LocalDateTime(1979, 5, 27, 7, 32, 0) | ||
.toInstant(TimeZone.UTC), | ||
LocalDateTime(1979, 5, 27, 0, 32, 0) | ||
.toInstant(TimeZone.of("UTC-7")), | ||
LocalDateTime(1979, 5, 27, 0, 32, 0, 999999000) | ||
.toInstant(TimeZone.of("UTC-7")), | ||
LocalDateTime(1979, 5, 27, 7, 32, 0) | ||
.toInstant(TimeZone.UTC), | ||
) | ||
val expectedLocalDateTimes = listOf( | ||
LocalDateTime(1979, 5, 27, 7, 32, 0), | ||
LocalDateTime(1979, 5, 27, 0, 32, 0, 999999000) | ||
) | ||
val expectedLocalDate = LocalDate(1979, 5, 27) | ||
assertEquals( | ||
TimeTable( | ||
expectedInstants, | ||
expectedLocalDateTimes, | ||
expectedLocalDate, | ||
"1979-05-27T00:32:00-07:00" | ||
), | ||
Toml().decodeFromString(toml) | ||
) | ||
} | ||
|
||
@Serializable | ||
data class InvalidInstant(val instant: Instant) | ||
|
||
@Serializable | ||
data class InvalidDateTime(val dateTime: LocalDateTime) | ||
|
||
@Serializable | ||
data class InvalidDate(val date: LocalDate) | ||
|
||
@Test | ||
fun testInvalidData() { | ||
assertFailsWith<ParseException> { | ||
Toml.decodeFromString<InvalidInstant>("instant=1979-05-27T07:32:00INVALID") | ||
} | ||
assertFailsWith<ParseException> { | ||
Toml.decodeFromString<InvalidDateTime>("dateTime=1979/05/27T07:32:00") | ||
} | ||
assertFailsWith<ParseException> { | ||
Toml.decodeFromString<InvalidDate>("date=1979/05/27") | ||
} | ||
} | ||
} |
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