Git Product home page Git Product logo

compare-xml's Introduction

Header

compare-xml's People

Contributors

adarsh avatar arthurweiden avatar vkononov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

compare-xml's Issues

Ignoring attributes works in unexpected ways

Thank you for this gem! I found it to be super helpful in tests.

One thing that was really unexpected for me is that options to ignore attributes require the attribute to be present in both elements.

For example, with ignore_attrs_by_name: ['class'] I expected the following two elements to be equivalent:

<div class="foo"></div>
<div></div>

However, they are considered to be different.

For them to be equivalent the second element must have a [class] attribute, with any value:

<div class="foo"></div>
<div class></div>

Maybe this is something that could be changed or documented.

Thanks again for the gem!

Element additions are shown as element changes?

Consider this code:

require 'compare-xml'

left_s = <<EOS
<?xml version="1.0" encoding="UTF-8"?>
<project>
    <keepDependencies>false</keepDependencies>
    <properties>
        <hudson.plugins.buildblocker.BuildBlockerProperty plugin="[email protected]">
            <useBuildBlocker>false</useBuildBlocker>
            <blockLevel>GLOBAL</blockLevel>
            <scanQueueFor>DISABLED</scanQueueFor>
            <blockingJobs/>
        </hudson.plugins.buildblocker.BuildBlockerProperty>
        <com.sonyericsson.rebuild.RebuildSettings plugin="[email protected]">
            <autoRebuild>false</autoRebuild>
            <rebuildDisabled>false</rebuildDisabled>
        </com.sonyericsson.rebuild.RebuildSettings>
        <hudson.model.ParametersDefinitionProperty>
            <parameterDefinitions>
                <hudson.model.StringParameterDefinition>
                    <name>approval_message</name>
                    <defaultValue/>
                </hudson.model.StringParameterDefinition>
            </parameterDefinitions>
        </hudson.model.ParametersDefinitionProperty>
    </properties>
</project>
EOS

right_s = <<EOS
<?xml version="1.0" encoding="UTF-8"?>
<project>
    <keepDependencies>false</keepDependencies>
    <properties>
        <hudson.model.ParametersDefinitionProperty>
            <parameterDefinitions>
                <hudson.model.StringParameterDefinition>
                    <name>approval_message</name>
                    <defaultValue/>
                </hudson.model.StringParameterDefinition>
            </parameterDefinitions>
        </hudson.model.ParametersDefinitionProperty>
    </properties>
</project>
EOS

left = Nokogiri::XML left_s
right = Nokogiri::XML right_s
res = CompareXML.equivalent? left, right, verbose: true
pp res

produces

[{:node1=>
   #(Element:0x3c {
     name = "hudson.plugins.buildblocker.BuildBlockerProperty",
     attributes = [
       #(Attr:0x50 { name = "plugin", value = "[email protected]" })],
     children = [
       #(Text "\n" + "            "),
       #(Element:0x64 {
         name = "useBuildBlocker",
         children = [ #(Text "false")]
         }),
       #(Text "\n" + "            "),
       #(Element:0x78 { name = "blockLevel", children = [ #(Text "GLOBAL")] }),
       #(Text "\n" + "            "),
       #(Element:0x8c {
         name = "scanQueueFor",
         children = [ #(Text "DISABLED")]
         }),
       #(Text "\n" + "            "),
       #(Element:0xa0 { name = "blockingJobs" }),
       #(Text "\n" + "        ")]
     }),
  :node2=>
   #(Element:0xb4 {
     name = "hudson.model.ParametersDefinitionProperty",
     children = [
       #(Text "\n" + "            "),
       #(Element:0xc8 {
         name = "parameterDefinitions",
         children = [
           #(Text "\n" + "                "),
           #(Element:0xdc {
             name = "hudson.model.StringParameterDefinition",
             children = [
               #(Text "\n" + "                    "),
               #(Element:0xf0 {
                 name = "name",
                 children = [ #(Text "approval_message")]
                 }),
               #(Text "\n" + "                    "),
               #(Element:0x104 { name = "defaultValue" }),
               #(Text "\n" + "                ")]
             }),
           #(Text "\n" + "            ")]
         }),
       #(Text "\n" + "        ")]
     }),
  :diff1=>"hudson.plugins.buildblocker.BuildBlockerProperty",
  :diff2=>"hudson.model.ParametersDefinitionProperty"}]

Since hudson.plugins.buildblocker.BuildBlockerProperty and com.sonyericsson.rebuild.RebuildSettings are added to the left XML blob but the XML blobs are otherwise the same, I'd expect node1 to show what it does but node2 to be empty. Instead, node2 seems to be showing what is at the spot in the XML tree where it found what is in node1. That doesn't seem right - it should just show the addition.

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.