| 1 |
use js_sys::*; |
| 2 |
use wasm_bindgen::{JsCast, JsValue}; |
| 3 |
use wasm_bindgen_test::*; |
| 4 |
|
| 5 |
#[wasm_bindgen_test] |
| 6 |
fn get_canonical_locales() { |
| 7 |
let locales = Array::new(); |
| 8 |
locales.push(&"EN-US".into()); |
| 9 |
locales.push(&"Fr".into()); |
| 10 |
let locales = JsValue::from(locales); |
| 11 |
let canonical_locales = Intl::get_canonical_locales(&locales); |
| 12 |
assert_eq!(canonical_locales.length(), 2); |
| 13 |
canonical_locales.for_each(&mut |l, i, _| { |
| 14 |
if i == 0 { |
| 15 |
assert_eq!(l, "en-US"); |
| 16 |
} else { |
| 17 |
assert_eq!(l, "fr"); |
| 18 |
} |
| 19 |
}); |
| 20 |
let canonical_locales = Intl::get_canonical_locales(&"EN-US".into()); |
| 21 |
assert_eq!(canonical_locales.length(), 1); |
| 22 |
canonical_locales.for_each(&mut |l, _, _| { |
| 23 |
assert_eq!(l, "en-US"); |
| 24 |
}); |
| 25 |
} |
| 26 |
|
| 27 |
#[wasm_bindgen_test] |
| 28 |
fn collator() { |
| 29 |
let locales = Array::of1(&JsValue::from("en-US")); |
| 30 |
let opts = Object::new(); |
| 31 |
|
| 32 |
let c = Intl::Collator::new(&locales, &opts); |
| 33 |
assert!(c.compare().is_instance_of::<Function>()); |
| 34 |
assert!(c.resolved_options().is_instance_of::<Object>()); |
| 35 |
|
| 36 |
let a = Intl::Collator::supported_locales_of(&locales, &opts); |
| 37 |
assert!(a.is_instance_of::<Array>()); |
| 38 |
} |
| 39 |
|
| 40 |
#[wasm_bindgen_test] |
| 41 |
fn collator_inheritance() { |
| 42 |
let locales = Array::of1(&JsValue::from("en-US")); |
| 43 |
let opts = Object::new(); |
| 44 |
let c = Intl::Collator::new(&locales, &opts); |
| 45 |
|
| 46 |
assert!(c.is_instance_of::<Intl::Collator>()); |
| 47 |
assert!(c.is_instance_of::<Object>()); |
| 48 |
let _: &Object = c.as_ref(); |
| 49 |
} |
| 50 |
|
| 51 |
#[wasm_bindgen_test] |
| 52 |
fn date_time_format() { |
| 53 |
let locales = Array::of1(&JsValue::from("en-US")); |
| 54 |
let opts = Object::new(); |
| 55 |
let epoch = Date::new(&JsValue::from(0)); |
| 56 |
|
| 57 |
let c = Intl::DateTimeFormat::new(&locales, &opts); |
| 58 |
assert!(c.format().is_instance_of::<Function>()); |
| 59 |
assert!(c.format_to_parts(&epoch).is_instance_of::<Array>()); |
| 60 |
assert!(c.resolved_options().is_instance_of::<Object>()); |
| 61 |
|
| 62 |
let a = Intl::DateTimeFormat::supported_locales_of(&locales, &opts); |
| 63 |
assert!(a.is_instance_of::<Array>()); |
| 64 |
} |
| 65 |
|
| 66 |
#[wasm_bindgen_test] |
| 67 |
fn date_time_format_inheritance() { |
| 68 |
let locales = Array::of1(&JsValue::from("en-US")); |
| 69 |
let opts = Object::new(); |
| 70 |
let c = Intl::DateTimeFormat::new(&locales, &opts); |
| 71 |
|
| 72 |
assert!(c.is_instance_of::<Intl::DateTimeFormat>()); |
| 73 |
assert!(c.is_instance_of::<Object>()); |
| 74 |
let _: &Object = c.as_ref(); |
| 75 |
} |
| 76 |
|
| 77 |
#[wasm_bindgen_test] |
| 78 |
fn number_format() { |
| 79 |
let locales = Array::of1(&JsValue::from("en-US")); |
| 80 |
let opts = Object::new(); |
| 81 |
|
| 82 |
let n = Intl::NumberFormat::new(&locales, &opts); |
| 83 |
assert!(n.format().is_instance_of::<Function>()); |
| 84 |
assert!(n.format_to_parts(42.5).is_instance_of::<Array>()); |
| 85 |
assert!(n.resolved_options().is_instance_of::<Object>()); |
| 86 |
|
| 87 |
let a = Intl::NumberFormat::supported_locales_of(&locales, &opts); |
| 88 |
assert!(a.is_instance_of::<Array>()); |
| 89 |
} |
| 90 |
|
| 91 |
#[wasm_bindgen_test] |
| 92 |
fn number_format_inheritance() { |
| 93 |
let locales = Array::of1(&JsValue::from("en-US")); |
| 94 |
let opts = Object::new(); |
| 95 |
let n = Intl::NumberFormat::new(&locales, &opts); |
| 96 |
|
| 97 |
assert!(n.is_instance_of::<Intl::NumberFormat>()); |
| 98 |
assert!(n.is_instance_of::<Object>()); |
| 99 |
let _: &Object = n.as_ref(); |
| 100 |
} |
| 101 |
|
| 102 |
#[wasm_bindgen_test] |
| 103 |
fn plural_rules() { |
| 104 |
let locales = Array::of1(&JsValue::from("en-US")); |
| 105 |
let opts = Object::new(); |
| 106 |
|
| 107 |
let r = Intl::PluralRules::new(&locales, &opts); |
| 108 |
assert!(r.resolved_options().is_instance_of::<Object>()); |
| 109 |
assert_eq!(r.select(1_f64), "one"); |
| 110 |
|
| 111 |
let a = Intl::PluralRules::supported_locales_of(&locales, &opts); |
| 112 |
assert!(a.is_instance_of::<Array>()); |
| 113 |
} |
| 114 |
|
| 115 |
#[wasm_bindgen_test] |
| 116 |
fn relative_time_format() { |
| 117 |
let locales = Array::of1(&JsValue::from("en-US")); |
| 118 |
let opts = Object::new(); |
| 119 |
|
| 120 |
let c = Intl::RelativeTimeFormat::new(&locales, &opts); |
| 121 |
assert!(c.format(1_f64.into(), &"seconds").is_string()); |
| 122 |
assert!(c |
| 123 |
.format_to_parts(1_f64.into(), &"seconds") |
| 124 |
.is_instance_of::<Array>()); |
| 125 |
assert!(c.resolved_options().is_instance_of::<Object>()); |
| 126 |
|
| 127 |
assert_eq!(c.format(1_f64.into(), &"seconds"), "in 1 second"); |
| 128 |
assert_eq!(c.format(1.5.into(), &"seconds"), "in 1.5 seconds"); |
| 129 |
assert_eq!(c.format((-1.5).into(), &"seconds"), "1.5 seconds ago"); |
| 130 |
|
| 131 |
let a = Intl::RelativeTimeFormat::supported_locales_of(&locales, &opts); |
| 132 |
assert!(a.is_instance_of::<Array>()); |
| 133 |
} |
| 134 |
|
| 135 |
#[wasm_bindgen_test] |
| 136 |
fn plural_rules_inheritance() { |
| 137 |
let locales = Array::of1(&JsValue::from("en-US")); |
| 138 |
let opts = Object::new(); |
| 139 |
let r = Intl::PluralRules::new(&locales, &opts); |
| 140 |
|
| 141 |
assert!(r.is_instance_of::<Intl::PluralRules>()); |
| 142 |
assert!(r.is_instance_of::<Object>()); |
| 143 |
let _: &Object = r.as_ref(); |
| 144 |
} |