mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-04-15 00:46:04 +00:00
Test are fully implemented
This commit is contained in:
parent
06d0704cf8
commit
367a56eb25
@ -6,7 +6,7 @@ exports.get_value_to_bind_to = function() {
|
|||||||
return { x: 2 };
|
return { x: 2 };
|
||||||
};
|
};
|
||||||
exports.list = function() {
|
exports.list = function() {
|
||||||
return Array.prototype.slice.call(arguments);
|
return function() {return Array.prototype.slice.call(arguments);}
|
||||||
};
|
};
|
||||||
exports.add_arguments = function() {
|
exports.add_arguments = function() {
|
||||||
return function(arg1, arg2) {return arg1 + arg2}
|
return function(arg1, arg2) {return arg1 + arg2}
|
||||||
|
@ -36,7 +36,7 @@ extern "C" {
|
|||||||
fn get_value_to_bind_to() -> JsValue;
|
fn get_value_to_bind_to() -> JsValue;
|
||||||
fn list() -> Function;
|
fn list() -> Function;
|
||||||
fn add_arguments() -> Function;
|
fn add_arguments() -> Function;
|
||||||
fn call_function(f: Function) -> JsValue;
|
fn call_function(f: &Function) -> JsValue;
|
||||||
fn call_function_arg(f: &Function, arg0: JsValue) -> JsValue;
|
fn call_function_arg(f: &Function, arg0: JsValue) -> JsValue;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -45,22 +45,24 @@ extern "C" {
|
|||||||
fn bind() {
|
fn bind() {
|
||||||
let f = get_function_to_bind();
|
let f = get_function_to_bind();
|
||||||
let new_f = f.bind(&get_value_to_bind_to());
|
let new_f = f.bind(&get_value_to_bind_to());
|
||||||
assert_eq!(call_function(f), 1);
|
assert_eq!(call_function(&f), 1);
|
||||||
assert_eq!(call_function(new_f), 2);
|
assert_eq!(call_function(&new_f), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen_test]
|
#[wasm_bindgen_test]
|
||||||
fn bind0() {
|
fn bind0() {
|
||||||
let f = get_function_to_bind();
|
let f = get_function_to_bind();
|
||||||
let new_f = f.bind0(&get_value_to_bind_to());
|
let new_f = f.bind0(&get_value_to_bind_to());
|
||||||
assert_eq!(call_function(f), 1);
|
assert_eq!(call_function(&f), 1);
|
||||||
assert_eq!(call_function(new_f), 2);
|
assert_eq!(call_function(&new_f), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen_test]
|
#[wasm_bindgen_test]
|
||||||
fn bind1() {
|
fn bind1() {
|
||||||
//let a_list = list();
|
let a_list = list();
|
||||||
//let prepended_list = a_list.bind1(&JsValue::NULL, &JsValue::from(2));
|
let prepended_list = a_list.bind1(&JsValue::NULL, &JsValue::from(2));
|
||||||
|
|
||||||
|
assert_eq!(Array::from(&call_function(&prepended_list)).pop(), 2);
|
||||||
|
|
||||||
let adder = add_arguments();
|
let adder = add_arguments();
|
||||||
let add_42 = adder.bind1(&JsValue::NULL, &JsValue::from(42));
|
let add_42 = adder.bind1(&JsValue::NULL, &JsValue::from(42));
|
||||||
@ -69,6 +71,38 @@ fn bind1() {
|
|||||||
assert_eq!(call_function_arg(&add_42, JsValue::from(378)), 420);
|
assert_eq!(call_function_arg(&add_42, JsValue::from(378)), 420);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen_test]
|
||||||
|
fn bind2() {
|
||||||
|
let a_list = list();
|
||||||
|
let prepended_list = a_list.bind2(&JsValue::NULL, &JsValue::from(2), &JsValue::from(3));
|
||||||
|
|
||||||
|
let arr = Array::from(&call_function(&prepended_list));
|
||||||
|
|
||||||
|
assert_eq!(arr.pop(), 3);
|
||||||
|
assert_eq!(arr.pop(), 2);
|
||||||
|
|
||||||
|
let adder = add_arguments();
|
||||||
|
let always_69 = adder.bind2(&JsValue::NULL, &JsValue::from(66), &JsValue::from(3));
|
||||||
|
|
||||||
|
assert_eq!(call_function(&always_69), 69);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen_test]
|
||||||
|
fn bind3() {
|
||||||
|
let a_list = list();
|
||||||
|
let prepended_list = a_list.bind3(&JsValue::NULL, &JsValue::from(2), &JsValue::from(3), &JsValue::from(4));
|
||||||
|
|
||||||
|
let arr = Array::from(&call_function(&prepended_list));
|
||||||
|
|
||||||
|
assert_eq!(arr.pop(), 4);
|
||||||
|
assert_eq!(arr.pop(), 3);
|
||||||
|
assert_eq!(arr.pop(), 2);
|
||||||
|
|
||||||
|
let adder = add_arguments();
|
||||||
|
let always_69 = adder.bind2(&JsValue::NULL, &JsValue::from(66), &JsValue::from(3));
|
||||||
|
|
||||||
|
assert_eq!(call_function(&always_69), 69);
|
||||||
|
}
|
||||||
|
|
||||||
#[wasm_bindgen_test]
|
#[wasm_bindgen_test]
|
||||||
fn length() {
|
fn length() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user