@@ -30,3 +30,39 @@ fn slice() {
30
30
"# )
31
31
. test ( )
32
32
}
33
+
34
+ #[ test]
35
+ fn substr ( ) {
36
+ project ( )
37
+ . file ( "src/lib.rs" , r#"
38
+ #![feature(proc_macro, wasm_custom_section)]
39
+
40
+ extern crate wasm_bindgen;
41
+ use wasm_bindgen::prelude::*;
42
+ use wasm_bindgen::js;
43
+
44
+ #[wasm_bindgen]
45
+ pub fn create_substr(this: &js::JsString, start: i32, length: i32) -> js::JsString {
46
+ this.substr(start, length)
47
+ }
48
+ "# )
49
+ . file ( "test.ts" , r#"
50
+ import * as assert from "assert";
51
+ import * as wasm from "./out";
52
+
53
+ export function test() {
54
+ let aString = "Mozilla";
55
+
56
+ assert.equal(wasm.create_substr(aString, 0, 1), "M");
57
+ assert.equal(wasm.create_substr(aString, 1, 0), "");
58
+ assert.equal(wasm.create_substr(aString, -1, 1), "a");
59
+ assert.equal(wasm.create_substr(aString, 1, -1), "");
60
+ // TODO: Uncomment and test these assertions, once we have support for optional parameters
61
+ // assert.equal(wasm.create_substr(aString, -3), "lla");
62
+ // assert.equal(wasm.create_substr(aString, 1), "ozilla");
63
+ assert.equal(wasm.create_substr(aString, -20, 2), "Mo");
64
+ assert.equal(wasm.create_substr(aString, 20, 2), "");
65
+ }
66
+ "# )
67
+ . test ( )
68
+ }
0 commit comments