From bec1c95b5c4e00d5135d9838aefd24c2c433ba41 Mon Sep 17 00:00:00 2001 From: "T. Nagasawa" Date: Fri, 20 Jul 2018 23:03:29 +0900 Subject: [PATCH] bindings for to_locale_XXX_case (#523) --- crates/js-sys/src/lib.rs | 14 ++++++ crates/js-sys/tests/all/JsString.rs | 68 +++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) diff --git a/crates/js-sys/src/lib.rs b/crates/js-sys/src/lib.rs index da7ac2ae2..4dced3d16 100644 --- a/crates/js-sys/src/lib.rs +++ b/crates/js-sys/src/lib.rs @@ -2156,6 +2156,20 @@ extern "C" { #[wasm_bindgen(method, js_class = "String")] pub fn substr(this: &JsString, start: i32, length: i32) -> JsString; + /// The toLocaleLowerCase() method returns the calling string value converted to lower case, + /// according to any locale-specific case mappings. + /// + /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleLowerCase + #[wasm_bindgen(method, js_class = "String", js_name = toLocaleLowerCase)] + pub fn to_locale_lower_case(this: &JsString, local: Option) -> JsString; + + /// The toLocaleUpperCase() method returns the calling string value converted to upper case, + /// according to any locale-specific case mappings. + /// + /// https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/String/toLocaleUpperCase + #[wasm_bindgen(method, js_class = "String", js_name = toLocaleUpperCase)] + pub fn to_locale_upper_case(this: &JsString, local: Option) -> JsString; + /// The `toLowerCase()` method returns the calling string value /// converted to lower case. /// diff --git a/crates/js-sys/tests/all/JsString.rs b/crates/js-sys/tests/all/JsString.rs index 0f4d61746..53041ae63 100644 --- a/crates/js-sys/tests/all/JsString.rs +++ b/crates/js-sys/tests/all/JsString.rs @@ -617,6 +617,74 @@ fn substr() { .test() } +#[test] +fn to_locale_lower_case() { + project() + .file( + "src/lib.rs", + r#" + #![feature(use_extern_macros)] + + extern crate wasm_bindgen; + extern crate js_sys; + use wasm_bindgen::prelude::*; + + #[wasm_bindgen] + pub fn string_to_locale_lower_case(this: &js_sys::JsString, local: Option) -> js_sys::JsString { + this.to_locale_lower_case(local) + } + "#, + ) + .file( + "test.js", + r#" + import * as assert from "assert"; + import * as wasm from "./out"; + + export function test() { + assert.equal(wasm.string_to_locale_lower_case("Mozilla"), "mozilla"); + assert.equal(wasm.string_to_locale_lower_case("\u0130", "tr"), "i"); + assert.notStrictEqual(wasm.string_to_locale_lower_case("\u0130", "en-US"), "i"); + } + "#, + ) + .test() +} + +#[test] +fn to_locale_upper_case() { + project() + .file( + "src/lib.rs", + r#" + #![feature(use_extern_macros)] + + extern crate wasm_bindgen; + extern crate js_sys; + use wasm_bindgen::prelude::*; + + #[wasm_bindgen] + pub fn string_to_locale_upper_case(this: &js_sys::JsString, local: Option) -> js_sys::JsString { + this.to_locale_upper_case(local) + } + "#, + ) + .file( + "test.js", + r#" + import * as assert from "assert"; + import * as wasm from "./out"; + + export function test() { + assert.equal(wasm.string_to_locale_upper_case("mozilla"), "MOZILLA"); + assert.equal(wasm.string_to_locale_upper_case("i\u0307", "lt"), "I"); + assert.notStrictEqual(wasm.string_to_locale_upper_case("i\u0307", "en-US"), "I"); + } + "#, + ) + .test() +} + #[test] fn to_lower_case() { project()