()
| 906 | #[cfg(test)] |
| 907 | mod 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 | }) |
nothing calls this directly
no test coverage detected