diff --git a/crates/js-sys/tests/all/Intl.rs b/crates/js-sys/tests/all/Intl.rs deleted file mode 100644 index b9954469..00000000 --- a/crates/js-sys/tests/all/Intl.rs +++ /dev/null @@ -1,34 +0,0 @@ -#![allow(non_snake_case)] - -use project; - -#[test] -fn get_canonical_locales() { - 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 get_canonical_locales(v: &JsValue) -> js_sys::Array { - js_sys::Intl::get_canonical_locales(v) - } - "#) - .file("test.js", r#" - import * as assert from "assert"; - import * as wasm from "./out"; - - export function test() { - let locales = ["EN-US", "Fr"]; - let canonical_locales = wasm.get_canonical_locales(locales); - assert.deepStrictEqual(canonical_locales, ["en-US", "fr"]); - - let single_locale = wasm.get_canonical_locales("EN-US"); - assert.equal(single_locale, "en-US"); - } - "#) - .test() -} \ No newline at end of file diff --git a/crates/js-sys/tests/all/main.rs b/crates/js-sys/tests/all/main.rs index 51b06e58..fafd6db9 100644 --- a/crates/js-sys/tests/all/main.rs +++ b/crates/js-sys/tests/all/main.rs @@ -11,7 +11,6 @@ fn project() -> project_builder::Project { // Keep these tests in alphabetical order, just like the imports in `src/js.rs`. mod ArrayIterator; -mod Intl; mod JsString; mod Map; mod MapIterator; diff --git a/crates/js-sys/tests/wasm/Intl.rs b/crates/js-sys/tests/wasm/Intl.rs new file mode 100644 index 00000000..208dd6a2 --- /dev/null +++ b/crates/js-sys/tests/wasm/Intl.rs @@ -0,0 +1,25 @@ +use wasm_bindgen::JsValue; +use wasm_bindgen_test::*; +use js_sys::*; + +#[wasm_bindgen_test] +fn get_canonical_locales() { + let locales = Array::new(); + locales.push("EN-US".into()); + locales.push("Fr".into()); + let locales = JsValue::from(locales); + let canonical_locales = Intl::get_canonical_locales(&locales); + assert_eq!(canonical_locales.length(), 2); + canonical_locales.for_each(&mut |l, i, _| { + if i == 0 { + assert_eq!(l, "en-US"); + } else { + assert_eq!(l, "fr"); + } + }); + let canonical_locales = Intl::get_canonical_locales(&"EN-US".into()); + assert_eq!(canonical_locales.length(), 1); + canonical_locales.for_each(&mut |l, _, _| { + assert_eq!(l, "en-US"); + }); +} diff --git a/crates/js-sys/tests/wasm/main.rs b/crates/js-sys/tests/wasm/main.rs index e0e41ec4..e71e2488 100644 --- a/crates/js-sys/tests/wasm/main.rs +++ b/crates/js-sys/tests/wasm/main.rs @@ -15,3 +15,4 @@ pub mod Date; pub mod Error; pub mod Function; pub mod Generator; +pub mod Intl;