()
| 808 | |
| 809 | #[test] |
| 810 | fn test_string_view() { |
| 811 | let b1 = Buffer::from(b"world\xFFbananas\xF0\x9F\x98\x81"); |
| 812 | let b2 = Buffer::from(b"cupcakes"); |
| 813 | let b3 = Buffer::from(b"Many strings are here contained of great length and verbosity"); |
| 814 | |
| 815 | let mut v = StringViewBuilder::new(); |
| 816 | assert_eq!(v.append_block(b1), 0); |
| 817 | |
| 818 | v.append_value("This is a very long string that exceeds the inline length"); |
| 819 | v.append_value("This is another very long string that exceeds the inline length"); |
| 820 | |
| 821 | assert_eq!(v.append_block(b2), 2); |
| 822 | assert_eq!(v.append_block(b3), 3); |
| 823 | |
| 824 | // Test short strings |
| 825 | v.try_append_view(0, 0, 5).unwrap(); // world |
| 826 | v.try_append_view(0, 6, 7).unwrap(); // bananas |
| 827 | v.try_append_view(2, 3, 5).unwrap(); // cake |
| 828 | v.try_append_view(2, 0, 3).unwrap(); // cup |
| 829 | v.try_append_view(2, 0, 8).unwrap(); // cupcakes |
| 830 | v.try_append_view(0, 13, 4).unwrap(); // 😁 |
| 831 | v.try_append_view(0, 13, 0).unwrap(); // |
| 832 | |
| 833 | // Test longer strings |
| 834 | v.try_append_view(3, 0, 16).unwrap(); // Many strings are |
| 835 | v.try_append_view(1, 0, 19).unwrap(); // This is a very long |
| 836 | v.try_append_view(3, 13, 27).unwrap(); // here contained of great length |
| 837 | |
| 838 | v.append_value("I do so like long strings"); |
| 839 | |
| 840 | let array = v.finish_cloned(); |
| 841 | array.to_data().validate_full().unwrap(); |
| 842 | assert_eq!(array.data_buffers().len(), 5); |
| 843 | let actual: Vec<_> = array.iter().flatten().collect(); |
| 844 | assert_eq!( |
| 845 | actual, |
| 846 | &[ |
| 847 | "This is a very long string that exceeds the inline length", |
| 848 | "This is another very long string that exceeds the inline length", |
| 849 | "world", |
| 850 | "bananas", |
| 851 | "cakes", |
| 852 | "cup", |
| 853 | "cupcakes", |
| 854 | "😁", |
| 855 | "", |
| 856 | "Many strings are", |
| 857 | "This is a very long", |
| 858 | "are here contained of great", |
| 859 | "I do so like long strings" |
| 860 | ] |
| 861 | ); |
| 862 | |
| 863 | let err = v.try_append_view(0, u32::MAX, 1).unwrap_err(); |
| 864 | assert_eq!( |
| 865 | err.to_string(), |
| 866 | "Invalid argument error: Range 4294967295..4294967296 out of bounds for block of length 17" |
| 867 | ); |
nothing calls this directly
no test coverage detected