()
| 635 | |
| 636 | #[test] |
| 637 | fn try_new() { |
| 638 | let data = Buffer::from_slice_ref("helloworld"); |
| 639 | let offsets = OffsetBuffer::new(vec![0, 5, 10].into()); |
| 640 | StringArray::new(offsets.clone(), data.clone(), None); |
| 641 | |
| 642 | let nulls = NullBuffer::new_null(3); |
| 643 | let err = |
| 644 | StringArray::try_new(offsets.clone(), data.clone(), Some(nulls.clone())).unwrap_err(); |
| 645 | assert_eq!( |
| 646 | err.to_string(), |
| 647 | "Invalid argument error: Incorrect length of null buffer for StringArray, expected 2 got 3" |
| 648 | ); |
| 649 | |
| 650 | let err = BinaryArray::try_new(offsets.clone(), data.clone(), Some(nulls)).unwrap_err(); |
| 651 | assert_eq!( |
| 652 | err.to_string(), |
| 653 | "Invalid argument error: Incorrect length of null buffer for BinaryArray, expected 2 got 3" |
| 654 | ); |
| 655 | |
| 656 | let non_utf8_data = Buffer::from_slice_ref(b"he\xFFloworld"); |
| 657 | let err = StringArray::try_new(offsets.clone(), non_utf8_data.clone(), None).unwrap_err(); |
| 658 | assert_eq!( |
| 659 | err.to_string(), |
| 660 | "Invalid argument error: Encountered non UTF-8 data: invalid utf-8 sequence of 1 bytes from index 2" |
| 661 | ); |
| 662 | |
| 663 | BinaryArray::new(offsets, non_utf8_data, None); |
| 664 | |
| 665 | let offsets = OffsetBuffer::new(vec![0, 5, 11].into()); |
| 666 | let err = StringArray::try_new(offsets.clone(), data.clone(), None).unwrap_err(); |
| 667 | assert_eq!( |
| 668 | err.to_string(), |
| 669 | "Invalid argument error: Offset of 11 exceeds length of values 10" |
| 670 | ); |
| 671 | |
| 672 | let err = BinaryArray::try_new(offsets.clone(), data, None).unwrap_err(); |
| 673 | assert_eq!( |
| 674 | err.to_string(), |
| 675 | "Invalid argument error: Maximum offset of 11 is larger than values of length 10" |
| 676 | ); |
| 677 | |
| 678 | let non_ascii_data = Buffer::from_slice_ref("heìloworld"); |
| 679 | StringArray::new(offsets.clone(), non_ascii_data.clone(), None); |
| 680 | BinaryArray::new(offsets, non_ascii_data.clone(), None); |
| 681 | |
| 682 | let offsets = OffsetBuffer::new(vec![0, 3, 10].into()); |
| 683 | let err = StringArray::try_new(offsets.clone(), non_ascii_data.clone(), None).unwrap_err(); |
| 684 | assert_eq!( |
| 685 | err.to_string(), |
| 686 | "Invalid argument error: Split UTF-8 codepoint at offset 3" |
| 687 | ); |
| 688 | |
| 689 | BinaryArray::new(offsets, non_ascii_data, None); |
| 690 | } |
| 691 | |
| 692 | #[test] |
| 693 | fn create_repeated() { |
no test coverage detected