forked from boa-dev/boa
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.rs
More file actions
94 lines (87 loc) · 3.03 KB
/
tests.rs
File metadata and controls
94 lines (87 loc) · 3.03 KB
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
use crate::{JsNativeErrorKind, TestAction, run_test_actions};
#[test]
fn weakset_add_and_has() {
run_test_actions([
TestAction::run("var ws = new WeakSet(); var obj = {}; ws.add(obj);"),
TestAction::assert("ws.has(obj)"),
]);
}
#[test]
fn weakset_add_chaining() {
run_test_actions([
TestAction::run("var ws = new WeakSet(); var obj = {};"),
TestAction::assert("ws.add(obj) === ws"),
]);
}
#[test]
fn weakset_delete_behavior() {
run_test_actions([
TestAction::run("var ws = new WeakSet(); var obj = {}; ws.add(obj);"),
TestAction::assert("ws.delete(obj) === true"),
TestAction::assert("ws.delete(obj) === false"),
TestAction::assert("ws.has(obj) === false"),
]);
}
#[test]
fn weakset_add_primitive_rejection() {
run_test_actions([
TestAction::run("var ws = new WeakSet();"),
TestAction::assert_native_error(
"ws.add(1);",
JsNativeErrorKind::Type,
"WeakSet.add: expected target argument of type `object`, got target of type `number`",
),
TestAction::assert_native_error(
"ws.add('x');",
JsNativeErrorKind::Type,
"WeakSet.add: expected target argument of type `object`, got target of type `string`",
),
TestAction::assert_native_error(
"ws.add(true);",
JsNativeErrorKind::Type,
"WeakSet.add: expected target argument of type `object`, got target of type `boolean`",
),
TestAction::assert_native_error(
"ws.add(null);",
JsNativeErrorKind::Type,
"WeakSet.add: expected target argument of type `object`, got target of type `object`",
),
TestAction::assert_native_error(
"ws.add(undefined);",
JsNativeErrorKind::Type,
"WeakSet.add: expected target argument of type `object`, got target of type `undefined`",
),
TestAction::assert_native_error(
"ws.add(Symbol('id'));",
JsNativeErrorKind::Type,
"WeakSet.add: expected target argument of type `object`, got target of type `symbol`",
),
]);
}
#[test]
fn weakset_has_primitive_returns_false() {
run_test_actions([
TestAction::run("var ws = new WeakSet();"),
TestAction::assert("ws.has(1) === false"),
TestAction::assert("ws.has('x') === false"),
TestAction::assert("ws.has(null) === false"),
]);
}
#[test]
fn weakset_delete_primitive_returns_false() {
run_test_actions([
TestAction::run("var ws = new WeakSet();"),
TestAction::assert("ws.delete(1) === false"),
TestAction::assert("ws.delete('x') === false"),
TestAction::assert("ws.delete(null) === false"),
]);
}
#[test]
fn weakset_add_duplicate() {
run_test_actions([
TestAction::run("var ws = new WeakSet(); var obj = {}; ws.add(obj);"),
TestAction::assert("ws.has(obj) === true"),
TestAction::run("ws.add(obj);"),
TestAction::assert("ws.has(obj) === true"),
]);
}