()
| 470 | |
| 471 | #[test] |
| 472 | fn test_parse_decimal() { |
| 473 | // Supported cases |
| 474 | let cases = [ |
| 475 | ("0", ScalarValue::Decimal128(Some(0), 1, 0)), |
| 476 | ("1", ScalarValue::Decimal128(Some(1), 1, 0)), |
| 477 | ("123.45", ScalarValue::Decimal128(Some(12345), 5, 2)), |
| 478 | // Digit count is less than scale |
| 479 | ("0.001", ScalarValue::Decimal128(Some(1), 3, 3)), |
| 480 | // Scientific notation |
| 481 | ("123.456e-2", ScalarValue::Decimal128(Some(123456), 6, 5)), |
| 482 | // Negative scale |
| 483 | ("123456e128", ScalarValue::Decimal128(Some(123456), 6, -128)), |
| 484 | // Decimal256 |
| 485 | ( |
| 486 | &("9".repeat(39) + "." + "99999"), |
| 487 | ScalarValue::Decimal256( |
| 488 | Some(i256::from_string(&"9".repeat(44)).unwrap()), |
| 489 | 44, |
| 490 | 5, |
| 491 | ), |
| 492 | ), |
| 493 | ]; |
| 494 | for (input, expect) in cases { |
| 495 | let output = parse_decimal(input, true).unwrap(); |
| 496 | assert_eq!( |
| 497 | output, |
| 498 | Expr::Literal(expect.arithmetic_negate().unwrap(), None) |
| 499 | ); |
| 500 | |
| 501 | let output = parse_decimal(input, false).unwrap(); |
| 502 | assert_eq!(output, Expr::Literal(expect, None)); |
| 503 | } |
| 504 | |
| 505 | // scale < i8::MIN |
| 506 | assert_eq!( |
| 507 | parse_decimal("1e129", false).unwrap_err().strip_backtrace(), |
| 508 | "This feature is not implemented: Decimal scale -129 exceeds the minimum supported scale: -128" |
| 509 | ); |
| 510 | |
| 511 | // Unsupported precision |
| 512 | assert_eq!( |
| 513 | parse_decimal(&"1".repeat(77), false) |
| 514 | .unwrap_err() |
| 515 | .strip_backtrace(), |
| 516 | "This feature is not implemented: Decimal precision 77 exceeds the maximum supported precision: 76" |
| 517 | ); |
| 518 | } |
| 519 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…