Support String.prototype.concat

This commit is contained in:
Satoshi Amemiya
2018-06-27 00:48:09 +09:00
parent 947dfbeae0
commit 3d72a90481
2 changed files with 39 additions and 0 deletions

View File

@@ -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 starts_with() {
project()