Skip to content

Commit

Permalink
add test to MessageParserTest.kt
Browse files Browse the repository at this point in the history
  • Loading branch information
vitormarcal committed Feb 22, 2024
1 parent a52a068 commit f8b9a9e
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ class MessageParserTest {
"16.11.2023. 18:44",
"16.11.23, 18:44",
"2023.11.16, 18:44",
"2/22/24, 12:06"
).forEach {
assertEquals(it, MessageParser().extractTextDate(it))
assertEquals(it, MessageParser().extractTextDate("${it}xyz"))
Expand All @@ -193,6 +194,7 @@ class MessageParserTest {
assertEquals("[${it}pm]", MessageParser().extractTextDate("[${it}pm]"))
assertEquals("[${it}am]", MessageParser().extractTextDate("[${it}am]"))
assertEquals("[${it}]", MessageParser().extractTextDate("[${it}]"))
assertEquals("[${it}]", MessageParser().extractTextDate("[${it}]"))
}
}

Expand All @@ -207,13 +209,15 @@ class MessageParserTest {
assertEquals(LocalDateTime.of(2023, 11, 16, 18, 44), MessageParser().parseDate("16/ 11/ 23/ 18:44"))
assertEquals(LocalDateTime.of(2023, 11, 16, 18, 44), MessageParser().parseDate("16-11-23 18:44"))
assertEquals(LocalDateTime.of(2023, 11, 16, 18, 44), MessageParser().parseDate("[16-11-23 18:44]"))
assertEquals(LocalDateTime.of(2024, 2, 22, 12, 6), MessageParser().parseDate("2/22/24, 12:06"))
}


@Test
fun `based on previous resolved dates, should resolve ambiguity`() {
MessageParser().apply {
assertEquals(LocalDateTime.of(2023, 1, 16, 18, 44), this.parseDate("01/16/2023 18:44"))
assertEquals(LocalDateTime.of(2024, 2, 22, 12, 6), this.parseDate("2/22/24, 12:06"))
assertEquals(LocalDateTime.of(2023, 1, 1, 18, 44), this.parseDate("01/01/2023 18:44"))
assertEquals(LocalDateTime.of(2023, 2, 1, 18, 44), this.parseDate("02/01/2023 18:44"))
assertEquals(LocalDateTime.of(2023, 3, 1, 18, 44), this.parseDate("03/01/2023 18:44"))
Expand All @@ -237,6 +241,7 @@ class MessageParserTest {
MessageParser().apply {
assertEquals(LocalDateTime.of(2023, 1, 16, 18, 44), this.parseDate("1/16/2023 18:44"))
assertEquals(LocalDateTime.of(2023, 1, 1, 18, 44), this.parseDate("1/1/2023 18:44"))
assertEquals(LocalDateTime.of(2024, 2, 22, 12, 6), this.parseDate("2/22/24, 12:06"))
}
}

Expand All @@ -250,6 +255,10 @@ class MessageParserTest {
assertEquals(LocalDateTime.of(2023, 5, 1, 18, 44), this.parseDate("05/01/2023 18:44"))
assertEquals(LocalDateTime.of(2023, 6, 1, 18, 44), this.parseDate("06/01/2023 18:44"))
}
MessageParser("M/dd/yy, HH:mm").apply {
assertEquals(LocalDateTime.of(2024, 2, 22, 12, 6), this.parseDate("2/22/24, 12:06"))
assertEquals(LocalDateTime.of(2024, 2, 22, 12, 6), this.parseDate("02/22/24, 12:06"))
}

MessageParser("dd/MM/yyyy HH:mm").apply {
assertEquals(LocalDateTime.of(2023, 1, 1, 18, 44), this.parseDate("01/01/2023 18:44"))
Expand Down

0 comments on commit f8b9a9e

Please sign in to comment.