String - lastIndexOf (#490)

This commit is contained in:
data-pup
2018-07-17 13:12:36 -04:00
committed by Alex Crichton
parent 9d27b44a4a
commit 5f2f30dba1
2 changed files with 47 additions and 0 deletions

View File

@ -261,6 +261,45 @@ fn index_of() {
.test()
}
#[test]
fn last_index_of() {
project()
.file("src/lib.rs", r#"
#![feature(use_extern_macros, wasm_custom_section)]
extern crate wasm_bindgen;
use wasm_bindgen::prelude::*;
use wasm_bindgen::js;
#[wasm_bindgen]
pub fn string_last_index_of(this: &js::JsString, search_value: &js::JsString, from_index: i32) -> i32 {
this.last_index_of(search_value, from_index)
}
"#)
.file("test.js", r#"
import * as assert from "assert";
import * as wasm from "./out";
export function test() {
let str = "canal";
let len = str.length;
// TODO: remove second parameter once we have optional parameters
assert.equal(wasm.string_last_index_of(str, 'a', len), 3);
assert.equal(wasm.string_last_index_of(str, 'a', 2), 1);
assert.equal(wasm.string_last_index_of(str, 'a', 0), -1);
// TODO: remove second parameter once we have optional parameters
assert.equal(wasm.string_last_index_of(str, 'x', len), -1);
assert.equal(wasm.string_last_index_of(str, 'c', -5), 0);
assert.equal(wasm.string_last_index_of(str, 'c', 0), 0);
// TODO: remove second parameter once we have optional parameters
assert.equal(wasm.string_last_index_of(str, '', len), 5);
assert.equal(wasm.string_last_index_of(str, '', 2), 2);
}
"#)
.test()
}
#[test]
fn slice() {
project()