Skip to content

Commit 7e598c9

Browse files
committed
keep existing test for parse_string_to_decimal_native and add equivalency test with parse_decimal.
1 parent ae88078 commit 7e598c9

File tree

1 file changed

+55
-2
lines changed

1 file changed

+55
-2
lines changed

arrow-cast/src/cast/decimal.rs

+55-2
Original file line numberDiff line numberDiff line change
@@ -590,24 +590,51 @@ where
590590
#[cfg(test)]
591591
mod tests {
592592
use super::*;
593+
use crate::parse::parse_decimal;
593594

594595
#[test]
595596
fn test_parse_string_to_decimal_native() -> Result<(), ArrowError> {
596597
assert_eq!(
597598
parse_string_to_decimal_native::<Decimal128Type>("0", 0)?,
598599
0_i128
599600
);
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+
600608
assert_eq!(
601609
parse_string_to_decimal_native::<Decimal128Type>("0", 5)?,
602610
0_i128
603611
);
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+
);
604618

605619
assert_eq!(
606620
parse_string_to_decimal_native::<Decimal128Type>("123", 0)?,
607621
123_i128
608622
);
609623
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)?,
610636
parse_string_to_decimal_native::<Decimal128Type>("123", 5)?,
637+
"value is {}",
611638
12300000_i128
612639
);
613640

@@ -616,16 +643,42 @@ mod tests {
616643
123_i128
617644
);
618645
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)?,
619658
parse_string_to_decimal_native::<Decimal128Type>("123.45", 5)?,
659+
"value is {}",
620660
12345000_i128
621661
);
622662

623663
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
626677
);
627678
assert_eq!(
679+
parse_decimal::<Decimal128Type>("123.4567891", 38, 5)?,
628680
parse_string_to_decimal_native::<Decimal128Type>("123.4567891", 5)?,
681+
"value is {}",
629682
12345679_i128
630683
);
631684
Ok(())

0 commit comments

Comments
 (0)