Comments (9)
DOM-based comparison seems a little more flexible so you can document in code what kind of whitespace or attribute differences are acceptable. If you do string-based you might run into issues such as the hashmap ordering of attributes being different.
from bikeshed-rs.
See https://github.com/tabatkins/bikeshed/tree/master/tests. The idea is, given an input .bs, does it generate the expected .html.
from bikeshed-rs.
I use the serialize method of kuchiki
to serialize the DOM tree now, but there's a special HTML serializer in bikeshed
. If we want to use the expected HTML files in bikeshed
for testing, maybe we need to write a serializer like that.
from bikeshed-rs.
Alternatively, can we parse the bikeshed HTML with kuchiki, and serialize it back to guarantee it's idempotent?
Output doesn't have to be whitespace-compatible IMO.
from bikeshed-rs.
That makes sense if there's nothing special about the serializer in bikeshed
. What about building DOM trees from source files and expected HTML files, and then comparing them without serialization?
from bikeshed-rs.
That's also fine, but you'll still run into the whitespace issues I suspect. And potentially attribute ordering issues as well. (Attribute order is unfortunately still implementation-defined.)
from bikeshed-rs.
Yeah, however those issues should be easy to work around / ignore in the comparison (sorting the attributes, and skipping child whitespace text nodes where appropriate).
So it seems pretty reasonable to me.
from bikeshed-rs.
I'm trying to compare DOM trees in this way:
fn is_equal(lhs: &NodeRef, rhs: &NodeRef) -> bool {
if lhs.data() != rhs.data() {
return false;
}
let lhs_children = lhs.children().collect::<Vec<NodeRef>>();
let rhs_children = rhs.children().collect::<Vec<NodeRef>>();
if lhs_children.len() != rhs_children.len() {
return false;
}
for (lc, rc) in lhs_children.iter().zip(rhs_children.iter()) {
if !is_equal(lc, rc) {
return false;
}
}
true
}
But it isn't working because whitespace characters that are outside of HTML elements will be treated as text nodes (kuchiki
will treat newline character as NodeRef(Text(RefCell { value: "\n" })
).
-
If we want to do the DOM-based comparison, we need to handle these text nodes in DOM trees.
-
If we want to do the string-based comparison, we need to ensure the generated HTML files and the expected HTML files have the same format.
from bikeshed-rs.
The DOM-based comparison is working now. See #12.
from bikeshed-rs.
Related Issues (7)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bikeshed-rs.