mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-12 20:41:24 +00:00
Adding in support for async iterators (#1895)
* Adding in support for async iterators * Adding in some unit tests for asyncIterator * Fixing unit tests * Fixing UI tests
This commit is contained in:
@ -36,6 +36,41 @@ exports.test_iterator = function(sym) {
|
||||
assert.deepEqual([...iterable1], [1, 2, 3]);
|
||||
};
|
||||
|
||||
exports.test_async_iterator = async function(sym) {
|
||||
const iterable1 = new Object();
|
||||
|
||||
iterable1[sym] = function () {
|
||||
let done = false;
|
||||
|
||||
return {
|
||||
next() {
|
||||
if (done) {
|
||||
return Promise.resolve({
|
||||
done: true,
|
||||
value: 1
|
||||
});
|
||||
|
||||
} else {
|
||||
done = true;
|
||||
|
||||
return Promise.resolve({
|
||||
done: false,
|
||||
value: 0
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
const values = [];
|
||||
|
||||
for await (let value of iterable1) {
|
||||
values.push(value);
|
||||
}
|
||||
|
||||
assert.deepEqual(values, [0]);
|
||||
};
|
||||
|
||||
exports.test_match = function(sym) {
|
||||
const regexp1 = /foo/;
|
||||
assert.throws(() => '/foo/'.startsWith(regexp1));
|
||||
|
@ -1,12 +1,14 @@
|
||||
use js_sys::*;
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen_test::*;
|
||||
use wasm_bindgen_futures::JsFuture;
|
||||
|
||||
#[wasm_bindgen(module = "tests/wasm/Symbol.js")]
|
||||
extern "C" {
|
||||
fn test_has_instance(sym: &Symbol);
|
||||
fn test_is_concat_spreadable(sym: &Symbol);
|
||||
fn test_iterator(sym: &Symbol);
|
||||
fn test_async_iterator(sym: &Symbol) -> Promise;
|
||||
fn test_match(sym: &Symbol);
|
||||
fn test_replace(sym: &Symbol);
|
||||
fn test_search(sym: &Symbol);
|
||||
@ -37,6 +39,11 @@ fn iterator() {
|
||||
test_iterator(&Symbol::iterator());
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
async fn async_iterator() {
|
||||
JsFuture::from(test_async_iterator(&Symbol::async_iterator())).await.unwrap_throw();
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn match_() {
|
||||
test_match(&Symbol::match_());
|
||||
@ -89,12 +96,14 @@ fn key_for() {
|
||||
let sym = Symbol::for_("foo");
|
||||
assert_eq!(Symbol::key_for(&sym), "foo");
|
||||
assert!(Symbol::key_for(&Symbol::iterator()).is_undefined());
|
||||
assert!(Symbol::key_for(&Symbol::async_iterator()).is_undefined());
|
||||
assert!(Symbol::key_for(&gensym(JsValue::undefined())).is_undefined());
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn to_string() {
|
||||
assert_eq!(Symbol::iterator().to_string(), "Symbol(Symbol.iterator)");
|
||||
assert_eq!(Symbol::async_iterator().to_string(), "Symbol(Symbol.asyncIterator)");
|
||||
assert_eq!(Symbol::for_("foo").to_string(), "Symbol(foo)");
|
||||
assert_eq!(gensym("desc".into()).to_string(), "Symbol(desc)");
|
||||
}
|
||||
|
Reference in New Issue
Block a user