| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
#[path = "harness/parity.rs"] |
| 13 |
mod parity; |
| 14 |
|
| 15 |
use parity::Parity; |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#[test] |
| 20 |
fn attribute_order_is_not_a_difference() { |
| 21 |
Parity::strict().assert( |
| 22 |
"t", |
| 23 |
r#"<div id="a" class="card" data-x="1"></div>"#, |
| 24 |
r#"<div data-x="1" id="a" class="card"></div>"#, |
| 25 |
); |
| 26 |
} |
| 27 |
|
| 28 |
#[test] |
| 29 |
fn class_order_is_not_a_difference() { |
| 30 |
|
| 31 |
|
| 32 |
Parity::strict().assert( |
| 33 |
"t", |
| 34 |
r#"<div class="card is-selected raised"></div>"#, |
| 35 |
r#"<div class="raised card is-selected"></div>"#, |
| 36 |
); |
| 37 |
} |
| 38 |
|
| 39 |
#[test] |
| 40 |
fn whitespace_between_tags_collapses() { |
| 41 |
Parity::strict().assert( |
| 42 |
"t", |
| 43 |
"<ul>\n <li>one</li>\n <li>two</li>\n</ul>", |
| 44 |
"<ul><li>one</li><li>two</li></ul>", |
| 45 |
); |
| 46 |
} |
| 47 |
|
| 48 |
#[test] |
| 49 |
fn runs_of_whitespace_inside_text_collapse_to_one_space() { |
| 50 |
Parity::strict().assert("t", "<p>one two\n\tthree</p>", "<p>one two three</p>"); |
| 51 |
} |
| 52 |
|
| 53 |
#[test] |
| 54 |
fn comments_are_not_a_difference() { |
| 55 |
Parity::strict().assert( |
| 56 |
"t", |
| 57 |
"<div><!-- explains the next line --><span>x</span></div>", |
| 58 |
"<div><span>x</span></div>", |
| 59 |
); |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
#[test] |
| 65 |
#[should_panic(expected = "does not render the same page")] |
| 66 |
fn a_changed_attribute_value_fails() { |
| 67 |
Parity::strict().assert("t", r#"<a href="/a">x</a>"#, r#"<a href="/b">x</a>"#); |
| 68 |
} |
| 69 |
|
| 70 |
#[test] |
| 71 |
#[should_panic(expected = "does not render the same page")] |
| 72 |
fn a_dropped_class_fails() { |
| 73 |
Parity::strict().assert( |
| 74 |
"t", |
| 75 |
r#"<div class="card raised"></div>"#, |
| 76 |
r#"<div class="card"></div>"#, |
| 77 |
); |
| 78 |
} |
| 79 |
|
| 80 |
#[test] |
| 81 |
#[should_panic(expected = "does not render the same page")] |
| 82 |
fn changed_text_fails() { |
| 83 |
Parity::strict().assert("t", "<p>Saved.</p>", "<p>Saved</p>"); |
| 84 |
} |
| 85 |
|
| 86 |
#[test] |
| 87 |
#[should_panic(expected = "does not render the same page")] |
| 88 |
fn different_nesting_fails() { |
| 89 |
|
| 90 |
|
| 91 |
Parity::strict().assert( |
| 92 |
"t", |
| 93 |
"<div><section><p>x</p></section></div>", |
| 94 |
"<div><section></section><p>x</p></div>", |
| 95 |
); |
| 96 |
} |
| 97 |
|
| 98 |
#[test] |
| 99 |
#[should_panic(expected = "does not render the same page")] |
| 100 |
fn whitespace_inside_pre_is_content_and_still_compares() { |
| 101 |
Parity::strict().assert("t", "<pre>one two</pre>", "<pre>one two</pre>"); |
| 102 |
} |
| 103 |
|
| 104 |
#[test] |
| 105 |
#[should_panic(expected = "does not render the same page")] |
| 106 |
fn a_missing_doctype_fails() { |
| 107 |
|
| 108 |
Parity::strict().assert("t", "<!doctype html><html></html>", "<html></html>"); |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
#[test] |
| 114 |
fn a_named_attribute_can_be_forgiven() { |
| 115 |
|
| 116 |
|
| 117 |
Parity::strict().ignoring_attr("data-action").assert( |
| 118 |
"t", |
| 119 |
r#"<button data-action="toggleCart" data-arg="7">Buy</button>"#, |
| 120 |
r#"<button data-arg="7">Buy</button>"#, |
| 121 |
); |
| 122 |
} |
| 123 |
|
| 124 |
#[test] |
| 125 |
#[should_panic(expected = "does not render the same page")] |
| 126 |
fn forgiving_one_attribute_does_not_forgive_its_neighbours() { |
| 127 |
Parity::strict().ignoring_attr("data-action").assert( |
| 128 |
"t", |
| 129 |
r#"<button data-action="toggleCart" data-arg="7">Buy</button>"#, |
| 130 |
r#"<button data-action="toggleCart">Buy</button>"#, |
| 131 |
); |
| 132 |
} |
| 133 |
|
| 134 |
#[test] |
| 135 |
fn a_named_class_can_be_forgiven() { |
| 136 |
Parity::strict().ignoring_class("raised").assert( |
| 137 |
"t", |
| 138 |
r#"<div class="card"></div>"#, |
| 139 |
r#"<div class="card raised"></div>"#, |
| 140 |
); |
| 141 |
} |
| 142 |
|
| 143 |
#[test] |
| 144 |
fn a_class_attribute_emptied_by_the_allowlist_matches_having_none() { |
| 145 |
Parity::strict().ignoring_class("raised").assert( |
| 146 |
"t", |
| 147 |
"<div></div>", |
| 148 |
r#"<div class="raised"></div>"#, |
| 149 |
); |
| 150 |
} |
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
#[test] |
| 155 |
fn the_failure_names_the_screen_and_shows_both_sides() { |
| 156 |
let err = std::panic::catch_unwind(|| { |
| 157 |
Parity::strict().assert("item_pricing", "<p>a</p>", "<p>b</p>"); |
| 158 |
}) |
| 159 |
.expect_err("it fails"); |
| 160 |
let msg = err |
| 161 |
.downcast_ref::<String>() |
| 162 |
.expect("the panic carries a message"); |
| 163 |
|
| 164 |
assert!(msg.contains("item_pricing"), "names the screen: {msg}"); |
| 165 |
assert!(msg.contains("Askama"), "shows the Askama side: {msg}"); |
| 166 |
assert!(msg.contains("quasi"), "shows the quasi side: {msg}"); |
| 167 |
assert!( |
| 168 |
msg.contains("ignoring_attr"), |
| 169 |
"says what to do about an intended difference: {msg}" |
| 170 |
); |
| 171 |
} |
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|