Skip to content

Commit 367a56e

Browse files
author
Samuel Warfield
committed
Test are fully implemented
1 parent 06d0704 commit 367a56e

File tree

2 files changed

+43
-9
lines changed

2 files changed

+43
-9
lines changed

crates/js-sys/tests/wasm/Function.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ exports.get_value_to_bind_to = function() {
66
return { x: 2 };
77
};
88
exports.list = function() {
9-
return Array.prototype.slice.call(arguments);
9+
return function() {return Array.prototype.slice.call(arguments);}
1010
};
1111
exports.add_arguments = function() {
1212
return function(arg1, arg2) {return arg1 + arg2}
@@ -16,4 +16,4 @@ exports.call_function = function(f) {
1616
};
1717
exports.call_function_arg = function(f, arg1) {
1818
return f(arg1);
19-
};
19+
};

crates/js-sys/tests/wasm/Function.rs

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ extern "C" {
3636
fn get_value_to_bind_to() -> JsValue;
3737
fn list() -> Function;
3838
fn add_arguments() -> Function;
39-
fn call_function(f: Function) -> JsValue;
39+
fn call_function(f: &Function) -> JsValue;
4040
fn call_function_arg(f: &Function, arg0: JsValue) -> JsValue;
4141

4242
}
@@ -45,22 +45,24 @@ extern "C" {
4545
fn bind() {
4646
let f = get_function_to_bind();
4747
let new_f = f.bind(&get_value_to_bind_to());
48-
assert_eq!(call_function(f), 1);
49-
assert_eq!(call_function(new_f), 2);
48+
assert_eq!(call_function(&f), 1);
49+
assert_eq!(call_function(&new_f), 2);
5050
}
5151

5252
#[wasm_bindgen_test]
5353
fn bind0() {
5454
let f = get_function_to_bind();
5555
let new_f = f.bind0(&get_value_to_bind_to());
56-
assert_eq!(call_function(f), 1);
57-
assert_eq!(call_function(new_f), 2);
56+
assert_eq!(call_function(&f), 1);
57+
assert_eq!(call_function(&new_f), 2);
5858
}
5959

6060
#[wasm_bindgen_test]
6161
fn bind1() {
62-
//let a_list = list();
63-
//let prepended_list = a_list.bind1(&JsValue::NULL, &JsValue::from(2));
62+
let a_list = list();
63+
let prepended_list = a_list.bind1(&JsValue::NULL, &JsValue::from(2));
64+
65+
assert_eq!(Array::from(&call_function(&prepended_list)).pop(), 2);
6466

6567
let adder = add_arguments();
6668
let add_42 = adder.bind1(&JsValue::NULL, &JsValue::from(42));
@@ -69,6 +71,38 @@ fn bind1() {
6971
assert_eq!(call_function_arg(&add_42, JsValue::from(378)), 420);
7072
}
7173

74+
#[wasm_bindgen_test]
75+
fn bind2() {
76+
let a_list = list();
77+
let prepended_list = a_list.bind2(&JsValue::NULL, &JsValue::from(2), &JsValue::from(3));
78+
79+
let arr = Array::from(&call_function(&prepended_list));
80+
81+
assert_eq!(arr.pop(), 3);
82+
assert_eq!(arr.pop(), 2);
83+
84+
let adder = add_arguments();
85+
let always_69 = adder.bind2(&JsValue::NULL, &JsValue::from(66), &JsValue::from(3));
86+
87+
assert_eq!(call_function(&always_69), 69);
88+
}
89+
90+
#[wasm_bindgen_test]
91+
fn bind3() {
92+
let a_list = list();
93+
let prepended_list = a_list.bind3(&JsValue::NULL, &JsValue::from(2), &JsValue::from(3), &JsValue::from(4));
94+
95+
let arr = Array::from(&call_function(&prepended_list));
96+
97+
assert_eq!(arr.pop(), 4);
98+
assert_eq!(arr.pop(), 3);
99+
assert_eq!(arr.pop(), 2);
100+
101+
let adder = add_arguments();
102+
let always_69 = adder.bind2(&JsValue::NULL, &JsValue::from(66), &JsValue::from(3));
103+
104+
assert_eq!(call_function(&always_69), 69);
105+
}
72106

73107
#[wasm_bindgen_test]
74108
fn length() {

0 commit comments

Comments
 (0)