@@ -15,11 +15,11 @@ class LocalDateTimeFormatTest {
15
15
16
16
@Test
17
17
fun testErrorHandling () {
18
- val format = LocalDateTime .Formats .ISO
19
- assertEquals(LocalDateTime (2023 , 2 , 28 , 15 , 36 ), format. parse(" 2023-02-28T15:36" ))
20
- val error = assertFailsWith< DateTimeFormatException > { format.parse (" 2023-02-40T15:36" ) }
21
- assertContains(error.message !! , " 40 " )
22
- assertFailsWith< DateTimeFormatException > { format.parse( " 2023-02-XXT15:36 " ) }
18
+ LocalDateTime .Formats .ISO . apply {
19
+ assertEquals(LocalDateTime (2023 , 2 , 28 , 15 , 36 ), parse(" 2023-02-28T15:36" ))
20
+ assertCanNotParse (" 2023-02-40T15:36" )
21
+ assertCanNotParse( " 2023-02-XXT15:36 " )
22
+ }
23
23
}
24
24
25
25
@Test
@@ -163,7 +163,7 @@ class LocalDateTimeFormatTest {
163
163
put(LocalDateTime (123456 , 1 , 1 , 13 , 44 , 0 , 0 ), (" +123456- 1- 1 13:44: 0" to setOf ()))
164
164
put(LocalDateTime (- 123456 , 1 , 1 , 13 , 44 , 0 , 0 ), (" -123456- 1- 1 13:44: 0" to setOf ()))
165
165
}
166
- val format = LocalDateTime .Format {
166
+ LocalDateTime .Format {
167
167
year(Padding .SPACE )
168
168
char(' -' )
169
169
monthNumber(Padding .SPACE )
@@ -175,17 +175,18 @@ class LocalDateTimeFormatTest {
175
175
minute(Padding .SPACE )
176
176
char(' :' )
177
177
second(Padding .SPACE )
178
+ }.apply {
179
+ test(dateTimes, this )
180
+ parse(" 008- 7- 5 0: 0: 0" )
181
+ assertCanNotParse(" 008- 7- 5 0: 0: 0" )
182
+ assertCanNotParse(" 8- 7- 5 0: 0: 0" )
183
+ assertCanNotParse(" 008- 7- 5 0: 0: 0" )
184
+ assertCanNotParse(" 008-7- 5 0: 0: 0" )
185
+ assertCanNotParse(" +008- 7- 5 0: 0: 0" )
186
+ assertCanNotParse(" -08- 7- 5 0: 0: 0" )
187
+ assertCanNotParse(" -08- 7- 5 0: 0: 0" )
188
+ assertCanNotParse(" -8- 7- 5 0: 0: 0" )
178
189
}
179
- test(dateTimes, format)
180
- format.parse(" 008- 7- 5 0: 0: 0" )
181
- assertFailsWith<DateTimeFormatException > { format.parse(" 008- 7- 5 0: 0: 0" ) }
182
- assertFailsWith<DateTimeFormatException > { format.parse(" 8- 7- 5 0: 0: 0" ) }
183
- assertFailsWith<DateTimeFormatException > { format.parse(" 008- 7- 5 0: 0: 0" ) }
184
- assertFailsWith<DateTimeFormatException > { format.parse(" 008-7- 5 0: 0: 0" ) }
185
- assertFailsWith<DateTimeFormatException > { format.parse(" +008- 7- 5 0: 0: 0" ) }
186
- assertFailsWith<DateTimeFormatException > { format.parse(" -08- 7- 5 0: 0: 0" ) }
187
- assertFailsWith<DateTimeFormatException > { format.parse(" -08- 7- 5 0: 0: 0" ) }
188
- assertFailsWith<DateTimeFormatException > { format.parse(" -8- 7- 5 0: 0: 0" ) }
189
190
}
190
191
191
192
@Test
0 commit comments