mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-12-26 11:34:22 +03:00
Support String.prototype.concat
This commit is contained in:
parent
947dfbeae0
commit
3d72a90481
@ -447,6 +447,13 @@ extern {
|
|||||||
#[wasm_bindgen(method, js_class = "String", js_name = charAt)]
|
#[wasm_bindgen(method, js_class = "String", js_name = charAt)]
|
||||||
pub fn char_at(this: &JsString, index: u32) -> JsString;
|
pub fn char_at(this: &JsString, index: u32) -> JsString;
|
||||||
|
|
||||||
|
|
||||||
|
/// The concat() method concatenates the string arguments to the calling string and returns a new string.
|
||||||
|
///
|
||||||
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/concat
|
||||||
|
#[wasm_bindgen(method, js_class = "String")]
|
||||||
|
pub fn concat(this: &JsString, string_2: &JsString) -> JsString;
|
||||||
|
|
||||||
/// The indexOf() method returns the index within the calling String object of
|
/// The indexOf() method returns the index within the calling String object of
|
||||||
/// the first occurrence of the specified value, starting the search at fromIndex.
|
/// the first occurrence of the specified value, starting the search at fromIndex.
|
||||||
/// Returns -1 if the value is not found.
|
/// Returns -1 if the value is not found.
|
||||||
|
@ -31,6 +31,38 @@ fn char_at() {
|
|||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn concat() {
|
||||||
|
project()
|
||||||
|
.file("src/lib.rs", r#"
|
||||||
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
|
extern crate wasm_bindgen;
|
||||||
|
use wasm_bindgen::prelude::*;
|
||||||
|
use wasm_bindgen::js;
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn string_concat(this: &js::JsString, string_2: &js::JsString) -> js::JsString {
|
||||||
|
this.concat(string_2)
|
||||||
|
}
|
||||||
|
"#)
|
||||||
|
.file("test.ts", r#"
|
||||||
|
import * as assert from "assert";
|
||||||
|
import * as wasm from "./out";
|
||||||
|
|
||||||
|
export function test() {
|
||||||
|
// TODO: Implement ability to receive multiple optional arguments
|
||||||
|
assert.equal(wasm.string_concat('Hello ', 'World'), 'Hello World');
|
||||||
|
assert.equal(wasm.string_concat('foo', {}), 'foo[object Object]');
|
||||||
|
assert.equal(wasm.string_concat('foo', []), 'foo');
|
||||||
|
assert.equal(wasm.string_concat('foo', null), 'foonull');
|
||||||
|
assert.equal(wasm.string_concat('foo', true), 'footrue');
|
||||||
|
assert.equal(wasm.string_concat('foo', 1234), 'foo1234');
|
||||||
|
}
|
||||||
|
"#)
|
||||||
|
.test()
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn starts_with() {
|
fn starts_with() {
|
||||||
project()
|
project()
|
||||||
|
Loading…
Reference in New Issue
Block a user