mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-23 17:51:33 +00:00
Merge branch 'master' of git://github.com/rustwasm/wasm-bindgen
This commit is contained in:
@ -17,7 +17,6 @@
|
||||
//! bindings.
|
||||
|
||||
#![doc(html_root_url = "https://docs.rs/js-sys/0.2")]
|
||||
#![feature(use_extern_macros)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
@ -885,6 +884,7 @@ impl Function {
|
||||
// Generator
|
||||
#[wasm_bindgen]
|
||||
extern {
|
||||
#[wasm_bindgen(extends = Object)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub type Generator;
|
||||
|
||||
@ -2092,7 +2092,7 @@ extern {
|
||||
/// or range of allowed values.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RangeError
|
||||
#[wasm_bindgen(extends = Error)]
|
||||
#[wasm_bindgen(extends = Error, extends = Object)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub type RangeError;
|
||||
|
||||
@ -2111,7 +2111,7 @@ extern {
|
||||
/// variable is referenced.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ReferenceError
|
||||
#[wasm_bindgen(extends = Error)]
|
||||
#[wasm_bindgen(extends = Error, extends = Object)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub type ReferenceError;
|
||||
|
||||
@ -2505,7 +2505,7 @@ extern {
|
||||
/// parsing code.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SyntaxError
|
||||
#[wasm_bindgen(extends = Error)]
|
||||
#[wasm_bindgen(extends = Error, extends = Object)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub type SyntaxError;
|
||||
|
||||
@ -2525,7 +2525,7 @@ extern {
|
||||
/// expected type.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError
|
||||
#[wasm_bindgen(extends = Error)]
|
||||
#[wasm_bindgen(extends = Error, extends = Object)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub type TypeError;
|
||||
|
||||
@ -2758,7 +2758,7 @@ extern {
|
||||
/// function was used in a wrong way.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError
|
||||
#[wasm_bindgen(extends = Error, js_name = URIError)]
|
||||
#[wasm_bindgen(extends = Error, extends = Object, js_name = URIError)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub type UriError;
|
||||
|
||||
@ -3117,6 +3117,38 @@ extern "C" {
|
||||
#[wasm_bindgen(static_method_of = JsString, js_class = "String", js_name = fromCharCode)]
|
||||
pub fn from_char_code5(a: u32, b: u32, c: u32, d: u32, e: u32) -> JsString;
|
||||
|
||||
/// The static String.fromCodePoint() method returns a string created by
|
||||
/// using the specified sequence of code points.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint
|
||||
///
|
||||
/// # Exceptions
|
||||
///
|
||||
/// A RangeError is thrown if an invalid Unicode code point is given
|
||||
///
|
||||
/// # Notes
|
||||
///
|
||||
/// There are a few bindings to `from_code_point` in `js-sys`: `from_code_point1`, `from_code_point2`, etc...
|
||||
/// with different arities.
|
||||
#[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
|
||||
pub fn from_code_point1(a: u32) -> Result<JsString, JsValue>;
|
||||
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint
|
||||
#[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
|
||||
pub fn from_code_point2(a: u32, b: u32) -> Result<JsString, JsValue>;
|
||||
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint
|
||||
#[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
|
||||
pub fn from_code_point3(a: u32, b: u32, c: u32) -> Result<JsString, JsValue>;
|
||||
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint
|
||||
#[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
|
||||
pub fn from_code_point4(a: u32, b: u32, c: u32, d: u32) -> Result<JsString, JsValue>;
|
||||
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint
|
||||
#[wasm_bindgen(catch, static_method_of = JsString, js_class = "String", js_name = fromCodePoint)]
|
||||
pub fn from_code_point5(a: u32, b: u32, c: u32, d: u32, e: u32) -> Result<JsString, JsValue>;
|
||||
|
||||
/// The `includes()` method determines whether one string may be found
|
||||
/// within another string, returning true or false as appropriate.
|
||||
///
|
||||
@ -3140,6 +3172,20 @@ extern "C" {
|
||||
#[wasm_bindgen(method, js_class = "String", js_name = lastIndexOf)]
|
||||
pub fn last_index_of(this: &JsString, search_value: &str, from_index: i32) -> i32;
|
||||
|
||||
/// The localeCompare() method returns a number indicating whether
|
||||
/// a reference string comes before or after or is the same as
|
||||
/// the given string in sort order.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare
|
||||
#[wasm_bindgen(method, js_class = "String", js_name = localeCompare)]
|
||||
pub fn locale_compare(this: &JsString, compare_string: &str, locales: &Array, options: &Object) -> i32;
|
||||
|
||||
/// The match() method retrieves the matches when matching a string against a regular expression.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match
|
||||
#[wasm_bindgen(method, js_class = "String", js_name = match)]
|
||||
pub fn match_(this: &JsString, pattern: &RegExp) -> Option<Object>;
|
||||
|
||||
/// The normalize() method returns the Unicode Normalization Form
|
||||
/// of a given string (if the value isn't a string, it will be converted to one first).
|
||||
///
|
||||
@ -3172,6 +3218,34 @@ extern "C" {
|
||||
#[wasm_bindgen(method, js_class = "String")]
|
||||
pub fn repeat(this: &JsString, count: i32) -> JsString;
|
||||
|
||||
/// The replace() method returns a new string with some or all matches of a pattern
|
||||
/// replaced by a replacement. The pattern can be a string or a RegExp, and
|
||||
/// the replacement can be a string or a function to be called for each match.
|
||||
///
|
||||
/// Note: The original string will remain unchanged.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace
|
||||
#[wasm_bindgen(method, js_class = "String")]
|
||||
pub fn replace(this: &JsString, pattern: &str, replacement: &str) -> JsString;
|
||||
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace
|
||||
#[wasm_bindgen(method, js_class = "String", js_name = replace)]
|
||||
pub fn replace_with_function(this: &JsString, pattern: &str, replacement: &Function) -> JsString;
|
||||
|
||||
#[wasm_bindgen(method, js_class = "String", js_name = replace)]
|
||||
pub fn replace_by_pattern(this: &JsString, pattern: &RegExp, replacement: &str) -> JsString;
|
||||
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace
|
||||
#[wasm_bindgen(method, js_class = "String", js_name = replace)]
|
||||
pub fn replace_by_pattern_with_function(this: &JsString, pattern: &RegExp, replacement: &Function) -> JsString;
|
||||
|
||||
/// The search() method executes a search for a match between
|
||||
/// a regular expression and this String object.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/search
|
||||
#[wasm_bindgen(method, js_class = "String")]
|
||||
pub fn search(this: &JsString, pattern: &RegExp) -> i32;
|
||||
|
||||
/// The `slice()` method extracts a section of a string and returns it as a
|
||||
/// new string, without modifying the original string.
|
||||
///
|
||||
@ -3179,6 +3253,25 @@ extern "C" {
|
||||
#[wasm_bindgen(method, js_class = "String")]
|
||||
pub fn slice(this: &JsString, start: u32, end: u32) -> JsString;
|
||||
|
||||
/// The split() method splits a String object into an array of strings by separating the string
|
||||
/// into substrings, using a specified separator string to determine where to make each split.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split
|
||||
#[wasm_bindgen(method, js_class = "String")]
|
||||
pub fn split(this: &JsString, separator: &str) -> Array;
|
||||
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split
|
||||
#[wasm_bindgen(method, js_class = "String", js_name = split)]
|
||||
pub fn split_limit(this: &JsString, separator: &str, limit: u32) -> Array;
|
||||
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split
|
||||
#[wasm_bindgen(method, js_class = "String", js_name = split)]
|
||||
pub fn split_by_pattern(this: &JsString, pattern: &RegExp) -> Array;
|
||||
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split
|
||||
#[wasm_bindgen(method, js_class = "String", js_name = split)]
|
||||
pub fn split_by_pattern_limit(this: &JsString, pattern: &RegExp, limit: u32) -> Array;
|
||||
|
||||
/// The `startsWith()` method determines whether a string begins with the
|
||||
/// characters of a specified string, returning true or false as
|
||||
/// appropriate.
|
||||
@ -3206,14 +3299,14 @@ extern "C" {
|
||||
///
|
||||
/// 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<&str>) -> JsString;
|
||||
pub fn to_locale_lower_case(this: &JsString, locale: Option<&str>) -> 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<&str>) -> JsString;
|
||||
pub fn to_locale_upper_case(this: &JsString, locale: Option<&str>) -> JsString;
|
||||
|
||||
/// The `toLowerCase()` method returns the calling string value
|
||||
/// converted to lower case.
|
||||
@ -3502,7 +3595,7 @@ pub mod Intl {
|
||||
/// that enable language sensitive string comparison.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator
|
||||
#[wasm_bindgen(js_namespace = Intl)]
|
||||
#[wasm_bindgen(extends = Object, js_namespace = Intl)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub type Collator;
|
||||
|
||||
@ -3546,7 +3639,7 @@ pub mod Intl {
|
||||
/// that enable language-sensitive date and time formatting.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat
|
||||
#[wasm_bindgen(js_namespace = Intl)]
|
||||
#[wasm_bindgen(extends = Object, js_namespace = Intl)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub type DateTimeFormat;
|
||||
|
||||
@ -3597,7 +3690,7 @@ pub mod Intl {
|
||||
/// that enable language sensitive number formatting.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat
|
||||
#[wasm_bindgen(js_namespace = Intl)]
|
||||
#[wasm_bindgen(extends = Object, js_namespace = Intl)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub type NumberFormat;
|
||||
|
||||
@ -3647,7 +3740,7 @@ pub mod Intl {
|
||||
/// that enable plural sensitive formatting and plural language rules.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/PluralRules
|
||||
#[wasm_bindgen(js_namespace = Intl)]
|
||||
#[wasm_bindgen(extends = Object, js_namespace = Intl)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub type PluralRules;
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
#![feature(use_extern_macros)]
|
||||
#![cfg(target_arch = "wasm32")]
|
||||
|
||||
extern crate wasm_bindgen_test;
|
||||
|
@ -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