@@ -2386,6 +2386,8 @@ fn trim_trailing_0s_hex(number: &str) -> &str {
23862386#[ cfg( test) ]
23872387mod tests {
23882388 use super :: * ;
2389+ use crate :: function:: utils:: test:: test_scalar_function;
2390+ use arrow:: array:: StringArray ;
23892391 use arrow:: datatypes:: DataType :: Utf8 ;
23902392 use datafusion_common:: Result ;
23912393
@@ -2417,4 +2419,51 @@ mod tests {
24172419
24182420 Ok ( ( ) )
24192421 }
2422+
2423+ #[ test]
2424+ fn test_insert_thousands_separator ( ) {
2425+ assert_eq ! ( insert_thousands_separator( "1234567.89" ) , "1,234,567.89" ) ;
2426+ assert_eq ! ( insert_thousands_separator( "123.45" ) , "123.45" ) ;
2427+ assert_eq ! ( insert_thousands_separator( "1234" ) , "1,234" ) ;
2428+ assert_eq ! ( insert_thousands_separator( "12" ) , "12" ) ;
2429+ assert_eq ! ( insert_thousands_separator( "0.5" ) , "0.5" ) ;
2430+ assert_eq ! (
2431+ insert_thousands_separator( "1234567890.1234" ) ,
2432+ "1,234,567,890.1234"
2433+ ) ;
2434+ assert_eq ! ( insert_thousands_separator( "1000" ) , "1,000" ) ;
2435+ assert_eq ! ( insert_thousands_separator( "100" ) , "100" ) ;
2436+ }
2437+
2438+ #[ test]
2439+ fn test_grouping_separator_float ( ) -> Result < ( ) > {
2440+ test_scalar_function ! (
2441+ FormatStringFunc :: new( ) ,
2442+ vec![
2443+ ColumnarValue :: Scalar ( ScalarValue :: Utf8 ( Some ( "%,.2f" . to_string( ) ) ) ) ,
2444+ ColumnarValue :: Scalar ( ScalarValue :: Float64 ( Some ( 1234567.89 ) ) ) ,
2445+ ] ,
2446+ Ok ( Some ( "1,234,567.89" ) ) ,
2447+ & str ,
2448+ Utf8 ,
2449+ StringArray
2450+ ) ;
2451+ Ok ( ( ) )
2452+ }
2453+
2454+ #[ test]
2455+ fn test_grouping_separator_decimal ( ) -> Result < ( ) > {
2456+ test_scalar_function ! (
2457+ FormatStringFunc :: new( ) ,
2458+ vec![
2459+ ColumnarValue :: Scalar ( ScalarValue :: Utf8 ( Some ( "%,.2f" . to_string( ) ) ) ) ,
2460+ ColumnarValue :: Scalar ( ScalarValue :: Decimal128 ( Some ( 123456789 ) , 10 , 2 ) ) ,
2461+ ] ,
2462+ Ok ( Some ( "1,234,567.89" ) ) ,
2463+ & str ,
2464+ Utf8 ,
2465+ StringArray
2466+ ) ;
2467+ Ok ( ( ) )
2468+ }
24202469}
0 commit comments