Coder Social home page Coder Social logo

Figure out a testing story. about bikeshed-rs HOT 9 OPEN

fiji-flo avatar fiji-flo commented on August 26, 2024
Figure out a testing story.

from bikeshed-rs.

Comments (9)

annevk avatar annevk commented on August 26, 2024 1

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.

annevk avatar annevk commented on August 26, 2024

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.

whichxjy avatar whichxjy commented on August 26, 2024

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.

emilio avatar emilio commented on August 26, 2024

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.

whichxjy avatar whichxjy commented on August 26, 2024

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.

annevk avatar annevk commented on August 26, 2024

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.

emilio avatar emilio commented on August 26, 2024

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.

whichxjy avatar whichxjy commented on August 26, 2024

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.

whichxjy avatar whichxjy commented on August 26, 2024

The DOM-based comparison is working now. See #12.

from bikeshed-rs.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.