|
| 1 | +/* |
| 2 | + * Copyright 2017 Michael Stringer |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
1 | 17 | package software.purpledragon.xml.compare
|
2 | 18 |
|
3 | 19 | import org.scalatest.{FlatSpec, Matchers}
|
@@ -80,6 +96,41 @@ class XmlCompareSpec extends FlatSpec with Matchers {
|
80 | 96 | )
|
81 | 97 | }
|
82 | 98 |
|
| 99 | + it should "match with same attributes" in { |
| 100 | + XmlCompare.compare(<test first="a" second="b"/>, <test first="a" second="b" />) shouldBe XmlEqual |
| 101 | + } |
| 102 | + |
| 103 | + it should "match with same attributes in different order" in { |
| 104 | + XmlCompare.compare(<test first="a" second="b"/>, <test second="b" first="a" />) shouldBe XmlEqual |
| 105 | + } |
| 106 | + |
| 107 | + it should "not-match with different attribute names" in { |
| 108 | + XmlCompare.compare(<test value="a" />, <test cost="a" />) shouldBe XmlDiffers( |
| 109 | + "different attribute names", |
| 110 | + Seq("value"), |
| 111 | + Seq("cost"), |
| 112 | + Seq("test") |
| 113 | + ) |
| 114 | + } |
| 115 | + |
| 116 | + it should "not-match with different attribute count" in { |
| 117 | + XmlCompare.compare(<test first="a" second="b" />, <test first="a" />) shouldBe XmlDiffers( |
| 118 | + "different attribute names", |
| 119 | + Seq("first", "second"), |
| 120 | + Seq("first"), |
| 121 | + Seq("test") |
| 122 | + ) |
| 123 | + } |
| 124 | + |
| 125 | + it should "not-match with different attribute value" in { |
| 126 | + XmlCompare.compare(<test value="a" />, <test value="b" />) shouldBe XmlDiffers( |
| 127 | + "different value for attribute 'value'", |
| 128 | + "a", |
| 129 | + "b", |
| 130 | + Seq("test") |
| 131 | + ) |
| 132 | + } |
| 133 | + |
83 | 134 | it should "not-match with multiple errors" in {
|
84 | 135 | XmlCompare.compare(
|
85 | 136 | <test><child-1>text-1</child-1><child-2>text-2</child-2></test>,
|
@@ -115,4 +166,17 @@ class XmlCompareSpec extends FlatSpec with Matchers {
|
115 | 166 | <t:test xmlns:e="http://example.org"/>,
|
116 | 167 | Set(IgnoreNamespace)) shouldBe XmlEqual
|
117 | 168 | }
|
| 169 | + |
| 170 | + "compare with StrictAttributeOrder" should "match with same attributes" in { |
| 171 | + XmlCompare.compare(<test first="a" second="b" />, <test first="a" second="b" />, Set(StrictAttributeOrdering)) shouldBe XmlEqual |
| 172 | + } |
| 173 | + |
| 174 | + it should "not-match with attributes in different order" in { |
| 175 | + XmlCompare.compare(<test first="a" second="b" />, <test second="b" first="a" />, Set(StrictAttributeOrdering)) shouldBe XmlDiffers( |
| 176 | + "different attribute ordering", |
| 177 | + Seq("first", "second"), |
| 178 | + Seq("second", "first"), |
| 179 | + Seq("test") |
| 180 | + ) |
| 181 | + } |
118 | 182 | }
|
0 commit comments