MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / raw_string_encodings

Function raw_string_encodings

tests/all/component_model/strings.rs:432–490  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

430// Test that that the pointer returned from `realloc` is bounds-checked.
431#[test]
432fn raw_string_encodings() -> Result<()> {
433 let engine = wasmtime_test_util::component::engine();
434 test_invalid_string_encoding(&engine, "utf8", "utf8", &[0xff], 1)?;
435 let array = b"valid string until \xffthen valid again";
436 test_invalid_string_encoding(&engine, "utf8", "utf8", array, array.len() as u32)?;
437 test_invalid_string_encoding(&engine, "utf8", "utf16", array, array.len() as u32)?;
438 let array = b"symbol \xce\xa3 until \xffthen valid";
439 test_invalid_string_encoding(&engine, "utf8", "utf8", array, array.len() as u32)?;
440 test_invalid_string_encoding(&engine, "utf8", "utf16", array, array.len() as u32)?;
441 test_invalid_string_encoding(&engine, "utf8", "latin1+utf16", array, array.len() as u32)?;
442 test_invalid_string_encoding(&engine, "utf16", "utf8", &[0x01, 0xd8], 1)?;
443 test_invalid_string_encoding(&engine, "utf16", "utf16", &[0x01, 0xd8], 1)?;
444 test_invalid_string_encoding(
445 &engine,
446 "utf16",
447 "latin1+utf16",
448 &[0xff, 0xff, 0x01, 0xd8],
449 2,
450 )?;
451 test_invalid_string_encoding(
452 &engine,
453 "latin1+utf16",
454 "utf8",
455 &[0x01, 0xd8],
456 1 | UTF16_TAG,
457 )?;
458 test_invalid_string_encoding(
459 &engine,
460 "latin1+utf16",
461 "utf16",
462 &[0x01, 0xd8],
463 1 | UTF16_TAG,
464 )?;
465 test_invalid_string_encoding(
466 &engine,
467 "latin1+utf16",
468 "utf16",
469 &[0xff, 0xff, 0x01, 0xd8],
470 2 | UTF16_TAG,
471 )?;
472 test_invalid_string_encoding(
473 &engine,
474 "latin1+utf16",
475 "latin1+utf16",
476 &[0xab, 0x00, 0xff, 0xff, 0x01, 0xd8],
477 3 | UTF16_TAG,
478 )?;
479
480 // This latin1+utf16 string should get compressed to latin1 across the
481 // boundary.
482 test_valid_string_encoding(
483 &engine,
484 "latin1+utf16",
485 "latin1+utf16",
486 &[0xab, 0x00, 0xff, 0x00],
487 2 | UTF16_TAG,
488 )?;
489 Ok(())

Callers

nothing calls this directly

Calls 5

OkFunction · 0.85
engineFunction · 0.50
lenMethod · 0.45

Tested by

no test coverage detected