@@ -261,6 +261,45 @@ fn index_of() {
261
261
. test ( )
262
262
}
263
263
264
+ #[ test]
265
+ fn last_index_of ( ) {
266
+ project ( )
267
+ . file ( "src/lib.rs" , r#"
268
+ #![feature(use_extern_macros, wasm_custom_section)]
269
+
270
+ extern crate wasm_bindgen;
271
+ use wasm_bindgen::prelude::*;
272
+ use wasm_bindgen::js;
273
+
274
+ #[wasm_bindgen]
275
+ pub fn string_last_index_of(this: &js::JsString, search_value: &js::JsString, from_index: i32) -> i32 {
276
+ this.last_index_of(search_value, from_index)
277
+ }
278
+ "# )
279
+ . file ( "test.js" , r#"
280
+ import * as assert from "assert";
281
+ import * as wasm from "./out";
282
+
283
+ export function test() {
284
+ let str = "canal";
285
+ let len = str.length;
286
+
287
+ // TODO: remove second parameter once we have optional parameters
288
+ assert.equal(wasm.string_last_index_of(str, 'a', len), 3);
289
+ assert.equal(wasm.string_last_index_of(str, 'a', 2), 1);
290
+ assert.equal(wasm.string_last_index_of(str, 'a', 0), -1);
291
+ // TODO: remove second parameter once we have optional parameters
292
+ assert.equal(wasm.string_last_index_of(str, 'x', len), -1);
293
+ assert.equal(wasm.string_last_index_of(str, 'c', -5), 0);
294
+ assert.equal(wasm.string_last_index_of(str, 'c', 0), 0);
295
+ // TODO: remove second parameter once we have optional parameters
296
+ assert.equal(wasm.string_last_index_of(str, '', len), 5);
297
+ assert.equal(wasm.string_last_index_of(str, '', 2), 2);
298
+ }
299
+ "# )
300
+ . test ( )
301
+ }
302
+
264
303
#[ test]
265
304
fn slice ( ) {
266
305
project ( )
0 commit comments