[librsvg/tests-for-gobject-introspection] Ignore changes to line numbers
- From: Sven Neumann <sneumann src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg/tests-for-gobject-introspection] Ignore changes to line numbers
- Date: Wed, 27 Jan 2021 17:49:33 +0000 (UTC)
commit 1197c553e1c00c299cc8a6b6295d3d34dca00754
Author: Sven Neumann <sven svenfoo org>
Date: Wed Jan 27 18:48:24 2021 +0100
Ignore changes to line numbers
Cargo.toml | 1 +
tests/fixtures/gir/Rsvg-2.0-ref.gir | 2 +-
tests/src/gir.rs | 40 ++++++++++++++++++++++++++++++++-----
3 files changed, 37 insertions(+), 6 deletions(-)
---
diff --git a/Cargo.toml b/Cargo.toml
index ccf738e2..cb284c7e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -57,6 +57,7 @@ criterion = "0.3"
glib = "0.9.0"
libc = "0.2"
lopdf = "0.26.0"
+markup5ever = "0.10"
markup5ever_rcdom = "0.1.0"
matches = "0.1"
pkg-config = "0.3.14"
diff --git a/tests/fixtures/gir/Rsvg-2.0-ref.gir b/tests/fixtures/gir/Rsvg-2.0-ref.gir
index 4fdea0c3..39f5e419 100644
--- a/tests/fixtures/gir/Rsvg-2.0-ref.gir
+++ b/tests/fixtures/gir/Rsvg-2.0-ref.gir
@@ -23,7 +23,7 @@ and/or use gtk-doc annotations. -->
introspectable="0">
<doc xml:space="preserve"
filename="rsvg-features.h"
- line="106">This C macro returns #TRUE if the the version of librsvg being
+ line="100">This C macro returns #TRUE if the the version of librsvg being
compiled against is the same or newer than the specified version.
Note that this a compile-time check for C programs. If you want a
diff --git a/tests/src/gir.rs b/tests/src/gir.rs
index b338a247..f42d07de 100644
--- a/tests/src/gir.rs
+++ b/tests/src/gir.rs
@@ -1,13 +1,17 @@
+extern crate markup5ever;
extern crate markup5ever_rcdom as rcdom;
extern crate xml5ever;
+use std::cell::RefCell;
use std::default::Default;
use std::fs::File;
use std::path::Path;
+use markup5ever::Attribute;
+use markup5ever::QualName;
use rcdom::{Handle, NodeData, RcDom};
use xml5ever::driver::parse_document;
-use xml5ever::tendril::TendrilSink;
+use xml5ever::tendril::{StrTendril, TendrilSink};
fn build_dir() -> &'static Path {
match option_env!("LIBRSVG_BUILD_DIR") {
@@ -23,14 +27,40 @@ fn parse(path: &Path) -> std::io::Result<RcDom> {
.read_from(&mut file)
}
+fn format_text(text: &RefCell<StrTendril>) -> String {
+ format!("text: {}", escape_default(&text.borrow()))
+}
+
+fn format_element(name: &QualName, attrs: &RefCell<Vec<Attribute>>) -> String {
+ let mut str = String::from(format!("<{}", name.local));
+ for attr in attrs.borrow().iter() {
+ str.push_str(&format!(" {}=\"{}\"", attr.name.local, attr.value));
+ }
+ str.push_str(">");
+ str
+}
+
+fn equal(a: &RefCell<Vec<Attribute>>, b: &RefCell<Vec<Attribute>>, ignore_name: &str) -> bool {
+ let ignore = |&attr: &&Attribute| -> bool { !attr.name.local.eq(ignore_name) };
+ a.borrow()
+ .iter()
+ .filter(ignore)
+ .zip(b.borrow().iter().filter(ignore))
+ .all(|(a, b)| a.eq(b))
+}
+
fn diff(a: &NodeData, b: &NodeData) -> Option<String> {
match a {
NodeData::Document if !matches!(b, NodeData::Document) => Some(String::from("root")),
- NodeData::Text { contents: ref c } if !matches!(b, NodeData::Text { contents: ref d } if c.eq(d)) =>
{
- Some(format!("text: {:?}", c))
+ NodeData::Text { contents: ref a } if !matches!(b, NodeData::Text { contents: ref b } if a.eq(&b))
=> {
+ Some(format_text(&a))
}
- NodeData::Element { name: ref c, .. } if !matches!(b, NodeData::Element { name: ref d, .. } if
c.eq(d)) => {
- Some(format!("element: {:?}", c))
+ NodeData::Element {
+ name: ref a,
+ attrs: ref a_attrs,
+ ..
+ } if !matches!(b, NodeData::Element { name: ref b, attrs: ref b_attrs, .. } if a.eq(&b) &&
equal(&a_attrs, &b_attrs, "line")) => {
+ Some(format_element(&a, &a_attrs))
}
_ => None,
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]