Skip to content

Commit

Permalink
tests/selection-traversal.rs: try different approach for testing wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
niklak committed Oct 18, 2024
1 parent e9afed5 commit 8a026f1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 47 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: Install stable stab
- name: Install stable rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
Expand All @@ -29,4 +29,4 @@ jobs:
with:
tool: wasm-bindgen-cli
- name: Run tests
run: cargo test --target wasm32-unknown-unknown --verbose --all
run: cargo test --target wasm32-unknown-unknown --all
90 changes: 45 additions & 45 deletions tests/selection-traversal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,33 +22,33 @@ const DOC_WITH_LISTS: &str = r#"<!DOCTYPE html>
</html>"#;


#[test]
#[wasm_bindgen_test]
#[cfg_attr(not(target_arch = "wasm32"), test)]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn test_select() {
let doc = doc();
let sel = doc.select("div.row-fluid");
assert_eq!(sel.length(), 9);
}

#[test]
#[wasm_bindgen_test]
#[cfg_attr(not(target_arch = "wasm32"), test)]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn test_select_not_self() {
let doc = doc();
let sel = doc.select("h1").select("h1");
assert_eq!(sel.length(), 0);
}

#[test]
#[cfg_attr(not(target_arch = "wasm32"), test)]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
#[should_panic]
#[wasm_bindgen_test]
fn test_select_invalid() {
let doc = doc();
let sel = doc.select(":+ ^");
assert_eq!(sel.length(), 0);
}

#[test]
#[wasm_bindgen_test]
#[cfg_attr(not(target_arch = "wasm32"), test)]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn test_select_big() {
let doc = doc_wiki();
let sel = doc.select("li");
Expand All @@ -57,74 +57,73 @@ fn test_select_big() {
assert_eq!(sel.length(), 706);
}

#[test]
#[wasm_bindgen_test]
#[cfg_attr(not(target_arch = "wasm32"), test)]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn test_chained_select() {
let doc = doc();
let sel = doc.select("div.hero-unit").select(".row-fluid");
assert_eq!(sel.length(), 4);
}

#[test]
#[cfg_attr(not(target_arch = "wasm32"), test)]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
#[should_panic]
#[wasm_bindgen_test]

fn test_chained_select_invalid() {
let doc = doc();
let sel = doc.select("div.hero-unit").select("");
assert_eq!(sel.length(), 0);
}

#[test]
#[wasm_bindgen_test]
#[cfg_attr(not(target_arch = "wasm32"), test)]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn test_children() {
let doc = doc();
let sel = doc.select(".pvk-content").children();
assert_eq!(sel.length(), 5)
}

#[test]
#[wasm_bindgen_test]
#[cfg_attr(not(target_arch = "wasm32"), test)]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn test_parent() {
let doc = doc();
let sel = doc.select(".container-fluid").parent();
assert_eq!(sel.length(), 3)
}

#[test]
#[wasm_bindgen_test]
#[cfg_attr(not(target_arch = "wasm32"), test)]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn test_parent_body() {
let doc = doc();
let sel = doc.select("body").parent();
assert_eq!(sel.length(), 1)
}

#[test]
#[wasm_bindgen_test]
#[cfg_attr(not(target_arch = "wasm32"), test)]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn test_next() {
let doc = doc();
let sel = doc.select("h1").next_sibling();
assert_eq!(sel.length(), 1)
}

#[test]
#[wasm_bindgen_test]
#[cfg_attr(not(target_arch = "wasm32"), test)]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn test_next2() {
let doc = doc();
let sel = doc.select(".close").next_sibling();
assert_eq!(sel.length(), 1)
}

#[test]
#[wasm_bindgen_test]
#[cfg_attr(not(target_arch = "wasm32"), test)]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn test_next_none() {
let doc = doc();
let sel = doc.select("small").next_sibling();
assert_eq!(sel.length(), 0)
}

#[test]
#[wasm_bindgen_test]
#[cfg_attr(not(target_arch = "wasm32"), test)]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn test_nth_child() {
let doc: Document = r#"<!DOCTYPE html>
<html lang="en">
Expand Down Expand Up @@ -153,8 +152,8 @@ fn test_nth_child() {
assert!(a.length() == 1);
}

#[test]
#[wasm_bindgen_test]
#[cfg_attr(not(target_arch = "wasm32"), test)]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn test_doc_select_single() {
let doc: Document = DOC_WITH_LISTS.into();

Expand All @@ -164,8 +163,9 @@ fn test_doc_select_single() {
let multiple_selection_count = doc.select(".list").length();
assert_eq!(multiple_selection_count, 2);
}
#[test]
#[wasm_bindgen_test]

#[cfg_attr(not(target_arch = "wasm32"), test)]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn test_select_single() {
let doc: Document = DOC_WITH_LISTS.into();

Expand All @@ -176,16 +176,16 @@ fn test_select_single() {
assert_eq!(multiple_selection_count, 2);
}

#[test]
#[wasm_bindgen_test]
#[cfg_attr(not(target_arch = "wasm32"), test)]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn test_try_select_doc() {
let doc: Document = DOC_WITH_LISTS.into();
let selection = doc.try_select(".list");
assert!(selection.is_some());
}

#[test]
#[wasm_bindgen_test]
#[cfg_attr(not(target_arch = "wasm32"), test)]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn test_try_select_doc_none() {
let doc: Document = DOC_WITH_LISTS.into();
let selection = doc.try_select(".none");
Expand All @@ -195,8 +195,8 @@ fn test_try_select_doc_none() {
}
}

#[test]
#[wasm_bindgen_test]
#[cfg_attr(not(target_arch = "wasm32"), test)]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn test_try_select_selection() {
let doc: Document = DOC_WITH_LISTS.into();
let selection = doc
Expand All @@ -205,8 +205,8 @@ fn test_try_select_selection() {
assert!(selection.is_some());
}

#[test]
#[wasm_bindgen_test]
#[cfg_attr(not(target_arch = "wasm32"), test)]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn test_try_select_selection_none() {
let doc: Document = DOC_WITH_LISTS.into();
let selection = doc
Expand All @@ -218,16 +218,16 @@ fn test_try_select_selection_none() {
}
}

#[test]
#[wasm_bindgen_test]
#[cfg_attr(not(target_arch = "wasm32"), test)]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn test_try_select_invalid() {
let doc: Document = DOC_WITH_LISTS.into();
let selection = doc.try_select(":+ ^");
assert!(selection.is_none());
}

#[test]
#[wasm_bindgen_test]
#[cfg_attr(not(target_arch = "wasm32"), test)]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn test_handle_selection() {
let doc: Document = DOC_WITH_LISTS.into();

Expand All @@ -243,8 +243,8 @@ fn test_handle_selection() {
);
}

#[test]
#[wasm_bindgen_test]
#[cfg_attr(not(target_arch = "wasm32"), test)]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn test_doc_uppercase() {
let contents = DOC_WITH_LISTS.to_uppercase();
let doc: Document = contents.into();
Expand Down

0 comments on commit 8a026f1

Please sign in to comment.