mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-23 17:51:33 +00:00
Js sys use &str arguments (#555)
* js-sys: imports should take &str parameters instead of &JsString * js-sys: Imports should take Option<&str> instead of Option<String>
This commit is contained in:
committed by
Alex Crichton
parent
19acb5bb72
commit
64591ef403
@ -149,8 +149,8 @@ fn now() {
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn parse() {
|
||||
let date = Date::parse(&"04 Dec 1995 00:12:00 GMT".into());
|
||||
let zero = Date::parse(&"01 Jan 1970 00:00:00 GMT".into());
|
||||
let date = Date::parse("04 Dec 1995 00:12:00 GMT");
|
||||
let zero = Date::parse("01 Jan 1970 00:00:00 GMT");
|
||||
|
||||
assert_eq!(date, 818035920000.0);
|
||||
assert_eq!(zero, 0.0);
|
||||
@ -355,14 +355,14 @@ fn to_json() {
|
||||
#[wasm_bindgen_test]
|
||||
fn to_locale_date_string() {
|
||||
let date = Date::new(&"August 19, 1975 23:15:30 UTC".into());
|
||||
let s = date.to_locale_date_string(&"de-DE".into(), &JsValue::undefined());
|
||||
let s = date.to_locale_date_string("de-DE", &JsValue::undefined());
|
||||
assert!(s.length() > 0);
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn to_locale_string() {
|
||||
let date = Date::new(&"August 19, 1975 23:15:30 UTC".into());
|
||||
let s = date.to_locale_string(&"de-DE".into(), &JsValue::undefined());
|
||||
let s = date.to_locale_string("de-DE", &JsValue::undefined());
|
||||
assert!(s.length() > 0);
|
||||
}
|
||||
|
||||
@ -370,7 +370,7 @@ fn to_locale_string() {
|
||||
fn to_locale_time_string() {
|
||||
let date = Date::new(&"August 19, 1975 23:15:30".into());
|
||||
assert_eq!(
|
||||
JsValue::from(date.to_locale_time_string(&"en-US".into())),
|
||||
JsValue::from(date.to_locale_time_string("en-US")),
|
||||
"11:15:30 PM",
|
||||
);
|
||||
}
|
||||
|
@ -4,34 +4,34 @@ use js_sys::*;
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn new() {
|
||||
let error = Error::new(&"some message".into());
|
||||
let error = Error::new("some message");
|
||||
assert_eq!(JsValue::from(error.message()), "some message");
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn set_message() {
|
||||
let error = Error::new(&"test".into());
|
||||
error.set_message(&"another".into());
|
||||
let error = Error::new("test");
|
||||
error.set_message("another");
|
||||
assert_eq!(JsValue::from(error.message()), "another");
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn name() {
|
||||
let error = Error::new(&"test".into());
|
||||
let error = Error::new("test");
|
||||
assert_eq!(JsValue::from(error.name()), "Error");
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn set_name() {
|
||||
let error = Error::new(&"test".into());
|
||||
error.set_name(&"different".into());
|
||||
let error = Error::new("test");
|
||||
error.set_name("different");
|
||||
assert_eq!(JsValue::from(error.name()), "different");
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn to_string() {
|
||||
let error = Error::new(&"error message 1".into());
|
||||
let error = Error::new("error message 1");
|
||||
assert_eq!(JsValue::from(error.to_string()), "Error: error message 1");
|
||||
error.set_name(&"error_name_1".into());
|
||||
error.set_name("error_name_1");
|
||||
assert_eq!(JsValue::from(error.to_string()), "error_name_1: error message 1");
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ fn throw() {
|
||||
let gen = one_two_generator();
|
||||
gen.next(&JsValue::undefined()).unwrap();
|
||||
|
||||
assert!(gen.throw(&Error::new(&"something went wrong".into())).is_err());
|
||||
assert!(gen.throw(&Error::new("something went wrong")).is_err());
|
||||
let next = GeneratorResult::from(gen.next(&JsValue::undefined()).unwrap());
|
||||
assert!(next.value().is_undefined());
|
||||
assert!(next.done());
|
||||
|
@ -53,9 +53,9 @@ fn ends_with() {
|
||||
let js = JsString::from(s);
|
||||
|
||||
// TODO: remove third parameter once we have optional parameters
|
||||
assert_eq!(js.ends_with(&"question.".into(), s.len() as i32), true);
|
||||
assert_eq!(js.ends_with(&"to be".into(), s.len() as i32), false);
|
||||
assert_eq!(js.ends_with(&"to be".into(), 19), true);
|
||||
assert_eq!(js.ends_with("question.", s.len() as i32), true);
|
||||
assert_eq!(js.ends_with("to be", s.len() as i32), false);
|
||||
assert_eq!(js.ends_with("to be", 19), true);
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
@ -63,13 +63,13 @@ fn includes() {
|
||||
let str = JsString::from("Blue Whale");
|
||||
|
||||
// TODO: remove second parameter once we have optional parameters
|
||||
assert_eq!(str.includes(&"Blue".into(), 0), true);
|
||||
assert_eq!(str.includes(&"Blute".into(), 0), false);
|
||||
assert_eq!(str.includes(&"Whale".into(), 0), true);
|
||||
assert_eq!(str.includes(&"Whale".into(), 5), true);
|
||||
assert_eq!(str.includes(&"Whale".into(), 7), false);
|
||||
assert_eq!(str.includes(&"".into(), 0), true);
|
||||
assert_eq!(str.includes(&"".into(), 16), true);
|
||||
assert_eq!(str.includes("Blue", 0), true);
|
||||
assert_eq!(str.includes("Blute", 0), false);
|
||||
assert_eq!(str.includes("Whale", 0), true);
|
||||
assert_eq!(str.includes("Whale", 5), true);
|
||||
assert_eq!(str.includes("Whale", 7), false);
|
||||
assert_eq!(str.includes("", 0), true);
|
||||
assert_eq!(str.includes("", 16), true);
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
@ -77,17 +77,17 @@ fn index_of() {
|
||||
let str = JsString::from("Blue Whale");
|
||||
|
||||
// TODO: remove second parameter once we have optional parameters
|
||||
assert_eq!(str.index_of(&"Blue".into(), 0), 0);
|
||||
assert_eq!(str.index_of("Blue", 0), 0);
|
||||
// TODO: remove second parameter once we have optional parameters
|
||||
assert_eq!(str.index_of(&"Blute".into(), 0), -1);
|
||||
assert_eq!(str.index_of(&"Whale".into(), 0), 5);
|
||||
assert_eq!(str.index_of(&"Whale".into(), 5), 5);
|
||||
assert_eq!(str.index_of(&"Whale".into(), 7), -1);
|
||||
assert_eq!(str.index_of("Blute", 0), -1);
|
||||
assert_eq!(str.index_of("Whale", 0), 5);
|
||||
assert_eq!(str.index_of("Whale", 5), 5);
|
||||
assert_eq!(str.index_of("Whale", 7), -1);
|
||||
// TODO: remove second parameter once we have optional parameters
|
||||
assert_eq!(str.index_of(&"".into(), 0), 0);
|
||||
assert_eq!(str.index_of(&"".into(), 9), 9);
|
||||
assert_eq!(str.index_of(&"".into(), 10), 10);
|
||||
assert_eq!(str.index_of(&"".into(), 11), 10);
|
||||
assert_eq!(str.index_of("", 0), 0);
|
||||
assert_eq!(str.index_of("", 9), 9);
|
||||
assert_eq!(str.index_of("", 10), 10);
|
||||
assert_eq!(str.index_of("", 11), 10);
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
@ -96,16 +96,16 @@ fn last_index_of() {
|
||||
let len = js.length() as i32;
|
||||
|
||||
// TODO: remove second parameter once we have optional parameters
|
||||
assert_eq!(js.last_index_of(&"a".into(), len), 3);
|
||||
assert_eq!(js.last_index_of(&"a".into(), 2), 1);
|
||||
assert_eq!(js.last_index_of(&"a".into(), 0), -1);
|
||||
assert_eq!(js.last_index_of("a", len), 3);
|
||||
assert_eq!(js.last_index_of("a", 2), 1);
|
||||
assert_eq!(js.last_index_of("a", 0), -1);
|
||||
// TODO: remove second parameter once we have optional parameters
|
||||
assert_eq!(js.last_index_of(&"x".into(), len), -1);
|
||||
assert_eq!(js.last_index_of(&"c".into(), -5), 0);
|
||||
assert_eq!(js.last_index_of(&"c".into(), 0), 0);
|
||||
assert_eq!(js.last_index_of("x", len), -1);
|
||||
assert_eq!(js.last_index_of("c", -5), 0);
|
||||
assert_eq!(js.last_index_of("c", 0), 0);
|
||||
// TODO: remove second parameter once we have optional parameters
|
||||
assert_eq!(js.last_index_of(&"".into(), len), 5);
|
||||
assert_eq!(js.last_index_of(&"".into(), 2), 2);
|
||||
assert_eq!(js.last_index_of("", len), 5);
|
||||
assert_eq!(js.last_index_of("", 2), 2);
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
@ -113,10 +113,10 @@ fn normalize() {
|
||||
let js = JsString::from("\u{1E9B}\u{0323}");
|
||||
|
||||
// TODO: Handle undefined
|
||||
assert_eq!(JsValue::from(js.normalize(&"NFC".into())), "\u{1E9B}\u{0323}");
|
||||
assert_eq!(JsValue::from(js.normalize(&"NFD".into())), "\u{017F}\u{0323}\u{0307}");
|
||||
assert_eq!(JsValue::from(js.normalize(&"NFKC".into())), "\u{1E69}");
|
||||
assert_eq!(JsValue::from(js.normalize(&"NFKD".into())), "\u{0073}\u{0323}\u{0307}");
|
||||
assert_eq!(JsValue::from(js.normalize("NFC")), "\u{1E9B}\u{0323}");
|
||||
assert_eq!(JsValue::from(js.normalize("NFD")), "\u{017F}\u{0323}\u{0307}");
|
||||
assert_eq!(JsValue::from(js.normalize("NFKC")), "\u{1E69}");
|
||||
assert_eq!(JsValue::from(js.normalize("NFKD")), "\u{0073}\u{0323}\u{0307}");
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
@ -124,13 +124,13 @@ fn pad_end() {
|
||||
let js = JsString::from("abc");
|
||||
|
||||
// TODO: remove second parameter once we have optional parameters
|
||||
assert_eq!(JsValue::from(js.pad_end(10, &" ".into())), "abc ");
|
||||
assert_eq!(JsValue::from(js.pad_end(10, " ")), "abc ");
|
||||
// TODO: remove second parameter once we have optional parameters
|
||||
assert_eq!(JsValue::from(js.pad_end(10, &" ".into())), "abc ");
|
||||
assert_eq!(JsValue::from(js.pad_end(10, &"foo".into())), "abcfoofoof");
|
||||
assert_eq!(JsValue::from(js.pad_end(6, &"123456".into())), "abc123");
|
||||
assert_eq!(JsValue::from(js.pad_end(10, " ")), "abc ");
|
||||
assert_eq!(JsValue::from(js.pad_end(10, "foo")), "abcfoofoof");
|
||||
assert_eq!(JsValue::from(js.pad_end(6, "123456")), "abc123");
|
||||
// TODO: remove second parameter once we have optional parameters
|
||||
assert_eq!(JsValue::from(js.pad_end(1, &" ".into())), "abc");
|
||||
assert_eq!(JsValue::from(js.pad_end(1, " ")), "abc");
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
@ -138,12 +138,12 @@ fn pad_start() {
|
||||
let js = JsString::from("abc");
|
||||
|
||||
// TODO: remove second parameter once we have optional parameters
|
||||
assert_eq!(js.pad_start(10, &" ".into()), " abc");
|
||||
assert_eq!(js.pad_start(10, &"foo".into()), "foofoofabc");
|
||||
assert_eq!(js.pad_start(6, &"123465".into()), "123abc");
|
||||
assert_eq!(js.pad_start(8, &"0".into()), "00000abc");
|
||||
assert_eq!(js.pad_start(10, " "), " abc");
|
||||
assert_eq!(js.pad_start(10, "foo"), "foofoofabc");
|
||||
assert_eq!(js.pad_start(6, "123465"), "123abc");
|
||||
assert_eq!(js.pad_start(8, "0"), "00000abc");
|
||||
// TODO: remove second parameter once we have optional parameters
|
||||
assert_eq!(js.pad_start(1, &" ".into()), "abc");
|
||||
assert_eq!(js.pad_start(1, " "), "abc");
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
@ -162,9 +162,9 @@ fn starts_with() {
|
||||
let js = JsString::from("To be, or not to be, that is the question.");
|
||||
|
||||
// TODO: remove second parameter for both assertions once we have optional parameters
|
||||
assert!(js.starts_with(&"To be".into(), 0));
|
||||
assert!(!js.starts_with(&"not to be".into(), 0));
|
||||
assert!(js.starts_with(&"not to be".into(), 10));
|
||||
assert!(js.starts_with("To be", 0));
|
||||
assert!(!js.starts_with("not to be", 0));
|
||||
assert!(js.starts_with("not to be", 10));
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
|
@ -74,19 +74,19 @@ fn to_string_tag() {
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn for_() {
|
||||
let foo = JsValue::from(Symbol::for_(&"foo".into()));
|
||||
let bar = JsValue::from(Symbol::for_(&"bar".into()));
|
||||
let foo = JsValue::from(Symbol::for_("foo"));
|
||||
let bar = JsValue::from(Symbol::for_("bar"));
|
||||
assert_eq!(foo, foo);
|
||||
assert_eq!(bar, bar);
|
||||
assert_ne!(foo, bar);
|
||||
assert_ne!(bar, foo);
|
||||
|
||||
assert_eq!(Symbol::for_(&"mario".into()).to_string(), "Symbol(mario)");
|
||||
assert_eq!(Symbol::for_("mario").to_string(), "Symbol(mario)");
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn key_for() {
|
||||
let sym = Symbol::for_(&"foo".into());
|
||||
let sym = Symbol::for_("foo");
|
||||
assert_eq!(Symbol::key_for(&sym), "foo");
|
||||
assert!(Symbol::key_for(&Symbol::iterator()).is_undefined());
|
||||
assert!(Symbol::key_for(&gensym(JsValue::undefined())).is_undefined());
|
||||
@ -95,13 +95,13 @@ fn key_for() {
|
||||
#[wasm_bindgen_test]
|
||||
fn to_string() {
|
||||
assert_eq!(Symbol::iterator().to_string(), "Symbol(Symbol.iterator)");
|
||||
assert_eq!(Symbol::for_(&"foo".into()).to_string(), "Symbol(foo)");
|
||||
assert_eq!(Symbol::for_("foo").to_string(), "Symbol(foo)");
|
||||
assert_eq!(gensym("desc".into()).to_string(), "Symbol(desc)");
|
||||
}
|
||||
|
||||
#[wasm_bindgen_test]
|
||||
fn value_of() {
|
||||
let a = Symbol::for_(&"foo".into());
|
||||
let a = Symbol::for_("foo");
|
||||
assert_eq!(JsValue::from(a.value_of()), JsValue::from(a));
|
||||
let a = gensym(JsValue::undefined());
|
||||
assert_eq!(JsValue::from(a.value_of()), JsValue::from(a));
|
||||
|
Reference in New Issue
Block a user