Add bindings for String.from_char_code

This commit is contained in:
Danielle Pham
2018-08-12 23:16:35 -04:00
parent aa735d221a
commit fd5958b51b
2 changed files with 41 additions and 0 deletions

View File

@ -58,6 +58,19 @@ fn ends_with() {
assert_eq!(js.ends_with("to be", 19), true);
}
#[wasm_bindgen_test]
fn from_char_code() {
let s = "½+¾=";
let codes : Vec<f64> = s.chars()
.map(|char| char as u32 as f64)
.collect();
assert_eq!(JsString::from_char_code1(codes[0]), "½");
assert_eq!(JsString::from_char_code2(codes[0], codes[1]), "½+");
assert_eq!(JsString::from_char_code3(codes[0], codes[1], codes[2]), "½+¾");
assert_eq!(JsString::from_char_code4(codes[0], codes[1], codes[2], codes[3]), "½+¾=");
}
#[wasm_bindgen_test]
fn includes() {
let str = JsString::from("Blue Whale");