Merge pull request #361 from brisad/string-lower-and-upper-case

Bindings for string lower and upper case
This commit is contained in:
Sendil Kumar N 2018-07-02 09:26:47 +02:00 committed by GitHub
commit 10ffe8b3be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 67 additions and 0 deletions

View File

@ -1074,12 +1074,27 @@ 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
#[wasm_bindgen(method, js_class = "String", js_name = toString)]
pub fn to_string(this: &JsString) -> JsString;
/// The toUpperCase() method returns the calling string value
/// converted to uppercase (the value will be converted to a
/// string if it isn't one).
///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase
#[wasm_bindgen(method, js_class = "String", js_name = toUpperCase)]
pub fn to_upper_case(this: &JsString) -> JsString;
/// The trim() method removes whitespace from both ends of a string.
/// Whitespace in this context is all the whitespace characters
/// (space, tab, no-break space, etc.) and all the line terminator characters (LF, CR, etc.).

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()
@ -429,6 +455,32 @@ fn to_string() {
.test()
}
#[test]
fn to_upper_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_upper_case(this: &js::JsString) -> js::JsString {
this.to_upper_case()
}
"#)
.file("test.ts", r#"
import * as assert from "assert";
import * as wasm from "./out";
export function test() {
assert.equal(wasm.string_to_upper_case("Mozilla"), "MOZILLA");
}
"#)
.test()
}
#[test]
fn trim() {
project()