summaryrefslogtreecommitdiffstats
path: root/vendor/js-sys/tests/wasm/Symbol.rs
blob: 0f1e3d0f63d1f71447587cfe5a62f1fc88f1ca5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
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));
}