mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-03-16 18:20:51 +00:00
Merge pull request #325 from rail44/string-concat
Support String.prototype.concat
This commit is contained in:
commit
09969db5cf
18
src/js.rs
18
src/js.rs
@ -583,13 +583,11 @@ extern {
|
||||
#[wasm_bindgen(method, js_class = "String", js_name = charCodeAt)]
|
||||
pub fn char_code_at(this: &JsString, index: u32) -> Number;
|
||||
|
||||
/// The indexOf() method returns the index within the calling String object of
|
||||
/// the first occurrence of the specified value, starting the search at fromIndex.
|
||||
/// Returns -1 if the value is not found.
|
||||
/// 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/indexOf
|
||||
#[wasm_bindgen(method, js_class = "String", js_name = indexOf)]
|
||||
pub fn index_of(this: &JsString, search_value: &JsString, from_index: i32) -> i32;
|
||||
/// 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 includes() method determines whether one string may be found within another string, returning true or false as appropriate.
|
||||
///
|
||||
@ -597,6 +595,14 @@ extern {
|
||||
#[wasm_bindgen(method, js_class = "String")]
|
||||
pub fn includes(this: &JsString, search_string: &JsString, position: i32) -> bool;
|
||||
|
||||
/// The indexOf() method returns the index within the calling String object of
|
||||
/// the first occurrence of the specified value, starting the search at fromIndex.
|
||||
/// Returns -1 if the value is not found.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf
|
||||
#[wasm_bindgen(method, js_class = "String", js_name = indexOf)]
|
||||
pub fn index_of(this: &JsString, search_value: &JsString, from_index: i32) -> i32;
|
||||
|
||||
/// The slice() method extracts a section of a string and returns it as a
|
||||
/// new string, without modifying the original string.
|
||||
///
|
||||
|
@ -31,6 +31,38 @@ fn char_at() {
|
||||
.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]
|
||||
fn char_code_at() {
|
||||
project()
|
||||
@ -59,7 +91,7 @@ fn char_code_at() {
|
||||
"#)
|
||||
.test()
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn starts_with() {
|
||||
project()
|
||||
|
Loading…
x
Reference in New Issue
Block a user