Add binding for String.prototype.toLowerCase

This commit is contained in:
Michael Hoffmann 2018-07-01 23:11:13 +02:00
parent bfffd58683
commit 58560f1408
2 changed files with 33 additions and 0 deletions

View File

@ -1065,6 +1065,13 @@ extern "C" {
#[wasm_bindgen(method, js_class = "String")]
pub fn substr(this: &JsString, start: i32, length: i32) -> JsString;
/// The toLowerCase() method returns the calling string value
/// converted to lower case.
///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLowerCase
#[wasm_bindgen(method, js_class = "String", js_name = toLowerCase)]
pub fn to_lower_case(this: &JsString) -> JsString;
/// The toString() method returns a string representing the specified object.
///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toString

View File

@ -396,6 +396,32 @@ fn substr() {
.test()
}
#[test]
fn to_lower_case() {
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_to_lower_case(this: &js::JsString) -> js::JsString {
this.to_lower_case()
}
"#)
.file("test.ts", r#"
import * as assert from "assert";
import * as wasm from "./out";
export function test() {
assert.equal(wasm.string_to_lower_case("Mozilla"), "mozilla");
}
"#)
.test()
}
#[test]
fn to_string() {
project()