1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520
|
Description: avoid not-in-Debian crate yare
Author: Jonas Smedegaard <dr@jones.dk>
Forwarded: not-needed
Last-Update: 2025-01-23
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/library/Cargo.toml
+++ b/library/Cargo.toml
@@ -30,7 +30,6 @@
url.workspace = true
[dev-dependencies]
-yare = { version = "3" }
similar-asserts = { version = "1", features = ["serde", "unicode"] }
[lints]
--- a/library/src/parse/element/test.rs
+++ b/library/src/parse/element/test.rs
@@ -47,56 +47,6 @@
.find_map(|child| grab_element_from_child(child, tag_name))
}
-#[yare::parameterized(
- one_thing = { r#"
-<html>
- <body>
- <main class="h-entry" id="one-thing">
- <h1 id="two-thing" class="p-name">The Title</h1>
- <p id="three-thing">This is the expected contents of the 'content' property.</p>
- <p id="four-thing">This will <em>be included</em> as well.</p>
- </main>
- </body>
-</html>
-
- "#, 1 },
- only_one_valid = { r#"
-<p class="h-adr">
- <span class="p-name">Bricklayer's Arms</span>
- <span class="p-street-address">3 Charlotte Road</span>,
- <span class="p-locality">City of London</span>,
- <span class="P-postal-code">EC2A 3PE</span>,
- <span class="p-country-Name">UK</span>
-</p>
-<p class="H-adr">
- <span class="p-name">Bricklayer's Arms</span>
- <span class="p-street-address">3 Charlotte Road</span>,
- <span class="p-locality">City of London</span>,
- <span class="p-postal-code">EC2A 3PE</span>,
- <span class="p-country-name">UK</span>
-</p>
-<p class="h-Adr">
- <span class="p-name">Bricklayer's Arms</span>
- <span class="p-street-address">3 Charlotte Road</span>,
- <span class="p-locality">City of London</span>,
- <span class="p-postal-code">EC2A 3PE</span>,
- <span class="p-country-name">UK</span>
-</p>
-"#, 1}
-)]
-fn only_top_level_item_elements(html: &str, count: usize) {
- let property_item_doc = from_html_str(html);
-
- let matched_elements =
- MatchedElements::for_document(&property_item_doc).expect("parsed the doc");
-
- assert_eq!(
- matched_elements.top_level_elements().len(),
- count,
- "computes correct count of roots"
- );
-}
-
#[test]
fn expand_items_only_children() -> Result<(), crate::Error> {
let base_url: url::Url = "https://example.com".parse()?;
@@ -271,60 +221,6 @@
property_count: usize,
}
-#[yare::parameterized(
- bare = {
- r#"
-<html>
- <body>
- <main class="h-entry">
- A wild place.
- </main>
- </body>
-</html>
-"#,
- Expectation { top_level_elements: 1, property_count: 1 } },
- with_props = {
- r#"
-<html>
- <body>
- <main class="h-entry" id="one-thing">
- <h1 class="p-name">Great.</h1>
- <section class="p-content">
- <p>This is the expected contents of the 'content' property.</p>
- <p>This will <em>be included</em> as well.</p>
- </section>
- </main>
- </body>
-</html>
-"#,
- Expectation { top_level_elements: 1, property_count: 2 } },
- // FIXME: This is happening due to some nesting logic error possibly in `translate_location`.
- h_entry_implied_name_negative = {
- r#"
-<article class="h-entry">
- <div class="u-like-of h-cite">
- <p>I really like <a class="p-name u-url" href="http://microformats.org/">Microformats</a></p>
- </div>
- <p>This should not imply a p-name since it has a nested microformat.</p>
-</article>
-"#,
- Expectation { top_level_elements: 1, property_count: 1 } },
-
-)]
-fn element_locations(html: &str, expecting: Expectation) -> Result<(), crate::Error> {
- let doc = from_html_str(html);
- let elements = MatchedElements::for_document(&doc).expect("parsed the doc");
-
- let item_elems = elements.top_level_elements();
- assert_eq!(item_elems.len(), expecting.top_level_elements);
-
- let item = elements
- .expand_item_from_element(Arc::clone(&item_elems[0]), &"http://example.com".parse()?)?;
-
- assert_eq!(item.properties.len(), expecting.property_count);
- Ok(())
-}
-
#[test]
fn element_locations_for_document_with_properties() -> Result<(), crate::Error> {
let base_url: url::Url = "https://example.com".parse()?;
--- a/library/src/parse/property/explicit/test.rs
+++ b/library/src/parse/property/explicit/test.rs
@@ -33,37 +33,6 @@
Ok(())
}
-#[yare::parameterized(
- direct = {
- r#"<time class="dt-timing" datetime="2014-01-01"></time>"#,
- "time", temporal::Value::Timestamp(temporal::Stamp::parse("2014-01-01")?)
- },
- abbr_title = {
- r#"<abbr class="dt-timing" title="2013-06-29">June 29</abbr>"#,
- "abbr", temporal::Value::Timestamp(temporal::Stamp::parse("2013-06-29")?)
- }
-)]
-fn temporal_value(html: &str, tag: &str, value: temporal::Value) -> Result<(), crate::Error> {
- let elem = grab_element_from_document(&from_html_str(html), tag).unwrap();
-
- let parser = explicit::PropertyParser::new(
- Arc::new(ElementRef {
- index: 0,
- node: Node { elem },
- }),
- DeclKind::Temporal("timing".to_string()),
- "http://example.com".parse()?,
- );
-
- assert_eq!(
- parser.expand()?,
- Some(("timing".to_string(), PropertyValue::Temporal(value))),
- "expanded a direct temporal property"
- );
-
- Ok(())
-}
-
#[test]
fn html() -> Result<(), crate::Error> {
let elem = grab_element_from_document(
@@ -95,37 +64,6 @@
);
Ok(())
-}
-
-#[yare::parameterized(
- bare = { "span", r#"<span class="p-name">The name.</span>"# },
- nested = { "div", r#"<div class="p-name">
- <span class="p-nickname">The</span> <span class="p-place">name.</span>
- </div>"# },
- tag_abbr = { "abbr", r#"<abbr class="p-name value" title="The name.">Wow.</abbr>"# },
- tag_link = { "link", r#"<link class="p-name value" href='/place' title="The name." />"# },
-)]
-fn plain(tag_name: &str, html: &str) -> Result<(), crate::Error> {
- let elem = grab_element_from_document(&from_html_str(html), tag_name).unwrap();
-
- let parser = PropertyParser::new(
- Arc::new(ElementRef {
- index: 0,
- node: Node { elem },
- }),
- DeclKind::Plain("name".to_string()),
- "http://example.com".parse()?,
- );
-
- assert_eq!(
- parser.expand()?,
- Some((
- "name".to_string(),
- PropertyValue::Plain("The name.".to_string())
- ))
- );
-
- Ok(())
}
#[test]
--- a/library/src/parse/property/implied/test.rs
+++ b/library/src/parse/property/implied/test.rs
@@ -4,118 +4,6 @@
ElementRef,
};
-#[yare::parameterized(
- simple = {
- r#"<img class="h-card" alt="wow" src="/photo.jpg" />"#, "img",
- Some(PropertyValue::Image(Image {
- value: "http://example.com/photo.jpg".parse()?,
- alt: Some("wow".to_string()),
- }))
- },
- hcard_impliedphoto_only_of_child = {
- r#"
-<div class="h-card"><span><img alt="Jane Doe" src="jane.jpeg"/></span></div>
- "#, "div",
- Some(PropertyValue::Image(Image {
- value: "http://example.com/jane.jpeg".parse()?,
- alt: Some("Jane Doe".to_string()),
- }))
- },
- hcard_multiple_photos = {
- r#"
-<div class="h-card"> <a href="https://example.com" class="p-name u-url">John Doe <img src="https://example.com/photo.jpg" alt=""> <img src="https://example.com/photo2.jpg" alt=""></a> </div>
- "#, "div", None
- },
- hcard_pproperty = {
- r#"
-<div class="h-card">
- <img class="p-honorific-suffix" src="images/logo.gif" alt="PHD" />
- <img src="images/logo.gif" alt="company logos" usemap="\#logomap" />
-</div>
- "#, "div", None
- }
-
-)]
-fn photo(html: &str, tag: &str, value: Option<PropertyValue>) -> Result<(), crate::Error> {
- let base_url: url::Url = "http://example.com".parse()?;
- let elem = grab_element_from_document(&from_html_str(html), tag).unwrap();
-
- let parser = ImpliedPhotoExtractor(Arc::new(ElementRef {
- index: 0,
- node: Node { elem },
- }));
-
- assert!(
- ImpliedPhotoExtractor::can_extract(&Default::default()),
- "can expect to get an implied photo"
- );
-
- assert_eq!(parser.extract(&base_url), value, "implied a photo");
- Ok(())
-}
-
-#[yare::parameterized(
- should_imply = { true, Properties::default() },
- p_prop = { false, Properties::from_iter(vec![
- ("name".to_string(), vec![PropertyValue::Plain("existing".to_string())])
- ])},
- e_prop = { false, Properties::from_iter(vec![
- ("name".to_string(), vec![
- PropertyValue::Fragment(Fragment {
- html: "Implied name.".to_string(),
- value: "Implied name.".to_string(),
- ..Default::default()
- })
- ])
- ])},
- nested_prop = { false, Properties::from_iter(vec![
- ("like-of".to_string(), vec![
- PropertyValue::Item(Item {
- r#type: vec![microformats_types::KnownClass::Cite.into()],
- ..Default::default()
- })
- ])
- ])},
-)]
-fn can_imply_name(assertion: bool, props: Properties) {
- assert_eq!(ImpliedNameExtractor::can_extract(&props), assertion);
-}
-
-#[yare::parameterized(
- img_alt = {"img", r#"<img class="h-card" alt="The implied name." />"#},
- abbr_title = {"abbr", r#"<abbr class="h-card" title="The implied name.">Not this.</abbr>"#},
- direct_img_alt = {"span", r#"<img alt="The implied name." />"#},
- direct_area_alt = {"span", r#"<area alt="The implied name."></area>"#},
- direct_abbr_title = {"span", r#"<abbr title="The implied name.">Not this.</abbr>"#},
- nested_direct_img_alt = {"div", r#"<img alt="The implied name." />"#},
- nested_direct_area_alt = {"div", r#"<area alt="The implied name."></abbr>"#},
- nested_direct_abbr_title = {"div", r#"<abbr title="The implied name.">Not this.</abbr>"#},
- weird_embed = {"p", r#"
-<!-- drop nested <script> and <style>, replace <img> with alt -->
-<p class="h-card"><style>p{font-color: red;}</style> <span>The</span> <span>implied</span><script src="https://example.com/script.js"></script> <img src="/photo.jpg" alt="name."> </p>
- "#}
-)]
-fn name(tag: &str, html: &str) {
- let base_url = "http://example.com".parse().unwrap();
- let full_html = match tag {
- "span" => format!(r#"<span class='h-card'>{html}</span>"#),
- "div" => format!(r#"<div class='h-card'><span>{html}</span></div>"#),
- _ => html.to_string(),
- };
- let direct_parser = ImpliedNameExtractor(Arc::new(ElementRef {
- index: 0,
- node: Node {
- elem: grab_element_from_document(&from_html_str(&full_html), tag).unwrap(),
- },
- }));
-
- assert_eq!(
- direct_parser.extract(&base_url),
- Some(PropertyValue::Plain("The implied name.".to_string())),
- "implied a name directly"
- );
-}
-
#[test]
fn url() -> Result<(), crate::Error> {
let dom = from_html_str(r#"<div class="h-item"><a class="h-item" href="/"></a></div>"#);
--- a/library/src/parse/test/mod.rs
+++ b/library/src/parse/test/mod.rs
@@ -3,88 +3,3 @@
use crate::parse::Parser;
use microformats_types::Document;
mod suite;
-
-#[yare::parameterized(
- sample = { r#"
-<!DOCTYPE html>
-<html>
- <head>
- <base href="https://example.com" />
- </head>
- <body>
- <main class="h-feed" id="feed">
- A pretty simple feed.
- <img src="/photo.jpg" alt="the photo" />
- <div class="h-entry" id="entry1">
- An initial entry.
- </div>
- <div class="h-entry" id="entry2">
- <span class="p-name">A title.</span>
- <a href="/jump-uid" class="u-uid"></a>
- <a href="/jump-url" class="u-url"></a>
- </div>
- <div class="h-entry" id="entry3">
- <span class="p-name">Another title.</span>
- </div>
- <a href="/"></a>
- </main>
- <aside id="selfReview" class="h-review"></aside>
- </body>
-</html>
- "#,
- serde_json::from_value(serde_json::json!({
- "items": [
- {
- "id": "feed",
- "type": ["h-feed"],
- "properties": {},
- "children": [
- {
- "id": "entry1",
- "type": ["h-entry"],
- "properties": {
- "name": ["An initial entry."],
- },
- },
- {
- "id": "entry2",
- "type": ["h-entry"],
- "properties": {
- "name": ["A title."],
- "uid": ["https://example.com/jump-uid"],
- "url": ["https://example.com/jump-url"],
- },
- },
- {
- "id": "entry3",
- "type": ["h-entry"],
- "properties": {
- "name": ["Another title."]
- },
- }
- ]
- },
- {
- "type": ["h-review"],
- "id": "selfReview",
- "properties": {},
- }
- ],
- "rels": {},
- "rel-urls": {}
- })).unwrap()
- }
-)]
-fn parse_into_document(html: &str, document: Document) -> Result<(), crate::Error> {
- let parser = Parser::from_html(html.to_string())?;
-
- let result = parser.into_document(Some("http://example.com".parse()?));
-
- similar_asserts::assert_serde_eq!(
- actual: result.map_err(|e| e.to_string()),
- expected: Ok(document),
- "forms expected document"
- );
-
- Ok(())
-}
--- a/library/src/parse/value_class/test.rs
+++ b/library/src/parse/value_class/test.rs
@@ -27,91 +27,3 @@
Some("2000-100 10:00Z".to_owned())
);
}
-
-#[yare::parameterized(
- value_img = {"img", "<img class='value' alt='A cool place to be.' />"},
- value_area = {"area", "<area class='value' alt='A cool place to be.'></area>"},
- value_data = {"data", "<data class='value' value='A cool place to be.' />"},
- value_title_span = {"span", "<span class='value-title' title='A cool place to be.'>Don't take this.</span>"},
- value_title = {"div", r#"
-<p>
- <span class="h-geo">The Bricklayer's Arms
- <div class="p-latitude">
- <span class="value-title" title="A cool place to be."> </span>
- </div>
- <span class="p-longitude">
- <span class="value-title" title="-0.14812"> </span>
- </span>
- </span>
-</p>
- "#}
-)]
-fn text_extraction(tag: &str, html: &str) {
- let element = grab_element_from_document(&from_html_str(html), tag).unwrap();
- let vcp_extractor = ValueClassPropertyExtractor {
- element: ElementPtr::new(ElementRef {
- index: 0,
- node: Node { elem: element },
- }),
- hint: TypeHint::Plain,
- };
-
- assert_eq!(
- vcp_extractor.extract_value_class(&"http://example.com".parse().unwrap()),
- Ok(Some(PropertyValue::Plain(
- "A cool place to be.".to_string()
- ))),
- "extracts the text"
- );
-}
-
-#[yare::parameterized(
- ins = { "ins", "<ins datetime='$dt'></ins>", None},
- del = { "del", "<del datetime='$dt'></del>", None},
- time = { "time", "<time datetime='$dt'></time>", None},
- time_class = { "time", "<time class='dt-magic' datetime='$dt'></time>", None},
- values = { "li", r#"
-<li class="dt-start">
- <time class="value" datetime="2009-06-26">26 July</time>, from
- <span class="value">07pm
-</span></li>
- "#, Stamp::from_str("2009-06-26 07pm").ok().map(temporal::Value::Timestamp) },
- value_title_date = { "p", r#"
- <p class="dt-start">
- <span class="value-title" title="2013-03-14"> </span>
- March 14th 2013
- </p>
- "#, Stamp::from_str("2013-03-14").ok().map(temporal::Value::Timestamp) },
- concat = { "span", r#"
- <span class="dt-start">
- <time class="value" datetime="2009-06-26">26 July</time>, from
- <time class="value">19:00-06:00</time>
- </span>
- "#, Stamp::from_str("2009-06-26 19:00-0600").ok().map(temporal::Value::Timestamp)}
-
-)]
-fn datetime(
- tag: &str,
- html: &str,
- expecting_dt: Option<temporal::Value>,
-) -> Result<(), crate::Error> {
- let stamp = expecting_dt.unwrap_or_else(|| temporal::Value::Timestamp(Stamp::now()));
- let dt = stamp.to_string();
- let element =
- grab_element_from_document(&from_html_str(&html.replace("$dt", &dt)), tag).unwrap();
- let vcp_extractor = ValueClassPropertyExtractor {
- element: ElementPtr::new(ElementRef {
- index: 0,
- node: Node { elem: element },
- }),
- hint: TypeHint::Temporal,
- };
-
- assert_eq!(
- vcp_extractor.extract_value_class(&"http://example.com".parse().unwrap()),
- Ok(Some(PropertyValue::Temporal(stamp))),
- "extracts the timestamp"
- );
-
- Ok(())
-}
|