mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-07-31 03:51:56 +00:00
Merge branch 'master' of git://github.com/rustwasm/wasm-bindgen
This commit is contained in:
@@ -306,4 +306,5 @@ fn array_inheritance() {
|
||||
let array = Array::new();
|
||||
assert!(array.is_instance_of::<Array>());
|
||||
assert!(array.is_instance_of::<Object>());
|
||||
let _: &Object = array.as_ref();
|
||||
}
|
||||
|
@@ -41,4 +41,5 @@ fn arraybuffer_inheritance() {
|
||||
let buf = ArrayBuffer::new(4);
|
||||
assert!(buf.is_instance_of::<ArrayBuffer>());
|
||||
assert!(buf.is_instance_of::<Object>());
|
||||
let _: &Object = buf.as_ref();
|
||||
}
|
||||
|
@@ -18,4 +18,5 @@ fn boolean_inheritance() {
|
||||
let b = Boolean::new(&JsValue::from(true));
|
||||
assert!(b.is_instance_of::<Boolean>());
|
||||
assert!(b.is_instance_of::<Object>());
|
||||
let _: &Object = b.as_ref();
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
use js_sys::*;
|
||||
use wasm_bindgen::JsCast;
|
||||
use wasm_bindgen::JsValue;
|
||||
use wasm_bindgen_test::*;
|
||||
use wasm_bindgen::JsCast;
|
||||
use js_sys::*;
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn test() {
|
||||
@@ -36,7 +36,9 @@ fn test() {
|
||||
v.set_int8(0, 42);
|
||||
|
||||
// TODO: figure out how to do `bytes[2]`
|
||||
bytes.subarray(2, 3).for_each(&mut |x, _, _| assert_eq!(x, 42));
|
||||
bytes
|
||||
.subarray(2, 3)
|
||||
.for_each(&mut |x, _, _| assert_eq!(x, 42));
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
@@ -50,4 +52,5 @@ fn dataview_inheritance() {
|
||||
|
||||
assert!(v.is_instance_of::<DataView>());
|
||||
assert!(v.is_instance_of::<Object>());
|
||||
let _: &Object = v.as_ref();
|
||||
}
|
||||
|
@@ -413,4 +413,5 @@ fn date_inheritance() {
|
||||
let date = Date::new(&"August 19, 1975 23:15:30".into());
|
||||
assert!(date.is_instance_of::<Date>());
|
||||
assert!(date.is_instance_of::<Object>());
|
||||
let _: &Object = date.as_ref();
|
||||
}
|
||||
|
@@ -42,4 +42,5 @@ fn error_inheritance() {
|
||||
let error = Error::new("test");
|
||||
assert!(error.is_instance_of::<Error>());
|
||||
assert!(error.is_instance_of::<Object>());
|
||||
let _: &Object = error.as_ref();
|
||||
}
|
||||
|
@@ -52,4 +52,6 @@ fn evalerror_inheritance() {
|
||||
assert!(error.is_instance_of::<EvalError>());
|
||||
assert!(error.is_instance_of::<Error>());
|
||||
assert!(error.is_instance_of::<Object>());
|
||||
let _: &Error = error.as_ref();
|
||||
let _: &Object = error.as_ref();
|
||||
}
|
||||
|
@@ -66,4 +66,5 @@ fn to_string() {
|
||||
fn function_inheritance() {
|
||||
assert!(MAX.is_instance_of::<Function>());
|
||||
assert!(MAX.is_instance_of::<Object>());
|
||||
let _: &Object = MAX.as_ref();
|
||||
}
|
||||
|
@@ -1,5 +1,6 @@
|
||||
use wasm_bindgen::prelude::*;
|
||||
use wasm_bindgen_test::*;
|
||||
use wasm_bindgen::JsCast;
|
||||
use js_sys::*;
|
||||
|
||||
#[wasm_bindgen(module = "tests/wasm/Generator.js")]
|
||||
@@ -56,3 +57,10 @@ fn throw() {
|
||||
assert!(next.value().is_undefined());
|
||||
assert!(next.done());
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn generator_inheritance() {
|
||||
let gen = dummy_generator();
|
||||
|
||||
assert!(gen.is_instance_of::<Object>());
|
||||
}
|
||||
|
@@ -37,6 +37,17 @@ fn collator() {
|
||||
assert!(a.is_instance_of::<Array>());
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn collator_inheritance() {
|
||||
let locales = Array::of1(&JsValue::from("en-US"));
|
||||
let opts = Object::new();
|
||||
let c = Intl::Collator::new(&locales, &opts);
|
||||
|
||||
assert!(c.is_instance_of::<Intl::Collator>());
|
||||
assert!(c.is_instance_of::<Object>());
|
||||
let _: &Object = c.as_ref();
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn date_time_format() {
|
||||
let locales = Array::of1(&JsValue::from("en-US"));
|
||||
@@ -52,6 +63,17 @@ fn date_time_format() {
|
||||
assert!(a.is_instance_of::<Array>());
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn date_time_format_inheritance() {
|
||||
let locales = Array::of1(&JsValue::from("en-US"));
|
||||
let opts = Object::new();
|
||||
let c = Intl::DateTimeFormat::new(&locales, &opts);
|
||||
|
||||
assert!(c.is_instance_of::<Intl::DateTimeFormat>());
|
||||
assert!(c.is_instance_of::<Object>());
|
||||
let _: &Object = c.as_ref();
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn number_format() {
|
||||
let locales = Array::of1(&JsValue::from("en-US"));
|
||||
@@ -66,6 +88,17 @@ fn number_format() {
|
||||
assert!(a.is_instance_of::<Array>());
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn number_format_inheritance() {
|
||||
let locales = Array::of1(&JsValue::from("en-US"));
|
||||
let opts = Object::new();
|
||||
let n = Intl::NumberFormat::new(&locales, &opts);
|
||||
|
||||
assert!(n.is_instance_of::<Intl::NumberFormat>());
|
||||
assert!(n.is_instance_of::<Object>());
|
||||
let _: &Object = n.as_ref();
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn plural_rules() {
|
||||
let locales = Array::of1(&JsValue::from("en-US"));
|
||||
@@ -75,6 +108,17 @@ fn plural_rules() {
|
||||
assert!(r.resolved_options().is_instance_of::<Object>());
|
||||
assert_eq!(r.select(1_f64), "one");
|
||||
|
||||
let r = Intl::PluralRules::supported_locales_of(&locales, &opts);
|
||||
assert!(r.is_instance_of::<Array>());
|
||||
let a = Intl::PluralRules::supported_locales_of(&locales, &opts);
|
||||
assert!(a.is_instance_of::<Array>());
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn plural_rules_inheritance() {
|
||||
let locales = Array::of1(&JsValue::from("en-US"));
|
||||
let opts = Object::new();
|
||||
let r = Intl::PluralRules::new(&locales, &opts);
|
||||
|
||||
assert!(r.is_instance_of::<Intl::PluralRules>());
|
||||
assert!(r.is_instance_of::<Object>());
|
||||
let _: &Object = r.as_ref();
|
||||
}
|
||||
|
@@ -1 +1,7 @@
|
||||
exports.new_string_object = () => new String("hi");
|
||||
exports.new_string_object = () => new String("hi");
|
||||
|
||||
exports.get_replacer_function = function() {
|
||||
return function upperToHyphenLower(match, offset, string) {
|
||||
return (offset > 0 ? '-' : '') + match.toLowerCase();
|
||||
};
|
||||
};
|
||||
|
@@ -7,6 +7,7 @@ use js_sys::*;
|
||||
#[wasm_bindgen(module = "tests/wasm/JsString.js")]
|
||||
extern {
|
||||
fn new_string_object() -> JsValue;
|
||||
fn get_replacer_function() -> Function;
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
@@ -85,6 +86,23 @@ fn from_char_code() {
|
||||
assert_eq!(JsString::from_char_code4(codes[0], codes[1], codes[2], codes[3]), "½+¾=");
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn from_code_point() {
|
||||
let s = "☃★♲你";
|
||||
let codes : Vec<u32> = s.chars()
|
||||
.map(|char| char as u32)
|
||||
.collect();
|
||||
|
||||
assert_eq!(JsString::from_code_point1(codes[0]).unwrap(), "☃");
|
||||
assert_eq!(JsString::from_code_point2(codes[0], codes[1]).unwrap(), "☃★");
|
||||
assert_eq!(JsString::from_code_point3(codes[0], codes[1], codes[2]).unwrap(), "☃★♲");
|
||||
assert_eq!(JsString::from_code_point4(codes[0], codes[1], codes[2], codes[3]).unwrap(), "☃★♲你");
|
||||
|
||||
assert!(!JsString::from_code_point1(0x10FFFF).is_err());
|
||||
assert!(JsString::from_code_point1(0x110000).is_err());
|
||||
assert!(JsString::from_code_point1(u32::max_value()).is_err());
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn includes() {
|
||||
let str = JsString::from("Blue Whale");
|
||||
@@ -135,6 +153,95 @@ fn last_index_of() {
|
||||
assert_eq!(js.last_index_of("", 2), 2);
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn locale_compare() {
|
||||
let a = "résumé";
|
||||
let b = "RESUME";
|
||||
let js_a = JsString::from(a);
|
||||
let js_b = JsString::from(b);
|
||||
let locales = Array::new();
|
||||
let options = Object::new();
|
||||
|
||||
assert_eq!(js_a.locale_compare(a, &locales, &options), 0);
|
||||
assert_eq!(js_b.locale_compare(b, &locales, &options), 0);
|
||||
assert!(js_a.locale_compare(b, &locales, &options) > 0);
|
||||
assert!(js_b.locale_compare(a, &locales, &options) < 0);
|
||||
|
||||
locales.push(&"en".into());
|
||||
Reflect::set(options.as_ref(), &"sensitivity".into(), &"base".into());
|
||||
|
||||
assert_eq!(js_a.locale_compare(a, &locales, &options), 0);
|
||||
assert_eq!(js_a.locale_compare(b, &locales, &options), 0);
|
||||
assert_eq!(js_b.locale_compare(a, &locales, &options), 0);
|
||||
assert_eq!(js_b.locale_compare(b, &locales, &options), 0);
|
||||
|
||||
let a = "ä";
|
||||
let z = "z";
|
||||
let js_a = JsString::from(a);
|
||||
let js_z = JsString::from(z);
|
||||
let locales_de = Array::of1(&"de".into());
|
||||
let locales_sv = Array::of1(&"sv".into());
|
||||
let options = Object::new();
|
||||
|
||||
assert_eq!(js_a.locale_compare(a, &locales_de, &options), 0);
|
||||
assert_eq!(js_z.locale_compare(z, &locales_de, &options), 0);
|
||||
assert!(js_a.locale_compare(z, &locales_de, &options) < 0);
|
||||
assert!(js_z.locale_compare(a, &locales_de, &options) > 0);
|
||||
|
||||
assert_eq!(js_a.locale_compare(a, &locales_sv, &options), 0);
|
||||
assert_eq!(js_z.locale_compare(z, &locales_sv, &options), 0);
|
||||
assert!(js_a.locale_compare(z, &locales_sv, &options) < 0);
|
||||
assert!(js_z.locale_compare(a, &locales_sv, &options) > 0);
|
||||
|
||||
let two = "2";
|
||||
let ten = "10";
|
||||
let js_two = JsString::from(two);
|
||||
let js_ten = JsString::from(ten);
|
||||
let locales = Array::new();
|
||||
let options = Object::new();
|
||||
|
||||
assert_eq!(js_two.locale_compare(two, &locales, &options), 0);
|
||||
assert_eq!(js_ten.locale_compare(ten, &locales, &options), 0);
|
||||
assert!(js_two.locale_compare(ten, &locales, &options) > 0);
|
||||
assert!(js_ten.locale_compare(two, &locales, &options) < 0);
|
||||
|
||||
locales.push(&"en-u-kn-true".into());
|
||||
|
||||
assert!(js_two.locale_compare(ten, &locales, &options) < 0);
|
||||
assert!(js_ten.locale_compare(two, &locales, &options) > 0);
|
||||
|
||||
let locales = Array::new();
|
||||
Reflect::set(options.as_ref(), &"numeric".into(), &JsValue::TRUE);
|
||||
|
||||
assert!(js_two.locale_compare(ten, &locales, &options) < 0);
|
||||
assert!(js_ten.locale_compare(two, &locales, &options) > 0);
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn match_() {
|
||||
let s = "The quick brown fox jumped over the lazy dog. It barked.";
|
||||
let re = RegExp::new("[A-Z]", "g");
|
||||
let result = JsString::from(s).match_(&re);
|
||||
let obj = result.unwrap();
|
||||
|
||||
assert_eq!(Reflect::get(obj.as_ref(), &"0".into()), "T");
|
||||
assert_eq!(Reflect::get(obj.as_ref(), &"1".into()), "I");
|
||||
|
||||
let result = JsString::from("foo").match_(&re);
|
||||
assert!(result.is_none());
|
||||
|
||||
let s = "For more information, see Chapter 3.4.5.1";
|
||||
let re = RegExp::new("see (chapter \\d+(\\.\\d)*)", "i");
|
||||
let result = JsString::from(s).match_(&re);
|
||||
let obj = result.unwrap();
|
||||
|
||||
assert_eq!(Reflect::get(obj.as_ref(), &"0".into()), "see Chapter 3.4.5.1");
|
||||
assert_eq!(Reflect::get(obj.as_ref(), &"1".into()), "Chapter 3.4.5.1");
|
||||
assert_eq!(Reflect::get(obj.as_ref(), &"2".into()), ".1");
|
||||
assert_eq!(Reflect::get(obj.as_ref(), &"index".into()), 22);
|
||||
assert_eq!(Reflect::get(obj.as_ref(), &"input".into()), s);
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn normalize() {
|
||||
let js = JsString::from("\u{1E9B}\u{0323}");
|
||||
@@ -178,12 +285,106 @@ fn repeat() {
|
||||
assert_eq!(JsString::from("test").repeat(3), "testtesttest");
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn replace() {
|
||||
let js = JsString::from("The quick brown fox jumped over the lazy dog. If the dog reacted, was it really lazy?");
|
||||
let result = js.replace("dog", "ferret");
|
||||
|
||||
assert_eq!(result, "The quick brown fox jumped over the lazy ferret. If the dog reacted, was it really lazy?");
|
||||
|
||||
let js = JsString::from("borderTop");
|
||||
let result = js.replace_with_function("T", &get_replacer_function());
|
||||
|
||||
assert_eq!(result, "border-top");
|
||||
|
||||
let js = JsString::from("The quick brown fox jumped over the lazy dog. If the dog reacted, was it really lazy?");
|
||||
let re = RegExp::new("dog", "g");
|
||||
let result = js.replace_by_pattern(&re, "ferret");
|
||||
|
||||
assert_eq!(result, "The quick brown fox jumped over the lazy ferret. If the ferret reacted, was it really lazy?");
|
||||
|
||||
let js = JsString::from("borderTop");
|
||||
let re = RegExp::new("[A-Z]", "g");
|
||||
let result = js.replace_by_pattern_with_function(&re, &get_replacer_function());
|
||||
|
||||
assert_eq!(result, "border-top");
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn search() {
|
||||
let js = JsString::from("The quick brown fox jumped over the lazy dog. If the dog reacted, was it really lazy?");
|
||||
let re = RegExp::new("[^\\w\\s]", "g");
|
||||
|
||||
assert_eq!(js.search(&re), 44);
|
||||
|
||||
let js = JsString::from("hey JudE");
|
||||
let re1 = RegExp::new("[A-Z]", "g");
|
||||
let re2 = RegExp::new("[.]", "g");
|
||||
|
||||
assert_eq!(js.search(&re1), 4);
|
||||
assert_eq!(js.search(&re2), -1);
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn slice() {
|
||||
let characters = JsString::from("acxn18");
|
||||
assert_eq!(characters.slice(1, 3), "cx");
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn split() {
|
||||
let js = JsString::from("Oh brave new world");
|
||||
let result = js.split(" ");
|
||||
|
||||
let mut v = Vec::with_capacity(result.length() as usize);
|
||||
result.for_each(&mut |x, _, _| v.push(x));
|
||||
|
||||
assert_eq!(v[0], "Oh");
|
||||
assert_eq!(v[1], "brave");
|
||||
assert_eq!(v[2], "new");
|
||||
assert_eq!(v[3], "world");
|
||||
|
||||
let js = JsString::from("Oct,Nov,Dec");
|
||||
let result = js.split(",");
|
||||
|
||||
let mut v = Vec::with_capacity(result.length() as usize);
|
||||
result.for_each(&mut |x, _, _| v.push(x));
|
||||
|
||||
assert_eq!(v[0], "Oct");
|
||||
assert_eq!(v[1], "Nov");
|
||||
assert_eq!(v[2], "Dec");
|
||||
|
||||
let result = js.split_limit(",", 2);
|
||||
|
||||
let mut v = Vec::with_capacity(result.length() as usize);
|
||||
result.for_each(&mut |x, _, _| v.push(x));
|
||||
|
||||
assert_eq!(result.length(), 2);
|
||||
assert_eq!(v[0], "Oct");
|
||||
assert_eq!(v[1], "Nov");
|
||||
|
||||
let js = JsString::from("Oh brave new world");
|
||||
let re = RegExp::new("\\s", "g");
|
||||
let result = js.split_by_pattern(&re);
|
||||
|
||||
let mut v = Vec::with_capacity(result.length() as usize);
|
||||
result.for_each(&mut |x, _, _| v.push(x));
|
||||
|
||||
assert_eq!(v[0], "Oh");
|
||||
assert_eq!(v[1], "brave");
|
||||
assert_eq!(v[2], "new");
|
||||
assert_eq!(v[3], "world");
|
||||
|
||||
let result = js.split_by_pattern_limit(&re, 2);
|
||||
|
||||
let mut v = Vec::with_capacity(result.length() as usize);
|
||||
result.for_each(&mut |x, _, _| v.push(x));
|
||||
|
||||
assert_eq!(result.length(), 2);
|
||||
assert_eq!(v[0], "Oh");
|
||||
assert_eq!(v[1], "brave");
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn starts_with() {
|
||||
let js = JsString::from("To be, or not to be, that is the question.");
|
||||
|
@@ -93,4 +93,5 @@ fn map_inheritance() {
|
||||
let map = Map::new();
|
||||
assert!(map.is_instance_of::<Map>());
|
||||
assert!(map.is_instance_of::<Object>());
|
||||
let _: &Object = map.as_ref();
|
||||
}
|
||||
|
@@ -111,4 +111,5 @@ fn number_inheritance() {
|
||||
let n = Number::new(&JsValue::from(42));
|
||||
assert!(n.is_instance_of::<Number>());
|
||||
assert!(n.is_instance_of::<Object>());
|
||||
let _: &Object = n.as_ref();
|
||||
}
|
||||
|
@@ -9,6 +9,8 @@ fn range_error() {
|
||||
assert!(error.is_instance_of::<RangeError>());
|
||||
assert!(error.is_instance_of::<Error>());
|
||||
assert!(error.is_instance_of::<Object>());
|
||||
let _: &Error = error.as_ref();
|
||||
let _: &Object = error.as_ref();
|
||||
|
||||
let base: &Error = error.as_ref();
|
||||
assert_eq!(JsValue::from(base.message()), "out of range yo");
|
||||
|
@@ -9,6 +9,8 @@ fn reference_error() {
|
||||
assert!(error.is_instance_of::<ReferenceError>());
|
||||
assert!(error.is_instance_of::<Error>());
|
||||
assert!(error.is_instance_of::<Object>());
|
||||
let _: &Error = error.as_ref();
|
||||
let _: &Object = error.as_ref();
|
||||
|
||||
let base: &Error = error.as_ref();
|
||||
assert_eq!(JsValue::from(base.message()), "bad reference, fool");
|
||||
|
@@ -7,6 +7,7 @@ fn regexp_inheritance() {
|
||||
let re = RegExp::new(".", "");
|
||||
assert!(re.is_instance_of::<RegExp>());
|
||||
assert!(re.is_instance_of::<Object>());
|
||||
let _: &Object = re.as_ref();
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
|
@@ -87,4 +87,5 @@ fn set_inheritance() {
|
||||
let set = Set::new(&JsValue::undefined());
|
||||
assert!(set.is_instance_of::<Set>());
|
||||
assert!(set.is_instance_of::<Object>());
|
||||
let _: &Object = set.as_ref();
|
||||
}
|
||||
|
@@ -9,6 +9,8 @@ fn syntax_error() {
|
||||
assert!(error.is_instance_of::<SyntaxError>());
|
||||
assert!(error.is_instance_of::<Error>());
|
||||
assert!(error.is_instance_of::<Object>());
|
||||
let _: &Error = error.as_ref();
|
||||
let _: &Object = error.as_ref();
|
||||
|
||||
let base: &Error = error.as_ref();
|
||||
assert_eq!(JsValue::from(base.message()), "msg");
|
||||
|
@@ -9,6 +9,8 @@ fn type_error() {
|
||||
assert!(error.is_instance_of::<TypeError>());
|
||||
assert!(error.is_instance_of::<Error>());
|
||||
assert!(error.is_instance_of::<Object>());
|
||||
let _: &Error = error.as_ref();
|
||||
let _: &Object = error.as_ref();
|
||||
|
||||
let base: &Error = error.as_ref();
|
||||
assert_eq!(JsValue::from(base.message()), "msg");
|
||||
|
@@ -9,6 +9,8 @@ fn uri_error() {
|
||||
assert!(error.is_instance_of::<UriError>());
|
||||
assert!(error.is_instance_of::<Error>());
|
||||
assert!(error.is_instance_of::<Object>());
|
||||
let _: &Error = error.as_ref();
|
||||
let _: &Object = error.as_ref();
|
||||
|
||||
let base: &Error = error.as_ref();
|
||||
assert_eq!(JsValue::from(base.message()), "msg");
|
||||
|
@@ -57,4 +57,5 @@ fn weakmap_inheritance() {
|
||||
let map = WeakMap::new();
|
||||
assert!(map.is_instance_of::<WeakMap>());
|
||||
assert!(map.is_instance_of::<Object>());
|
||||
let _: &Object = map.as_ref();
|
||||
}
|
||||
|
@@ -47,4 +47,5 @@ fn weakset_inheritance() {
|
||||
let set = WeakSet::new();
|
||||
assert!(set.is_instance_of::<WeakSet>());
|
||||
assert!(set.is_instance_of::<Object>());
|
||||
let _: &Object = set.as_ref();
|
||||
}
|
||||
|
@@ -1,5 +1,4 @@
|
||||
#![cfg(target_arch = "wasm32")]
|
||||
#![feature(use_extern_macros)]
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
extern crate futures;
|
||||
|
Reference in New Issue
Block a user