| 1 |
use wasm_bindgen::prelude::*; |
| 2 |
use wasm_bindgen_test::*; |
| 3 |
|
| 4 |
#[wasm_bindgen(module = "/tests/wasm/link_to.js")] |
| 5 |
extern "C" { |
| 6 |
#[wasm_bindgen(catch)] |
| 7 |
fn read_file(url: &str) -> Result<String, JsValue>; |
| 8 |
} |
| 9 |
|
| 10 |
#[wasm_bindgen_test] |
| 11 |
fn test_module() { |
| 12 |
let link = wasm_bindgen::link_to!(module = "/tests/wasm/linked_module.js"); |
| 13 |
assert_eq!(read_file(&link).unwrap(), "// linked module\n"); |
| 14 |
} |
| 15 |
|
| 16 |
#[wasm_bindgen_test] |
| 17 |
fn test_raw_module() { |
| 18 |
let link = wasm_bindgen::link_to!(raw_module = "./not-found.js"); |
| 19 |
assert!(read_file(&link).is_err()); |
| 20 |
} |
| 21 |
|
| 22 |
#[wasm_bindgen_test] |
| 23 |
fn test_inline_js() { |
| 24 |
// Test two invocations to ensure that snippet indices from different |
| 25 |
// Program structs are offset correctly. |
| 26 |
let link1 = wasm_bindgen::link_to!(inline_js = "// inline js 1\n"); |
| 27 |
let link2 = wasm_bindgen::link_to!(inline_js = "// inline js 2\n"); |
| 28 |
assert_eq!(read_file(&link1).unwrap(), "// inline js 1\n"); |
| 29 |
assert_eq!(read_file(&link2).unwrap(), "// inline js 2\n"); |
| 30 |
} |