summaryrefslogtreecommitdiffstats
path: root/vendor/js-sys/tests/wasm/Iterator.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:41:35 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:41:35 +0000
commit7e5d7eea9c580ef4b41a765bde624af431942b96 (patch)
tree2c0d9ca12878fc4525650aa4e54d77a81a07cc09 /vendor/js-sys/tests/wasm/Iterator.rs
parentAdding debian version 1.70.0+dfsg1-9. (diff)
downloadrustc-7e5d7eea9c580ef4b41a765bde624af431942b96.tar.xz
rustc-7e5d7eea9c580ef4b41a765bde624af431942b96.zip
Merging upstream version 1.70.0+dfsg2.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/js-sys/tests/wasm/Iterator.rs')
-rw-r--r--vendor/js-sys/tests/wasm/Iterator.rs42
1 files changed, 42 insertions, 0 deletions
diff --git a/vendor/js-sys/tests/wasm/Iterator.rs b/vendor/js-sys/tests/wasm/Iterator.rs
new file mode 100644
index 000000000..f06c58b54
--- /dev/null
+++ b/vendor/js-sys/tests/wasm/Iterator.rs
@@ -0,0 +1,42 @@
+use js_sys::*;
+use wasm_bindgen::prelude::*;
+use wasm_bindgen_test::*;
+
+#[wasm_bindgen(module = "tests/wasm/Iterator.js")]
+extern "C" {
+ fn get_iterable() -> JsValue;
+
+ fn get_not_iterable() -> JsValue;
+
+ fn get_symbol_iterator_throws() -> JsValue;
+
+ fn get_symbol_iterator_not_function() -> JsValue;
+
+ fn get_symbol_iterator_returns_not_object() -> JsValue;
+
+ fn get_symbol_iterator_returns_object_without_next() -> JsValue;
+}
+
+#[wasm_bindgen_test]
+fn try_iter_handles_iteration_protocol() {
+ assert_eq!(
+ try_iter(&get_iterable())
+ .unwrap()
+ .unwrap()
+ .map(|x| x.unwrap().as_string().unwrap())
+ .collect::<Vec<_>>(),
+ vec!["one", "two", "three"]
+ );
+
+ assert!(try_iter(&get_not_iterable()).unwrap().is_none());
+ assert!(try_iter(&get_symbol_iterator_throws()).is_err());
+ assert!(try_iter(&get_symbol_iterator_not_function())
+ .unwrap()
+ .is_none());
+ assert!(try_iter(&get_symbol_iterator_returns_not_object())
+ .unwrap()
+ .is_none());
+ assert!(try_iter(&get_symbol_iterator_returns_object_without_next())
+ .unwrap()
+ .is_none());
+}