mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-14 05:21:24 +00:00
Add bindings for String.prototype.split
This commit is contained in:
@ -321,6 +321,39 @@ fn slice() {
|
||||
assert_eq!(characters.slice(1, 3), "cx");
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn split() {
|
||||
let js = JsString::from("Oh brave new world");
|
||||
let result = js.split(" ");
|
||||
|
||||
let mut v = Vec::with_capacity(result.length() as usize);
|
||||
result.for_each(&mut |x, _, _| v.push(x));
|
||||
|
||||
assert_eq!(v[0], "Oh");
|
||||
assert_eq!(v[1], "brave");
|
||||
assert_eq!(v[2], "new");
|
||||
assert_eq!(v[3], "world");
|
||||
|
||||
let js = JsString::from("Oct,Nov,Dec");
|
||||
let result = js.split(",");
|
||||
|
||||
let mut v = Vec::with_capacity(result.length() as usize);
|
||||
result.for_each(&mut |x, _, _| v.push(x));
|
||||
|
||||
assert_eq!(v[0], "Oct");
|
||||
assert_eq!(v[1], "Nov");
|
||||
assert_eq!(v[2], "Dec");
|
||||
|
||||
let result = js.split_limit(",", 2);
|
||||
|
||||
let mut v = Vec::with_capacity(result.length() as usize);
|
||||
result.for_each(&mut |x, _, _| v.push(x));
|
||||
|
||||
assert_eq!(result.length(), 2);
|
||||
assert_eq!(v[0], "Oct");
|
||||
assert_eq!(v[1], "Nov");
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn starts_with() {
|
||||
let js = JsString::from("To be, or not to be, that is the question.");
|
||||
|
Reference in New Issue
Block a user