MCPcopy Create free account
hub / github.com/awslabs/llrt / test_subarray_partial

Function test_subarray_partial

modules/llrt_buffer/src/buffer.rs:908–937  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

906#[cfg(test)]
907mod tests {
908 use llrt_test::{call_test, test_async_with, ModuleEvaluator};
909
910 use crate::BufferModule;
911
912 #[tokio::test]
913 async fn test_subarray() {
914 test_async_with(|ctx| {
915 Box::pin(async move {
916 crate::init(&ctx).unwrap();
917 ModuleEvaluator::eval_rust::<BufferModule>(ctx.clone(), "buffer")
918 .await
919 .unwrap();
920
921 let data = "hello world".to_string().into_bytes();
922 let module = ModuleEvaluator::eval_js(
923 ctx.clone(),
924 "test",
925 r#"
926 import { Buffer } from 'buffer';
927
928 export async function test(data) {
929 let buffer = Buffer.from(data);
930 let sub = buffer.subarray(6, 11); // "world" part
931 return sub.toString();
932 }
933 "#,
934 )
935 .await
936 .unwrap();
937 let result = call_test::<String, _>(&ctx, &module, (data,)).await;
938 assert_eq!(result, "world");
939 })
940 })

Callers

nothing calls this directly

Calls 5

test_async_withFunction · 0.85
into_bytesMethod · 0.80
initFunction · 0.70
cloneMethod · 0.45
to_stringMethod · 0.45

Tested by

no test coverage detected