11package org.jetbrains.kotlinx.dataframe.io
22
3- import io.kotest.assertions.throwables.shouldThrow
43import io.kotest.matchers.shouldBe
54import kotlinx.datetime.LocalDateTime
65import kotlinx.datetime.LocalTime
@@ -145,9 +144,9 @@ class ParserTests {
145144 parsed.toList() shouldBe listOf (1 , 2 , null , 3 , null , null , 4.0 , 5.0 )
146145 }
147146
148- @Test // This does not yet use fastDoubleParser!
147+ @Test
149148 fun `converting String to Double in different locales` () {
150- val currentLocale = Locale .getDefault()
149+ val systemLocale = Locale .getDefault()
151150 try {
152151 // Test 45 behaviour combinations:
153152
@@ -157,11 +156,12 @@ class ParserTests {
157156 val columnMixed = columnOf(" 12.345" , " 67,890" )
158157 // *
159158 // (3 locales as converting parameter + original converting + original converting to nullable)
160- val parsingLocaleNotDefined: Locale ? = null
159+ val parsingLocaleNotDefined: Locale ? = null // takes parserOptions.locale ?: Locale.getDefault()
161160 val parsingLocaleUsesDot: Locale = Locale .forLanguageTag(" en-US" )
162161 val parsingLocaleUsesComma: Locale = Locale .forLanguageTag(" ru-RU" )
163162 // *
164163 // 3 system locales
164+ // --------------------------------------------------------------------------------
165165
166166 Locale .setDefault(Locale .forLanguageTag(" C.UTF-8" ))
167167
@@ -181,9 +181,13 @@ class ParserTests {
181181 columnComma.convertToDouble(parsingLocaleUsesDot) shouldBe columnOf(12345.0 , 67890.0 )
182182 columnMixed.convertToDouble(parsingLocaleUsesDot) shouldBe columnOf(12.345 , 67890.0 )
183183
184- shouldThrow<TypeConversionException > { columnDot.convertToDouble(parsingLocaleUsesComma) }
184+ // uses fallback to ROOT locale
185+ columnDot.convertToDouble(parsingLocaleUsesComma) shouldBe columnOf(12.345 , 67.89 )
185186 columnComma.convertToDouble(parsingLocaleUsesComma) shouldBe columnOf(12.345 , 67.89 )
186- shouldThrow<TypeConversionException > { columnMixed.convertToDouble(parsingLocaleUsesComma) }
187+ // uses fallback to ROOT locale
188+ columnMixed.convertToDouble(parsingLocaleUsesComma) shouldBe columnOf(12.345 , 67.89 )
189+
190+ // --------------------------------------------------------------------------------
187191
188192 Locale .setDefault(Locale .forLanguageTag(" en-US" ))
189193
@@ -203,33 +207,42 @@ class ParserTests {
203207 columnComma.convertToDouble(parsingLocaleUsesDot) shouldBe columnOf(12345.0 , 67890.0 )
204208 columnMixed.convertToDouble(parsingLocaleUsesDot) shouldBe columnOf(12.345 , 67890.0 )
205209
206- shouldThrow<TypeConversionException > { columnDot.convertToDouble(parsingLocaleUsesComma) }
210+ // uses fallback to ROOT locale
211+ columnDot.convertToDouble(parsingLocaleUsesComma) shouldBe columnOf(12.345 , 67.89 )
207212 columnComma.convertToDouble(parsingLocaleUsesComma) shouldBe columnOf(12.345 , 67.89 )
208- shouldThrow<TypeConversionException > { columnMixed.convertToDouble(parsingLocaleUsesComma) }
213+ // uses fallback to ROOT locale
214+ columnMixed.convertToDouble(parsingLocaleUsesComma) shouldBe columnOf(12.345 , 67.89 )
215+
216+ // --------------------------------------------------------------------------------
209217
210218 Locale .setDefault(Locale .forLanguageTag(" ru-RU" ))
211219
212220 columnDot.convertTo<Double >() shouldBe columnOf(12.345 , 67.89 )
213221 columnComma.convertTo<Double >() shouldBe columnOf(12.345 , 67.89 )
214- columnMixed.convertTo<Double >() shouldBe columnOf(12.345 , 67890.0 )
222+ // uses fallback to ROOT locale
223+ columnMixed.convertTo<Double >() shouldBe columnOf(12.345 , 67.89 )
215224
216225 columnDot.convertTo<Double ?>() shouldBe columnOf(12.345 , 67.89 )
217226 columnComma.convertTo<Double ?>() shouldBe columnOf(12.345 , 67.89 )
218- columnMixed.convertTo<Double ?>() shouldBe columnOf(12.345 , 67890.0 )
227+ // uses fallback to ROOT locale
228+ columnMixed.convertTo<Double ?>() shouldBe columnOf(12.345 , 67.89 )
219229
220230 columnDot.convertToDouble(parsingLocaleNotDefined) shouldBe columnOf(12.345 , 67.89 )
221231 columnComma.convertToDouble(parsingLocaleNotDefined) shouldBe columnOf(12.345 , 67.89 )
222- columnMixed.convertToDouble(parsingLocaleNotDefined) shouldBe columnOf(12.345 , 67890.0 )
232+ // uses fallback to ROOT locale
233+ columnMixed.convertToDouble(parsingLocaleNotDefined) shouldBe columnOf(12.345 , 67.89 )
223234
224235 columnDot.convertToDouble(parsingLocaleUsesDot) shouldBe columnOf(12.345 , 67.89 )
225236 columnComma.convertToDouble(parsingLocaleUsesDot) shouldBe columnOf(12345.0 , 67890.0 )
226237 columnMixed.convertToDouble(parsingLocaleUsesDot) shouldBe columnOf(12.345 , 67890.0 )
227238
228- shouldThrow<TypeConversionException > { columnDot.convertToDouble(parsingLocaleUsesComma) }
239+ // uses fallback to ROOT locale
240+ columnDot.convertToDouble(parsingLocaleUsesComma) shouldBe columnOf(12.345 , 67.89 )
229241 columnComma.convertToDouble(parsingLocaleUsesComma) shouldBe columnOf(12.345 , 67.89 )
230- shouldThrow<TypeConversionException > { columnMixed.convertToDouble(parsingLocaleUsesComma) }
242+ // uses fallback to ROOT locale
243+ columnMixed.convertToDouble(parsingLocaleUsesComma) shouldBe columnOf(12.345 , 67.89 )
231244 } finally {
232- Locale .setDefault(currentLocale )
245+ Locale .setDefault(systemLocale )
233246 }
234247 }
235248
0 commit comments