Skip to content

Commit

Permalink
tests/: renamed test document functions
Browse files Browse the repository at this point in the history
  • Loading branch information
niklak committed Oct 7, 2024
1 parent 73e241b commit 2db01dd
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 21 deletions.
File renamed without changes.
6 changes: 3 additions & 3 deletions tests/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ pub fn doc() -> Document {
include_str!("../test-pages/page.html").into()
}

pub fn docwiki() -> Document {
pub fn doc_wiki() -> Document {
include_str!("../test-pages/rustwiki.html").into()
}

pub fn doc2() -> Document {
include_str!("../test-pages/page2.html").into()
pub fn doc_with_siblings() -> Document {
include_str!("../test-pages/tests_with_siblings.html").into()
}
1 change: 1 addition & 0 deletions tests/html-dom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ fn parse_and_serialize(input: StrTendril) -> StrTendril {
serialize(&mut result, &inner, Default::default()).unwrap();
StrTendril::try_from_byte_slice(&result).unwrap()
}

macro_rules! test_fn {
($f:ident, $name:ident, $input:expr, $output:expr) => {
#[test]
Expand Down
12 changes: 6 additions & 6 deletions tests/selection-manipulation.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
mod data;

use data::doc2;
use data::doc_with_siblings;

#[test]
fn test_replace_with_html() {
let doc = doc2();
let doc = doc_with_siblings();

println!("{}", doc.html());

Expand All @@ -20,7 +20,7 @@ fn test_replace_with_html() {

#[test]
fn test_set_html() {
let doc = doc2();
let doc = doc_with_siblings();
let mut q = doc.select("#main, #foot");
q.set_html(r#"<div id="replace">test</div>"#);

Expand All @@ -33,15 +33,15 @@ fn test_set_html() {

#[test]
fn test_set_html_no_match() {
let doc = doc2();
let doc = doc_with_siblings();
let mut q = doc.select("#notthere");
q.set_html(r#"<div id="replace">test</div>"#);
assert_eq!(doc.select("#replace").length(), 0);
}

#[test]
fn test_set_html_empty() {
let doc = doc2();
let doc = doc_with_siblings();
let mut q = doc.select("#main");
q.set_html("");
assert_eq!(doc.select("#main").length(), 1);
Expand All @@ -50,7 +50,7 @@ fn test_set_html_empty() {

#[test]
fn test_replace_with_selection() {
let doc = doc2();
let doc = doc_with_siblings();

let s1 = doc.select("#nf5");
let mut sel = doc.select("#nf6");
Expand Down
20 changes: 10 additions & 10 deletions tests/selection-property.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod data;

use data::doc;
use data::doc2;
use data::doc_with_siblings;

#[test]
fn test_attr_exists() {
Expand All @@ -26,7 +26,7 @@ fn test_attr_not_exist() {

#[test]
fn test_remove_attr() {
let doc = doc2();
let doc = doc_with_siblings();
let mut sel = doc.select("div");

sel.remove_attr("id");
Expand All @@ -36,7 +36,7 @@ fn test_remove_attr() {

#[test]
fn test_set_attr() {
let doc = doc2();
let doc = doc_with_siblings();
let mut sel = doc.select("#main");
sel.set_attr("id", "not-main");

Expand All @@ -46,7 +46,7 @@ fn test_set_attr() {

#[test]
fn test_set_attr2() {
let doc = doc2();
let doc = doc_with_siblings();
let mut sel = doc.select("#main");

sel.set_attr("foo", "bar");
Expand All @@ -65,7 +65,7 @@ fn test_text() {

#[test]
fn test_add_class() {
let doc = doc2();
let doc = doc_with_siblings();
let mut sel = doc.select("#main");

sel.add_class("main main main");
Expand All @@ -75,7 +75,7 @@ fn test_add_class() {

#[test]
fn test_add_class_similar() {
let doc = doc2();
let doc = doc_with_siblings();
let mut sel = doc.select("#nf5");

sel.add_class("odd");
Expand All @@ -87,7 +87,7 @@ fn test_add_class_similar() {

#[test]
fn test_add_empty_class() {
let doc = doc2();
let doc = doc_with_siblings();
let mut sel = doc.select("#main");

sel.add_class("");
Expand All @@ -96,7 +96,7 @@ fn test_add_empty_class() {

#[test]
fn test_add_classes() {
let doc = doc2();
let doc = doc_with_siblings();
let mut sel = doc.select("#main");

sel.add_class("a b");
Expand Down Expand Up @@ -127,7 +127,7 @@ fn has_class_not_first() {

#[test]
fn test_remove_class() {
let doc = doc2();
let doc = doc_with_siblings();
let mut sel = doc.select("#nf1");
sel.remove_class("one row");

Expand All @@ -138,7 +138,7 @@ fn test_remove_class() {

#[test]
fn test_remove_class_similar() {
let doc = doc2();
let doc = doc_with_siblings();
let mut sel = doc.select("#nf5, #nf6");
assert_eq!(sel.length(), 2);

Expand Down
4 changes: 2 additions & 2 deletions tests/selection-traversal.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod data;

use data::doc;
use data::docwiki;
use data::doc_wiki;
use dom_query::Document;

#[test]
Expand All @@ -28,7 +28,7 @@ fn test_select_invalid() {

#[test]
fn test_select_big() {
let doc = docwiki();
let doc = doc_wiki();
let sel = doc.select("li");
assert_eq!(sel.length(), 420);
let sel = doc.select("span");
Expand Down

0 comments on commit 2db01dd

Please sign in to comment.