summaryrefslogtreecommitdiffstats
path: root/vendor/js-sys/tests/wasm/Symbol.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/Symbol.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/Symbol.rs')
-rw-r--r--vendor/js-sys/tests/wasm/Symbol.rs130
1 files changed, 130 insertions, 0 deletions
diff --git a/vendor/js-sys/tests/wasm/Symbol.rs b/vendor/js-sys/tests/wasm/Symbol.rs
new file mode 100644
index 000000000..0f1e3d0f6
--- /dev/null
+++ b/vendor/js-sys/tests/wasm/Symbol.rs
@@ -0,0 +1,130 @@
+use js_sys::*;
+use wasm_bindgen::prelude::*;
+use wasm_bindgen_futures::JsFuture;
+use wasm_bindgen_test::*;
+
+#[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);
+ fn test_species(sym: &Symbol);
+ fn test_split(sym: &Symbol);
+ fn test_to_primitive(sym: &Symbol);
+ fn test_to_string_tag(sym: &Symbol);
+}
+
+#[wasm_bindgen]
+extern "C" {
+ #[wasm_bindgen(js_name = Symbol)]
+ fn gensym(val: JsValue) -> Symbol;
+}
+
+#[wasm_bindgen_test]
+fn has_instance() {
+ test_has_instance(&Symbol::has_instance());
+}
+
+#[wasm_bindgen_test]
+fn is_concat_spreadable() {
+ test_is_concat_spreadable(&Symbol::is_concat_spreadable());
+}
+
+#[wasm_bindgen_test]
+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_());
+}
+
+#[wasm_bindgen_test]
+fn replace() {
+ test_replace(&Symbol::replace());
+}
+
+#[wasm_bindgen_test]
+fn search() {
+ test_search(&Symbol::search());
+}
+
+#[wasm_bindgen_test]
+fn species() {
+ test_species(&Symbol::species());
+}
+
+#[wasm_bindgen_test]
+fn split() {
+ test_split(&Symbol::split());
+}
+
+#[wasm_bindgen_test]
+fn to_primitive() {
+ test_to_primitive(&Symbol::to_primitive());
+}
+
+#[wasm_bindgen_test]
+fn to_string_tag() {
+ test_to_string_tag(&Symbol::to_string_tag());
+}
+
+#[wasm_bindgen_test]
+fn for_() {
+ let foo = JsValue::from(Symbol::for_("foo"));
+ let bar = JsValue::from(Symbol::for_("bar"));
+ assert_eq!(foo, foo);
+ assert_eq!(bar, bar);
+ assert_ne!(foo, bar);
+ assert_ne!(bar, foo);
+
+ assert_eq!(Symbol::for_("mario").to_string(), "Symbol(mario)");
+}
+
+#[wasm_bindgen_test]
+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)");
+}
+
+#[wasm_bindgen_test]
+fn unscopables() {
+ assert_eq!(
+ Symbol::unscopables().to_string(),
+ "Symbol(Symbol.unscopables)"
+ );
+}
+
+#[wasm_bindgen_test]
+fn value_of() {
+ let a = Symbol::for_("foo");
+ assert_eq!(JsValue::from(a.value_of()), JsValue::from(a));
+ let a = gensym(JsValue::undefined());
+ assert_eq!(JsValue::from(a.value_of()), JsValue::from(a));
+}