MCPcopy Create free account
hub / github.com/apache/arrow-rs / test_utf8_validation

Function test_utf8_validation

parquet/src/arrow/buffer/offset_buffer.rs:294–331  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

292
293 #[test]
294 fn test_utf8_validation() {
295 let valid_2_byte_utf8 = &[0b11001000, 0b10001000];
296 std::str::from_utf8(valid_2_byte_utf8).unwrap();
297 let valid_3_byte_utf8 = &[0b11101000, 0b10001000, 0b10001000];
298 std::str::from_utf8(valid_3_byte_utf8).unwrap();
299 let valid_4_byte_utf8 = &[0b11110010, 0b10101000, 0b10101001, 0b10100101];
300 std::str::from_utf8(valid_4_byte_utf8).unwrap();
301
302 let mut buffer = OffsetBuffer::<i32>::with_capacity(0);
303 buffer.try_push(valid_2_byte_utf8, true).unwrap();
304 buffer.try_push(valid_3_byte_utf8, true).unwrap();
305 buffer.try_push(valid_4_byte_utf8, true).unwrap();
306
307 // Cannot append string starting with incomplete codepoint
308 buffer.try_push(&valid_2_byte_utf8[1..], true).unwrap_err();
309 buffer.try_push(&valid_3_byte_utf8[1..], true).unwrap_err();
310 buffer.try_push(&valid_3_byte_utf8[2..], true).unwrap_err();
311 buffer.try_push(&valid_4_byte_utf8[1..], true).unwrap_err();
312 buffer.try_push(&valid_4_byte_utf8[2..], true).unwrap_err();
313 buffer.try_push(&valid_4_byte_utf8[3..], true).unwrap_err();
314
315 // Can append data containing an incomplete codepoint
316 buffer.try_push(&[0b01111111, 0b10111111], true).unwrap();
317
318 assert_eq!(buffer.len(), 4);
319 assert_eq!(buffer.values.len(), 11);
320
321 buffer.try_push(valid_3_byte_utf8, true).unwrap();
322
323 // Should fail due to incomplete codepoint
324 buffer.check_valid_utf8(0).unwrap_err();
325
326 // After broken codepoint -> success
327 buffer.check_valid_utf8(11).unwrap();
328
329 // Fails if run from middle of codepoint
330 buffer.check_valid_utf8(12).unwrap_err();
331 }
332
333 #[test]
334 fn test_pad_nulls_empty() {

Callers

nothing calls this directly

Calls 2

try_pushMethod · 0.80
check_valid_utf8Method · 0.80

Tested by

no test coverage detected