1 use js_sys::*;
2 use wasm_bindgen::prelude::*;
3 use wasm_bindgen_futures::JsFuture;
4 use wasm_bindgen_test::*;
5
6 #[wasm_bindgen(module = "tests/wasm/Symbol.js")]
7 extern "C" {
test_has_instance(sym: &Symbol)8 fn test_has_instance(sym: &Symbol);
test_is_concat_spreadable(sym: &Symbol)9 fn test_is_concat_spreadable(sym: &Symbol);
test_iterator(sym: &Symbol)10 fn test_iterator(sym: &Symbol);
test_async_iterator(sym: &Symbol) -> Promise11 fn test_async_iterator(sym: &Symbol) -> Promise;
test_match(sym: &Symbol)12 fn test_match(sym: &Symbol);
test_replace(sym: &Symbol)13 fn test_replace(sym: &Symbol);
test_search(sym: &Symbol)14 fn test_search(sym: &Symbol);
test_species(sym: &Symbol)15 fn test_species(sym: &Symbol);
test_split(sym: &Symbol)16 fn test_split(sym: &Symbol);
test_to_primitive(sym: &Symbol)17 fn test_to_primitive(sym: &Symbol);
test_to_string_tag(sym: &Symbol)18 fn test_to_string_tag(sym: &Symbol);
19 }
20
21 #[wasm_bindgen]
22 extern "C" {
23 #[wasm_bindgen(js_name = Symbol)]
gensym(val: JsValue) -> Symbol24 fn gensym(val: JsValue) -> Symbol;
25 }
26
27 #[wasm_bindgen_test]
has_instance()28 fn has_instance() {
29 test_has_instance(&Symbol::has_instance());
30 }
31
32 #[wasm_bindgen_test]
is_concat_spreadable()33 fn is_concat_spreadable() {
34 test_is_concat_spreadable(&Symbol::is_concat_spreadable());
35 }
36
37 #[wasm_bindgen_test]
iterator()38 fn iterator() {
39 test_iterator(&Symbol::iterator());
40 }
41
42 #[wasm_bindgen_test]
async_iterator()43 async fn async_iterator() {
44 JsFuture::from(test_async_iterator(&Symbol::async_iterator()))
45 .await
46 .unwrap_throw();
47 }
48
49 #[wasm_bindgen_test]
match_()50 fn match_() {
51 test_match(&Symbol::match_());
52 }
53
54 #[wasm_bindgen_test]
replace()55 fn replace() {
56 test_replace(&Symbol::replace());
57 }
58
59 #[wasm_bindgen_test]
search()60 fn search() {
61 test_search(&Symbol::search());
62 }
63
64 #[wasm_bindgen_test]
species()65 fn species() {
66 test_species(&Symbol::species());
67 }
68
69 #[wasm_bindgen_test]
split()70 fn split() {
71 test_split(&Symbol::split());
72 }
73
74 #[wasm_bindgen_test]
to_primitive()75 fn to_primitive() {
76 test_to_primitive(&Symbol::to_primitive());
77 }
78
79 #[wasm_bindgen_test]
to_string_tag()80 fn to_string_tag() {
81 test_to_string_tag(&Symbol::to_string_tag());
82 }
83
84 #[wasm_bindgen_test]
for_()85 fn for_() {
86 let foo = JsValue::from(Symbol::for_("foo"));
87 let bar = JsValue::from(Symbol::for_("bar"));
88 assert_eq!(foo, foo);
89 assert_eq!(bar, bar);
90 assert_ne!(foo, bar);
91 assert_ne!(bar, foo);
92
93 assert_eq!(Symbol::for_("mario").to_string(), "Symbol(mario)");
94 }
95
96 #[wasm_bindgen_test]
key_for()97 fn key_for() {
98 let sym = Symbol::for_("foo");
99 assert_eq!(Symbol::key_for(&sym), "foo");
100 assert!(Symbol::key_for(&Symbol::iterator()).is_undefined());
101 assert!(Symbol::key_for(&Symbol::async_iterator()).is_undefined());
102 assert!(Symbol::key_for(&gensym(JsValue::undefined())).is_undefined());
103 }
104
105 #[wasm_bindgen_test]
to_string()106 fn to_string() {
107 assert_eq!(Symbol::iterator().to_string(), "Symbol(Symbol.iterator)");
108 assert_eq!(
109 Symbol::async_iterator().to_string(),
110 "Symbol(Symbol.asyncIterator)"
111 );
112 assert_eq!(Symbol::for_("foo").to_string(), "Symbol(foo)");
113 assert_eq!(gensym("desc".into()).to_string(), "Symbol(desc)");
114 }
115
116 #[wasm_bindgen_test]
unscopables()117 fn unscopables() {
118 assert_eq!(
119 Symbol::unscopables().to_string(),
120 "Symbol(Symbol.unscopables)"
121 );
122 }
123
124 #[wasm_bindgen_test]
value_of()125 fn value_of() {
126 let a = Symbol::for_("foo");
127 assert_eq!(JsValue::from(a.value_of()), JsValue::from(a));
128 let a = gensym(JsValue::undefined());
129 assert_eq!(JsValue::from(a.value_of()), JsValue::from(a));
130 }
131