@@ -31,35 +31,6 @@ fn char_at() {
31
31
. test ( )
32
32
}
33
33
34
- #[ test]
35
- fn slice ( ) {
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_slice(this: &js::JsString, start: u32, end: u32) -> js::JsString {
46
- this.slice(start, end)
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 characters = "acxn18";
55
- let subset = wasm.create_slice(characters, 1, 3);
56
-
57
- assert.equal(subset, "cx");
58
- }
59
- "# )
60
- . test ( )
61
- }
62
-
63
34
#[ test]
64
35
fn starts_with ( ) {
65
36
project ( )
@@ -168,3 +139,68 @@ fn index_of() {
168
139
"# )
169
140
. test ( )
170
141
}
142
+
143
+ #[ test]
144
+ fn slice ( ) {
145
+ project ( )
146
+ . file ( "src/lib.rs" , r#"
147
+ #![feature(proc_macro, wasm_custom_section)]
148
+
149
+ extern crate wasm_bindgen;
150
+ use wasm_bindgen::prelude::*;
151
+ use wasm_bindgen::js;
152
+
153
+ #[wasm_bindgen]
154
+ pub fn create_slice(this: &js::JsString, start: u32, end: u32) -> js::JsString {
155
+ this.slice(start, end)
156
+ }
157
+ "# )
158
+ . file ( "test.ts" , r#"
159
+ import * as assert from "assert";
160
+ import * as wasm from "./out";
161
+
162
+ export function test() {
163
+ let characters = "acxn18";
164
+ let subset = wasm.create_slice(characters, 1, 3);
165
+
166
+ assert.equal(subset, "cx");
167
+ }
168
+ "# )
169
+ . test ( )
170
+ }
171
+
172
+ #[ test]
173
+ fn substr ( ) {
174
+ project ( )
175
+ . file ( "src/lib.rs" , r#"
176
+ #![feature(proc_macro, wasm_custom_section)]
177
+
178
+ extern crate wasm_bindgen;
179
+ use wasm_bindgen::prelude::*;
180
+ use wasm_bindgen::js;
181
+
182
+ #[wasm_bindgen]
183
+ pub fn create_substr(this: &js::JsString, start: i32, length: i32) -> js::JsString {
184
+ this.substr(start, length)
185
+ }
186
+ "# )
187
+ . file ( "test.ts" , r#"
188
+ import * as assert from "assert";
189
+ import * as wasm from "./out";
190
+
191
+ export function test() {
192
+ let aString = "Mozilla";
193
+
194
+ assert.equal(wasm.create_substr(aString, 0, 1), "M");
195
+ assert.equal(wasm.create_substr(aString, 1, 0), "");
196
+ assert.equal(wasm.create_substr(aString, -1, 1), "a");
197
+ assert.equal(wasm.create_substr(aString, 1, -1), "");
198
+ // TODO: Uncomment and test these assertions, once we have support for optional parameters
199
+ // assert.equal(wasm.create_substr(aString, -3), "lla");
200
+ // assert.equal(wasm.create_substr(aString, 1), "ozilla");
201
+ assert.equal(wasm.create_substr(aString, -20, 2), "Mo");
202
+ assert.equal(wasm.create_substr(aString, 20, 2), "");
203
+ }
204
+ "# )
205
+ . test ( )
206
+ }
0 commit comments