mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-11-24 14:42:35 +03:00
Merge pull request #585 from twilco/master
Add web_sys binding for XPathResult
This commit is contained in:
commit
c975895c98
@ -80,6 +80,7 @@ mod history;
|
||||
web_sys::HtmlMenuElement,
|
||||
web_sys::HtmlSlotElement,
|
||||
*/
|
||||
mod xpath_result;
|
||||
|
||||
fn websys_project() -> Project {
|
||||
project()
|
||||
|
36
crates/web-sys/tests/all/xpath_result.rs
Normal file
36
crates/web-sys/tests/all/xpath_result.rs
Normal file
@ -0,0 +1,36 @@
|
||||
use super::websys_project;
|
||||
|
||||
#[test]
|
||||
fn xpath_result() {
|
||||
websys_project()
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
r#"
|
||||
#![feature(use_extern_macros)]
|
||||
extern crate wasm_bindgen;
|
||||
use wasm_bindgen::prelude::*;
|
||||
extern crate web_sys;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn test_xpath_result(xpath_result: &web_sys::XPathResult) {
|
||||
assert_eq!(xpath_result.result_type(), web_sys::XPathResult::UNORDERED_NODE_ITERATOR_TYPE);
|
||||
assert_eq!(xpath_result.invalid_iterator_state(), false);
|
||||
assert_eq!(xpath_result.iterate_next().unwrap().unwrap().text_content().unwrap(), "tomato");
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.js",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
export function test() {
|
||||
let xmlDoc = new DOMParser().parseFromString("<root><value>tomato</value></root>", "application/xml");
|
||||
let xpathResult = xmlDoc.evaluate("/root//value", xmlDoc, null, XPathResult.ANY_TYPE, null);
|
||||
wasm.test_xpath_result(xpathResult);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test();
|
||||
}
|
Loading…
Reference in New Issue
Block a user