2018-06-09 02:46:51 +03:00
|
|
|
// Keep these tests in alphabetical order, just like the imports in `src/js.rs`.
|
|
|
|
|
|
|
|
use super::project;
|
|
|
|
|
2018-06-21 00:16:57 +03:00
|
|
|
mod Array;
|
2018-06-22 00:00:02 +03:00
|
|
|
mod ArrayIterator;
|
2018-06-27 10:07:47 +03:00
|
|
|
mod Boolean;
|
2018-06-26 20:25:26 +03:00
|
|
|
mod Date;
|
2018-06-29 16:46:27 +03:00
|
|
|
mod Error;
|
2018-07-01 15:53:44 +03:00
|
|
|
mod Function;
|
2018-06-23 03:51:44 +03:00
|
|
|
mod JsString;
|
2018-06-28 22:51:39 +03:00
|
|
|
mod Map;
|
2018-06-28 22:58:34 +03:00
|
|
|
mod MapIterator;
|
2018-06-25 22:41:28 +03:00
|
|
|
mod Math;
|
2018-06-26 20:25:26 +03:00
|
|
|
mod Number;
|
|
|
|
mod Object;
|
2018-06-28 23:57:49 +03:00
|
|
|
mod Set;
|
|
|
|
mod SetIterator;
|
2018-06-26 07:34:17 +03:00
|
|
|
mod TypedArray;
|
2018-06-28 08:42:34 +03:00
|
|
|
mod WeakMap;
|
|
|
|
mod WeakSet;
|
2018-06-19 20:15:09 +03:00
|
|
|
|
2018-06-09 02:46:51 +03:00
|
|
|
#[test]
|
|
|
|
#[cfg(feature = "std")]
|
|
|
|
fn decode_uri() {
|
|
|
|
project()
|
2018-06-28 08:42:34 +03:00
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2018-06-09 02:46:51 +03:00
|
|
|
#![feature(proc_macro, wasm_custom_section)]
|
|
|
|
|
|
|
|
extern crate wasm_bindgen;
|
|
|
|
use wasm_bindgen::prelude::*;
|
|
|
|
use wasm_bindgen::js;
|
|
|
|
|
|
|
|
#[wasm_bindgen]
|
|
|
|
pub fn test() {
|
|
|
|
let x = js::decode_uri("https://mozilla.org/?x=%D1%88%D0%B5%D0%BB%D0%BB%D1%8B")
|
|
|
|
.ok()
|
|
|
|
.expect("should decode URI OK");
|
2018-06-24 02:59:49 +03:00
|
|
|
assert_eq!(String::from(x), "https://mozilla.org/?x=шеллы");
|
2018-06-09 02:46:51 +03:00
|
|
|
|
|
|
|
assert!(js::decode_uri("%E0%A4%A").is_err());
|
|
|
|
}
|
2018-06-28 08:42:34 +03:00
|
|
|
"#,
|
|
|
|
)
|
2018-06-09 02:46:51 +03:00
|
|
|
.test();
|
|
|
|
}
|
|
|
|
|
2018-07-01 15:53:44 +03:00
|
|
|
#[test]
|
|
|
|
fn decode_uri_component() {
|
|
|
|
project()
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
|
|
|
#![feature(proc_macro, wasm_custom_section)]
|
|
|
|
|
|
|
|
extern crate wasm_bindgen;
|
|
|
|
use wasm_bindgen::prelude::*;
|
|
|
|
use wasm_bindgen::js;
|
|
|
|
|
|
|
|
#[wasm_bindgen]
|
|
|
|
pub fn test() {
|
|
|
|
let x = js::decode_uri_component("%3Fx%3Dtest")
|
|
|
|
.ok()
|
|
|
|
.expect("should decode URI OK");
|
|
|
|
assert_eq!(String::from(x), "?x=test");
|
|
|
|
|
|
|
|
assert!(js::decode_uri_component("%E0%A4%A").is_err());
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.test();
|
|
|
|
}
|
|
|
|
|
2018-06-09 02:46:51 +03:00
|
|
|
#[test]
|
|
|
|
#[cfg(feature = "std")]
|
|
|
|
fn encode_uri() {
|
|
|
|
project()
|
2018-06-28 08:42:34 +03:00
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2018-06-09 02:46:51 +03:00
|
|
|
#![feature(proc_macro, wasm_custom_section)]
|
|
|
|
|
|
|
|
extern crate wasm_bindgen;
|
|
|
|
use wasm_bindgen::prelude::*;
|
|
|
|
use wasm_bindgen::js;
|
|
|
|
|
|
|
|
#[wasm_bindgen]
|
|
|
|
pub fn test() {
|
|
|
|
let x = js::encode_uri("ABC abc 123");
|
2018-06-24 02:59:49 +03:00
|
|
|
assert_eq!(String::from(x), "ABC%20abc%20123");
|
2018-06-09 02:46:51 +03:00
|
|
|
}
|
2018-06-28 08:42:34 +03:00
|
|
|
"#,
|
|
|
|
)
|
2018-06-09 02:46:51 +03:00
|
|
|
.test();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn eval() {
|
|
|
|
project()
|
2018-06-28 08:42:34 +03:00
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
2018-06-09 02:46:51 +03:00
|
|
|
#![feature(proc_macro, wasm_custom_section)]
|
|
|
|
|
|
|
|
extern crate wasm_bindgen;
|
|
|
|
use wasm_bindgen::prelude::*;
|
|
|
|
use wasm_bindgen::js;
|
|
|
|
|
|
|
|
#[wasm_bindgen]
|
|
|
|
pub fn test() {
|
|
|
|
let x = js::eval("42").ok().expect("should eval OK");
|
|
|
|
assert_eq!(x.as_f64().unwrap(), 42.0);
|
|
|
|
|
|
|
|
let err = js::eval("(function () { throw 42; }())")
|
|
|
|
.err()
|
|
|
|
.expect("eval should throw");
|
|
|
|
assert_eq!(err.as_f64().unwrap(), 42.0);
|
|
|
|
}
|
2018-06-28 08:42:34 +03:00
|
|
|
"#,
|
|
|
|
)
|
2018-06-09 02:46:51 +03:00
|
|
|
.test();
|
|
|
|
}
|