Add binding for String.prototype.search

This commit is contained in:
Danielle Pham
2018-08-19 14:52:10 -04:00
parent 44877880bb
commit 8698084a43
2 changed files with 22 additions and 0 deletions

View File

@ -300,6 +300,21 @@ fn replace() {
assert_eq!(result, "border-top");
}
#[wasm_bindgen_test]
fn search() {
let js = JsString::from("The quick brown fox jumped over the lazy dog. If the dog reacted, was it really lazy?");
let re = RegExp::new("[^\\w\\s]", "g");
assert_eq!(js.search(&re), 44);
let js = JsString::from("hey JudE");
let re1 = RegExp::new("[A-Z]", "g");
let re2 = RegExp::new("[.]", "g");
assert_eq!(js.search(&re1), 4);
assert_eq!(js.search(&re2), -1);
}
#[wasm_bindgen_test]
fn slice() {
let characters = JsString::from("acxn18");