@@ -590,24 +590,51 @@ where
590
590
#[ cfg( test) ]
591
591
mod tests {
592
592
use super :: * ;
593
+ use crate :: parse:: parse_decimal;
593
594
594
595
#[ test]
595
596
fn test_parse_string_to_decimal_native ( ) -> Result < ( ) , ArrowError > {
596
597
assert_eq ! (
597
598
parse_string_to_decimal_native:: <Decimal128Type >( "0" , 0 ) ?,
598
599
0_i128
599
600
) ;
601
+ assert_eq ! (
602
+ parse_decimal:: <Decimal128Type >( "0" , 38 , 0 ) ?,
603
+ parse_string_to_decimal_native:: <Decimal128Type >( "0" , 0 ) ?,
604
+ "value is {}" ,
605
+ 0_i128
606
+ ) ;
607
+
600
608
assert_eq ! (
601
609
parse_string_to_decimal_native:: <Decimal128Type >( "0" , 5 ) ?,
602
610
0_i128
603
611
) ;
612
+ assert_eq ! (
613
+ parse_decimal:: <Decimal128Type >( "0" , 38 , 5 ) ?,
614
+ parse_string_to_decimal_native:: <Decimal128Type >( "0" , 5 ) ?,
615
+ "value is {}" ,
616
+ 0_i128
617
+ ) ;
604
618
605
619
assert_eq ! (
606
620
parse_string_to_decimal_native:: <Decimal128Type >( "123" , 0 ) ?,
607
621
123_i128
608
622
) ;
609
623
assert_eq ! (
624
+ parse_decimal:: <Decimal128Type >( "123" , 38 , 0 ) ?,
625
+ parse_string_to_decimal_native:: <Decimal128Type >( "123" , 0 ) ?,
626
+ "value is {}" ,
627
+ 123_i128
628
+ ) ;
629
+
630
+ assert_eq ! (
631
+ parse_string_to_decimal_native:: <Decimal128Type >( "123" , 5 ) ?,
632
+ 12300000_i128
633
+ ) ;
634
+ assert_eq ! (
635
+ parse_decimal:: <Decimal128Type >( "123" , 38 , 5 ) ?,
610
636
parse_string_to_decimal_native:: <Decimal128Type >( "123" , 5 ) ?,
637
+ "value is {}" ,
611
638
12300000_i128
612
639
) ;
613
640
@@ -616,16 +643,42 @@ mod tests {
616
643
123_i128
617
644
) ;
618
645
assert_eq ! (
646
+ parse_decimal:: <Decimal128Type >( "123.45" , 38 , 0 ) ?,
647
+ parse_string_to_decimal_native:: <Decimal128Type >( "123.45" , 0 ) ?,
648
+ "value is {}" ,
649
+ 123_i128
650
+ ) ;
651
+
652
+ assert_eq ! (
653
+ parse_string_to_decimal_native:: <Decimal128Type >( "123.45" , 5 ) ?,
654
+ 12345000_i128
655
+ ) ;
656
+ assert_eq ! (
657
+ parse_decimal:: <Decimal128Type >( "123.45" , 38 , 5 ) ?,
619
658
parse_string_to_decimal_native:: <Decimal128Type >( "123.45" , 5 ) ?,
659
+ "value is {}" ,
620
660
12345000_i128
621
661
) ;
622
662
623
663
assert_eq ! (
624
- parse_string_to_decimal_native:: <Decimal128Type >( "123.4567891" , 0 ) ?,
625
- 123_i128
664
+ parse_string_to_decimal_native:: <Decimal128Type >( "123.4567891" , 5 ) ?,
665
+ 12345679_i128
666
+ ) ;
667
+ assert_eq ! (
668
+ parse_decimal:: <Decimal128Type >( "123.4567891" , 38 , 5 ) ?,
669
+ parse_string_to_decimal_native:: <Decimal128Type >( "123.4567891" , 5 ) ?,
670
+ "value is {}" ,
671
+ 12345679_i128
672
+ ) ;
673
+
674
+ assert_eq ! (
675
+ parse_string_to_decimal_native:: <Decimal128Type >( "123.4567891" , 5 ) ?,
676
+ 12345679_i128
626
677
) ;
627
678
assert_eq ! (
679
+ parse_decimal:: <Decimal128Type >( "123.4567891" , 38 , 5 ) ?,
628
680
parse_string_to_decimal_native:: <Decimal128Type >( "123.4567891" , 5 ) ?,
681
+ "value is {}" ,
629
682
12345679_i128
630
683
) ;
631
684
Ok ( ( ) )
0 commit comments