diff --git a/Cargo.lock b/Cargo.lock index a0c9ab5..aa9d77b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,7 +4,7 @@ version = 3 [[package]] name = "accessibility-rs" -version = "0.0.58" +version = "0.0.59" dependencies = [ "accessibility-scraper", "accessibility-tree", @@ -31,7 +31,7 @@ dependencies = [ [[package]] name = "accessibility-scraper" -version = "0.0.9" +version = "0.0.11" dependencies = [ "ahash", "cssparser", @@ -49,7 +49,7 @@ dependencies = [ [[package]] name = "accessibility-tree" -version = "0.0.10" +version = "0.0.11" dependencies = [ "accessibility-scraper", "atomic_refcell", @@ -134,9 +134,9 @@ checksum = "41e67cd8309bbd06cd603a9e693a784ac2e5d1e955f11286e355089fcab3047c" [[package]] name = "autocfg" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" [[package]] name = "backtrace" @@ -249,9 +249,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.3" +version = "4.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "949626d00e063efc93b6dca932419ceb5432f99769911c0b995f7e884c778813" +checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0" dependencies = [ "clap_builder", ] diff --git a/README.md b/README.md index 6a45b06..84cb65d 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ The Rust web accessibility engine. ```toml [dependencies] -accessibility-rs = "^0.0.58" +accessibility-rs = "^0.0.59" ``` ```rs @@ -32,11 +32,12 @@ With the Tokio runtime. ```toml [dependencies] -accessibility-rs = { version = "^0.0.58", features = ["tokio"]} +accessibility-rs = { version = "^0.0.59", features = ["tokio"]} ``` ```rs use accessibility_rs::{audit, AuditConfig}; +use tokio; #[tokio::main] async fn main() { @@ -72,11 +73,11 @@ async fn main() { ```sh audit-speed/core/audit: small html (4k iterations) -time: [60.988 µs 61.067 µs 61.157 µs] +time: [55.689 µs 56.246 µs 57.110 µs] audit-speed/core/audit: medium html (4k iterations) -time: [890.56 µs 905.52 µs 923.23 µs] +time: [824.07 µs 830.30 µs 839.37 µs] audit-speed/core/audit: large html (4k iterations) -time: [1.1316 ms 1.1101 ms 1.1478 ms] +time: [1.1206 ms 1.1260 ms 1.1321 ms] ``` ## Examples diff --git a/accessibility-rs/Cargo.toml b/accessibility-rs/Cargo.toml index fed5237..3ad1651 100644 --- a/accessibility-rs/Cargo.toml +++ b/accessibility-rs/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "accessibility-rs" -version = "0.0.58" +version = "0.0.59" authors = ["The A11yWatch Project Developers", "Jeff Mendez "] edition = "2021" license = "MIT OR Apache-2.0" @@ -12,8 +12,8 @@ include = ["/src", "../LICENSE_MIT", "../LICENSE_APACHE", "../README.md", "local [dependencies] lazy_static = { workspace = true } -accessibility-scraper = { version = "0.0.9", features = ["main"], default-features = false, path = "../accessibility-scraper" } -accessibility-tree = { version = "0.0.10", path = "../accessibility-tree/victor" } +accessibility-scraper = { version = "0.0.11", features = ["main"], default-features = false, path = "../accessibility-scraper" } +accessibility-tree = { version = "0.0.11", path = "../accessibility-tree/victor" } getrandom = { version = "0.2", features = ["js"] } taffy = { version = "0.4.0" } serde = { version = "1.0", features = ["derive"] } diff --git a/accessibility-rs/src/engine/audit/wcag.rs b/accessibility-rs/src/engine/audit/wcag.rs index 37b1942..e5d1226 100644 --- a/accessibility-rs/src/engine/audit/wcag.rs +++ b/accessibility-rs/src/engine/audit/wcag.rs @@ -93,7 +93,7 @@ impl WCAGAAA { } /// Audit html against WCAGAAA standards - #[cfg(feature = "rayon")] + #[cfg(all(feature = "rayon", not(feature = "tokio")))] pub fn audit(auditor: (Auditor<'_>, Option)) -> Vec { use crate::engine::audit::audit_utils::evaluate_rules_in_parallel; @@ -121,7 +121,7 @@ impl WCAGAAA { } /// Audit html against WCAGAAA standards - #[cfg(all(not(feature = "rayon"), feature = "tokio"))] + #[cfg(feature = "tokio")] pub async fn audit(auditor: (Auditor<'_>, Option)) -> Vec { WCAGAAA::run_audit(auditor).await } diff --git a/accessibility-rs/src/lib.rs b/accessibility-rs/src/lib.rs index 814c484..3a1c74a 100644 --- a/accessibility-rs/src/lib.rs +++ b/accessibility-rs/src/lib.rs @@ -23,11 +23,20 @@ //! ```no_run //! use accessibility_rs::{audit, AuditConfig}; //! +//! #[cfg(not(feature = "tokio"))] //! fn main() { //! let config = AuditConfig::basic(r###"

My Title

"###); //! let audit = audit(config); //! println!("{:?}", audit); //! } +//! +//! #[cfg(feature = "tokio")] +//! #[tokio::main] +//! async fn main() { +//! let config = AuditConfig::basic(r###"

My Title

"###); +//! let audit = audit(config).await; +//! println!("{:?}", audit); +//! } //! ``` //! diff --git a/accessibility-rs/tests/unit/anchor.rs b/accessibility-rs/tests/unit/anchor.rs index 588b567..5cb9360 100644 --- a/accessibility-rs/tests/unit/anchor.rs +++ b/accessibility-rs/tests/unit/anchor.rs @@ -4,6 +4,7 @@ use accessibility_rs::AuditConfig; use maud::html; #[test] +#[cfg(not(feature = "tokio"))] /// anchor contains single img element without alt fn _audit_missing_alt_anchor_img() { let audit = accessibility_rs::audit(AuditConfig::basic( @@ -26,6 +27,7 @@ fn _audit_missing_alt_anchor_img() { } #[test] +#[cfg(not(feature = "tokio"))] /// anchor contains valid href with no content fn _audit_missing_anchor_content_valid_href() { let markup = html! { @@ -40,6 +42,7 @@ fn _audit_missing_anchor_content_valid_href() { } #[test] +#[cfg(not(feature = "tokio"))] /// anchor is empty void fn _audit_missing_anchor_content() { let markup = html! { @@ -54,6 +57,7 @@ fn _audit_missing_anchor_content() { } #[test] +#[cfg(not(feature = "tokio"))] /// anchor text matches img alt fn _audit_img_alt_matches_text_anchor() { let audit = accessibility_rs::audit(AuditConfig::basic( diff --git a/accessibility-rs/tests/unit/applet.rs b/accessibility-rs/tests/unit/applet.rs index 3e65b7d..a249fa1 100644 --- a/accessibility-rs/tests/unit/applet.rs +++ b/accessibility-rs/tests/unit/applet.rs @@ -3,6 +3,7 @@ use accessibility_rs::AuditConfig; #[test] +#[cfg(not(feature = "tokio"))] /// missing applet alt fn _audit_missing_applet_alt() { let audit = accessibility_rs::audit(AuditConfig::basic( @@ -30,6 +31,7 @@ fn _audit_missing_applet_alt() { } #[test] +#[cfg(not(feature = "tokio"))] /// missing applet body fn _audit_missing_applet_body() { let audit = accessibility_rs::audit(AuditConfig::basic( diff --git a/accessibility-rs/tests/unit/area.rs b/accessibility-rs/tests/unit/area.rs index 435ddd7..ea90eef 100644 --- a/accessibility-rs/tests/unit/area.rs +++ b/accessibility-rs/tests/unit/area.rs @@ -3,6 +3,7 @@ use accessibility_rs::AuditConfig; #[test] +#[cfg(not(feature = "tokio"))] fn _audit_missing_alt_area() { //alt attribute missing on first tag let html = r#" @@ -23,6 +24,7 @@ fn _audit_missing_alt_area() { } #[test] +#[cfg(not(feature = "tokio"))] fn _audit_missing_alt_map() { // alt attribute missing on tag let html = r#" diff --git a/accessibility-rs/tests/unit/contrast.rs b/accessibility-rs/tests/unit/contrast.rs index 020a7c5..8c879f6 100644 --- a/accessibility-rs/tests/unit/contrast.rs +++ b/accessibility-rs/tests/unit/contrast.rs @@ -4,6 +4,7 @@ use accessibility_rs::AuditConfig; use maud::html; #[test] +#[cfg(not(feature = "tokio"))] /// anchor has valid contrast. fn _audit_contrast_text_anchor() { let markup = html! { diff --git a/accessibility-rs/tests/unit/fieldset.rs b/accessibility-rs/tests/unit/fieldset.rs index c52acb3..fc8d367 100644 --- a/accessibility-rs/tests/unit/fieldset.rs +++ b/accessibility-rs/tests/unit/fieldset.rs @@ -4,6 +4,7 @@ use accessibility_rs::AuditConfig; use maud::html; #[test] +#[cfg(not(feature = "tokio"))] /// anchor contains single img element without alt fn _audit_missing_fieldset_legend() { let m = html! { diff --git a/accessibility-rs/tests/unit/heading.rs b/accessibility-rs/tests/unit/heading.rs index a848bfa..23569ef 100644 --- a/accessibility-rs/tests/unit/heading.rs +++ b/accessibility-rs/tests/unit/heading.rs @@ -3,6 +3,7 @@ use accessibility_rs::AuditConfig; #[test] +#[cfg(not(feature = "tokio"))] /// empty headings fn _audit_headings_empty() { let audit = accessibility_rs::audit(AuditConfig::basic( diff --git a/accessibility-rs/tests/unit/img.rs b/accessibility-rs/tests/unit/img.rs index cf51436..59e5cf0 100644 --- a/accessibility-rs/tests/unit/img.rs +++ b/accessibility-rs/tests/unit/img.rs @@ -2,6 +2,7 @@ use accessibility_rs::AuditConfig; #[test] +#[cfg(not(feature = "tokio"))] /// img is missing an alt fn _audit_img_missing_alt() { let audit = accessibility_rs::audit(AuditConfig::basic( @@ -27,6 +28,7 @@ fn _audit_img_missing_alt() { } #[test] +#[cfg(not(feature = "tokio"))] /// img is missing an alt fn _audit_form_submit_img_missing_alt() { let audit = accessibility_rs::audit(AuditConfig::basic( @@ -55,6 +57,7 @@ fn _audit_form_submit_img_missing_alt() { } #[test] +#[cfg(not(feature = "tokio"))] /// img has empty alt and title fn _audit_form_submit_img_has_alt_and_title() { let audit = accessibility_rs::audit(AuditConfig::basic( diff --git a/accessibility-rs/tests/unit/input.rs b/accessibility-rs/tests/unit/input.rs index cea9249..2d8bf39 100644 --- a/accessibility-rs/tests/unit/input.rs +++ b/accessibility-rs/tests/unit/input.rs @@ -2,6 +2,7 @@ use accessibility_rs::AuditConfig; #[test] +#[cfg(not(feature = "tokio"))] /// input is missing a valid name fn _audit_input_valid_name() { let audit = accessibility_rs::audit(AuditConfig::basic( diff --git a/accessibility-rs/tests/unit/label.rs b/accessibility-rs/tests/unit/label.rs index d4a86f6..0f140cd 100644 --- a/accessibility-rs/tests/unit/label.rs +++ b/accessibility-rs/tests/unit/label.rs @@ -3,6 +3,7 @@ use accessibility_rs::AuditConfig; use maud::html; #[test] +#[cfg(not(feature = "tokio"))] /// label needs unique target ids fn _audit_label_valid_name() { let markup = html! { @@ -21,6 +22,7 @@ fn _audit_label_valid_name() { } #[test] +#[cfg(not(feature = "tokio"))] /// label has id that does not exist fn _audit_label_id_noexist() { let markup = html! { diff --git a/accessibility-rs/tests/unit/meta.rs b/accessibility-rs/tests/unit/meta.rs index f8a7f3b..0947015 100644 --- a/accessibility-rs/tests/unit/meta.rs +++ b/accessibility-rs/tests/unit/meta.rs @@ -5,6 +5,7 @@ use accessibility_rs::AuditConfig; use crate::mocks::mock; #[test] +#[cfg(not(feature = "tokio"))] /// missing title element fn _audit_missing_title() { let audit = accessibility_rs::audit(AuditConfig::basic(mock::MOCK_WEBSITE_HTML)); @@ -21,6 +22,7 @@ fn _audit_missing_title() { } #[test] +#[cfg(not(feature = "tokio"))] /// meta refresh redirect fn _audit_meta_refresh() { let audit = accessibility_rs::audit(AuditConfig::basic( @@ -74,6 +76,7 @@ fn _audit_meta_refresh() { } #[test] +#[cfg(not(feature = "tokio"))] /// no blink elements fn _audit_blink_found() { let audit = accessibility_rs::audit(AuditConfig::basic( @@ -99,6 +102,7 @@ fn _audit_blink_found() { } #[test] +#[cfg(not(feature = "tokio"))] /// iframe missing title fn _iframe_missing_title() { let audit = accessibility_rs::audit(AuditConfig { @@ -192,6 +196,7 @@ fn _iframe_missing_title() { } #[test] +#[cfg(not(feature = "tokio"))] /// incorrect xml:lang fn _xml_lang_incorrect_format() { let audit = accessibility_rs::audit(AuditConfig::basic( diff --git a/accessibility-scraper/Cargo.toml b/accessibility-scraper/Cargo.toml index 834789d..5f71f94 100644 --- a/accessibility-scraper/Cargo.toml +++ b/accessibility-scraper/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "accessibility-scraper" -version = "0.0.9" +version = "0.0.11" edition = "2021" description = "HTML parsing and querying with CSS selectors with CSS binding styles to elements." keywords = ["html", "css", "selector", "scraping"] diff --git a/accessibility-scraper/examples/document.rs b/accessibility-scraper/examples/document.rs deleted file mode 100644 index 954f5a4..0000000 --- a/accessibility-scraper/examples/document.rs +++ /dev/null @@ -1,28 +0,0 @@ -extern crate accessibility_scraper; - -use std::io::{self, Read, Write}; - -use accessibility_scraper::{Html, Selector}; - -fn main() { - let mut input = String::new(); - let mut stdout = io::stdout(); - let mut stdin = io::stdin(); - - write!(stdout, "CSS selector: ").unwrap(); - stdout.flush().unwrap(); - stdin.read_line(&mut input).unwrap(); - let selector = Selector::parse(&input).unwrap(); - - writeln!(stdout, "HTML document:").unwrap(); - stdout.flush().unwrap(); - input.clear(); - stdin.read_to_string(&mut input).unwrap(); - let document = Html::parse_document(&input); - - println!("{:#?}", document); - - for node in document.select(&selector) { - println!("{:?}", node.value()); - } -} diff --git a/accessibility-scraper/examples/fragment.rs b/accessibility-scraper/examples/fragment.rs deleted file mode 100644 index ad00691..0000000 --- a/accessibility-scraper/examples/fragment.rs +++ /dev/null @@ -1,28 +0,0 @@ -extern crate accessibility_scraper; - -use std::io::{self, Read, Write}; - -use accessibility_scraper::{Html, Selector}; - -fn main() { - let mut input = String::new(); - let mut stdout = io::stdout(); - let mut stdin = io::stdin(); - - write!(stdout, "CSS selector: ").unwrap(); - stdout.flush().unwrap(); - stdin.read_line(&mut input).unwrap(); - let selector = Selector::parse(&input).unwrap(); - - writeln!(stdout, "HTML fragment:").unwrap(); - stdout.flush().unwrap(); - input.clear(); - stdin.read_to_string(&mut input).unwrap(); - let fragment = Html::parse_fragment(&input); - - println!("{:#?}", fragment); - - for node in fragment.select(&selector) { - println!("{:?}", node.value()); - } -} diff --git a/accessibility-scraper/src/html/mod.rs b/accessibility-scraper/src/html/mod.rs index 6ef2bd0..d28730b 100644 --- a/accessibility-scraper/src/html/mod.rs +++ b/accessibility-scraper/src/html/mod.rs @@ -62,17 +62,18 @@ impl Html { /// # extern crate html5ever; /// # extern crate accessibility_scraper; /// # extern crate tendril; - /// # fn main() { + /// use accessibility_scraper::html::Html; + /// use crate::tendril::TendrilSink; + /// #[tokio::main] + /// # async fn main() { /// # let document = ""; /// use tokio_stream::{self as stream, StreamExt}; - /// let mut doc = Self::new_document(); - /// doc.quirks_mode = QuirksMode::Quirks; - /// let mut parser = driver::parse_document(doc, Default::default()); + /// let mut parser = html5ever::driver::parse_document(Html::new_document(), Default::default()); /// let mut stream = stream::iter(document.lines()); /// while let Some(item) = stream.next().await { /// parser.process(item.into()) /// } - /// parser.finish() + /// parser.finish(); /// # } /// ``` #[cfg(feature = "tokio")] diff --git a/accessibility-tree/victor/Cargo.toml b/accessibility-tree/victor/Cargo.toml index f9aeec8..51275d6 100644 --- a/accessibility-tree/victor/Cargo.toml +++ b/accessibility-tree/victor/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "accessibility-tree" -version = "0.0.10" +version = "0.0.11" authors = ["Jeff Mendez