summaryrefslogtreecommitdiff
path: root/test_plugin
diff options
context:
space:
mode:
Diffstat (limited to 'test_plugin')
-rw-r--r--test_plugin/src/lib.rs30
-rw-r--r--test_plugin/tests/integration_tests.rs2
-rw-r--r--test_plugin/tests/test.js13
3 files changed, 26 insertions, 19 deletions
diff --git a/test_plugin/src/lib.rs b/test_plugin/src/lib.rs
index 37868b310..781bc4259 100644
--- a/test_plugin/src/lib.rs
+++ b/test_plugin/src/lib.rs
@@ -13,15 +13,16 @@ pub fn deno_plugin_init(interface: &mut dyn Interface) {
fn op_test_sync(
_interface: &mut dyn Interface,
data: &[u8],
- zero_copy: Option<ZeroCopyBuf>,
+ zero_copy: &mut [ZeroCopyBuf],
) -> Op {
- if let Some(buf) = zero_copy {
- let data_str = std::str::from_utf8(&data[..]).unwrap();
+ let data_str = std::str::from_utf8(&data[..]).unwrap();
+ let zero_copy = zero_copy.to_vec();
+ if !zero_copy.is_empty() {
+ println!("Hello from plugin. data: {}", data_str);
+ }
+ for (idx, buf) in zero_copy.iter().enumerate() {
let buf_str = std::str::from_utf8(&buf[..]).unwrap();
- println!(
- "Hello from plugin. data: {} | zero_copy: {}",
- data_str, buf_str
- );
+ println!("zero_copy[{}]: {}", idx, buf_str);
}
let result = b"test";
let result_box: Buf = Box::new(*result);
@@ -31,16 +32,17 @@ fn op_test_sync(
fn op_test_async(
_interface: &mut dyn Interface,
data: &[u8],
- zero_copy: Option<ZeroCopyBuf>,
+ zero_copy: &mut [ZeroCopyBuf],
) -> Op {
- let data_str = std::str::from_utf8(&data[..]).unwrap().to_string();
+ let zero_copy = zero_copy.to_vec();
+ if !zero_copy.is_empty() {
+ let data_str = std::str::from_utf8(&data[..]).unwrap().to_string();
+ println!("Hello from plugin. data: {}", data_str);
+ }
let fut = async move {
- if let Some(buf) = zero_copy {
+ for (idx, buf) in zero_copy.iter().enumerate() {
let buf_str = std::str::from_utf8(&buf[..]).unwrap();
- println!(
- "Hello from plugin. data: {} | zero_copy: {}",
- data_str, buf_str
- );
+ println!("zero_copy[{}]: {}", idx, buf_str);
}
let (tx, rx) = futures::channel::oneshot::channel::<Result<(), ()>>();
std::thread::spawn(move || {
diff --git a/test_plugin/tests/integration_tests.rs b/test_plugin/tests/integration_tests.rs
index 17002fc01..8716048b1 100644
--- a/test_plugin/tests/integration_tests.rs
+++ b/test_plugin/tests/integration_tests.rs
@@ -57,7 +57,7 @@ fn basic() {
println!("stderr {}", stderr);
}
assert!(output.status.success());
- let expected = "Hello from plugin. data: test | zero_copy: test\nPlugin Sync Response: test\nHello from plugin. data: test | zero_copy: test\nPlugin Async Response: test\n";
+ let expected = "Hello from plugin. data: test\nzero_copy[0]: test\nzero_copy[1]: 123\nzero_copy[2]: cba\nPlugin Sync Response: test\nHello from plugin. data: test\nzero_copy[0]: test\nzero_copy[1]: 123\nPlugin Async Response: test\n";
assert_eq!(stdout, expected);
assert_eq!(stderr, "");
}
diff --git a/test_plugin/tests/test.js b/test_plugin/tests/test.js
index 8d6146902..fbe58aeb8 100644
--- a/test_plugin/tests/test.js
+++ b/test_plugin/tests/test.js
@@ -33,7 +33,9 @@ function runTestSync() {
const response = Deno.core.dispatch(
testSync,
new Uint8Array([116, 101, 115, 116]),
- new Uint8Array([116, 101, 115, 116])
+ new Uint8Array([116, 101, 115, 116]),
+ new Uint8Array([49, 50, 51]),
+ new Uint8Array([99, 98, 97])
);
console.log(`Plugin Sync Response: ${textDecoder.decode(response)}`);
@@ -47,7 +49,8 @@ function runTestAsync() {
const response = Deno.core.dispatch(
testAsync,
new Uint8Array([116, 101, 115, 116]),
- new Uint8Array([116, 101, 115, 116])
+ new Uint8Array([116, 101, 115, 116]),
+ new Uint8Array([49, 50, 51])
);
if (response != null || response != undefined) {
@@ -80,9 +83,11 @@ function runTestPluginClose() {
const preStr = JSON.stringify(resourcesPre, null, 2);
const postStr = JSON.stringify(resourcesPost, null, 2);
if (preStr !== postStr) {
- throw new Error(`Difference in open resources before openPlugin and after Plugin.close():
+ throw new Error(
+ `Difference in open resources before openPlugin and after Plugin.close():
Before: ${preStr}
-After: ${postStr}`);
+After: ${postStr}`
+ );
}
}