From c17aaa59642ea1726c173151ed4430a97c321e84 Mon Sep 17 00:00:00 2001 From: Michael Stringer Date: Wed, 2 Oct 2019 14:19:01 +0100 Subject: [PATCH 1/7] Sign sbt-release git sign flag --- build.sbt | 1 + 1 file changed, 1 insertion(+) diff --git a/build.sbt b/build.sbt index 728f0e4..9282d6c 100644 --- a/build.sbt +++ b/build.sbt @@ -70,6 +70,7 @@ lazy val root = Project("scala-xml-compare", file(".")) ), // sbt-release settings releaseCrossBuild := true, + releaseVcsSign := true, releaseProcess := Seq[ReleaseStep]( checkSnapshotDependencies, inquireVersions, From 7375573a43d53cdd6b8d6cc133447f1cf21ecd23 Mon Sep 17 00:00:00 2001 From: Michael Stringer Date: Wed, 2 Oct 2019 14:38:43 +0100 Subject: [PATCH 2/7] Encapsulate diff options into an object --- .../purpledragon/xml/compare/XmlCompare.scala | 23 ++++++------- .../xml/compare/options/DiffOptions.scala | 26 +++++++++++++++ .../xml/compare/options/package.scala | 27 ---------------- .../xml/compare/XmlCompareSpec.scala | 21 ++++++------ .../xml/scalatest/XmlMatchers.scala | 11 +++---- .../xml/scalatest/XmlMatchersSpec.scala | 4 +-- .../purpledragon/xml/specs2/XmlMatchers.scala | 32 +++++++++---------- .../xml/specs2/XmlMatchersSpec.scala | 4 +-- 8 files changed, 70 insertions(+), 78 deletions(-) create mode 100644 xml-compare/src/main/scala/software/purpledragon/xml/compare/options/DiffOptions.scala delete mode 100644 xml-compare/src/main/scala/software/purpledragon/xml/compare/options/package.scala diff --git a/xml-compare/src/main/scala/software/purpledragon/xml/compare/XmlCompare.scala b/xml-compare/src/main/scala/software/purpledragon/xml/compare/XmlCompare.scala index 36e2e77..8309bf6 100644 --- a/xml-compare/src/main/scala/software/purpledragon/xml/compare/XmlCompare.scala +++ b/xml-compare/src/main/scala/software/purpledragon/xml/compare/XmlCompare.scala @@ -28,15 +28,10 @@ import scala.xml._ object XmlCompare { private type Check = (Node, Node, DiffOptions, Seq[String]) => XmlDiff - private implicit val NodeOrdering = NormalisedNodeOrdering + private implicit val NodeOrdering: NormalisedNodeOrdering.type = NormalisedNodeOrdering - /** - * Default [[software.purpledragon.xml.compare.options.DiffOption.DiffOption DiffOption]]s to use during XML comparison. - * - * Currently these are: - * - [[software.purpledragon.xml.compare.options.DiffOption.IgnoreNamespacePrefix IgnoreNamespacePrefix]] - */ - val DefaultOptions: DiffOptions = Set(IgnoreNamespacePrefix) + @deprecated(message = "use DiffOptions.Default", since = "2.0.0") + val DefaultOptions: DiffOptions = DiffOptions.default /** * Compares two XML documents. This will perform a recursive scan of all the nodes in each document, checking each @@ -47,7 +42,7 @@ object XmlCompare { * @param options configuration options to control the way the comparison is performed. * @return results of the XML comparison. */ - def compare(left: Node, right: Node, options: DiffOptions = DefaultOptions): XmlDiff = { + def compare(left: Node, right: Node, options: DiffOptions = DiffOptions.default): XmlDiff = { compareNodes(left, right, options, Nil) } @@ -72,10 +67,10 @@ object XmlCompare { private def compareNamespace(left: Node, right: Node, options: DiffOptions, path: Seq[String]): XmlDiff = { if (left.label != right.label) { XmlDiffers("different label", left.label, right.label, extendPath(path, left)) - } else if (left.namespace != right.namespace && !options.contains(IgnoreNamespace)) { + } else if (left.namespace != right.namespace && options.isDisabled(IgnoreNamespace)) { XmlDiffers("different namespace", left.namespace, right.namespace, extendPath(path, left)) - } else if (left.prefix != right.prefix && !options.contains(IgnoreNamespacePrefix) && - !options.contains(IgnoreNamespace)) { + } else if (left.prefix != right.prefix && options.isDisabled(IgnoreNamespacePrefix) && + options.isDisabled(IgnoreNamespace)) { XmlDiffers("different namespace prefix", left.prefix, right.prefix, extendPath(path, left)) } else { XmlEqual @@ -88,7 +83,7 @@ object XmlCompare { if (leftKeys.sorted != rightKeys.sorted) { XmlDiffers("different attribute names", leftKeys.sorted, rightKeys.sorted, extendPath(path, left)) - } else if (options.contains(StrictAttributeOrdering) && leftKeys != rightKeys) { + } else if (options.isEnabled(StrictAttributeOrdering) && leftKeys != rightKeys) { XmlDiffers("different attribute ordering", leftKeys, rightKeys, extendPath(path, left)) } else { leftKeys.sorted collectFirst { @@ -134,7 +129,7 @@ object XmlCompare { } private def normalise(nodes: Seq[Node], options: DiffOptions): Seq[Node] = { - val sort = options.contains(DiffOption.IgnoreChildOrder) + val sort = options.isEnabled(DiffOption.IgnoreChildOrder) val filtered = nodes.filterNot(n => n.isInstanceOf[Atom[_]]) if (sort) { diff --git a/xml-compare/src/main/scala/software/purpledragon/xml/compare/options/DiffOptions.scala b/xml-compare/src/main/scala/software/purpledragon/xml/compare/options/DiffOptions.scala new file mode 100644 index 0000000..93b5004 --- /dev/null +++ b/xml-compare/src/main/scala/software/purpledragon/xml/compare/options/DiffOptions.scala @@ -0,0 +1,26 @@ +package software.purpledragon.xml.compare.options + +object DiffOptions { + + /** + * Default [[DiffOption DiffOption]]s to use during XML comparison. + * + * Currently these are: + * - [[DiffOption.IgnoreNamespacePrefix IgnoreNamespacePrefix]] + */ + val default: DiffOptions = DiffOptions(DiffOption.IgnoreNamespacePrefix) + val empty: DiffOptions = DiffOptions() + + def apply(options: DiffOption.DiffOption*): DiffOptions = DiffOptions(options.toSet) +} + +case class DiffOptions(options: Set[DiffOption.DiffOption]) { + def &(option: DiffOption.DiffOption): DiffOptions = copy(options = options + option) + def &!(option: DiffOption.DiffOption): DiffOptions = copy(options = options - option) + + def +(option: DiffOption.DiffOption): DiffOptions = copy(options = options + option) + def -(option: DiffOption.DiffOption): DiffOptions = copy(options = options - option) + + def isEnabled(option: DiffOption.DiffOption): Boolean = options.contains(option) + def isDisabled(option: DiffOption.DiffOption): Boolean = !options.contains(option) +} diff --git a/xml-compare/src/main/scala/software/purpledragon/xml/compare/options/package.scala b/xml-compare/src/main/scala/software/purpledragon/xml/compare/options/package.scala deleted file mode 100644 index 5d26d97..0000000 --- a/xml-compare/src/main/scala/software/purpledragon/xml/compare/options/package.scala +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2017 Michael Stringer - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package software.purpledragon.xml.compare - -import software.purpledragon.xml.compare.options.DiffOption.DiffOption - -package object options { - - /** - * Shorthand for a collection of [[DiffOption]]s. - */ - type DiffOptions = Set[DiffOption] -} diff --git a/xml-compare/src/test/scala/software/purpledragon/xml/compare/XmlCompareSpec.scala b/xml-compare/src/test/scala/software/purpledragon/xml/compare/XmlCompareSpec.scala index d498b9d..1473ebc 100644 --- a/xml-compare/src/test/scala/software/purpledragon/xml/compare/XmlCompareSpec.scala +++ b/xml-compare/src/test/scala/software/purpledragon/xml/compare/XmlCompareSpec.scala @@ -18,6 +18,7 @@ package software.purpledragon.xml.compare import org.scalatest.{FlatSpec, Matchers} import software.purpledragon.xml.compare.options.DiffOption._ +import software.purpledragon.xml.compare.options.DiffOptions class XmlCompareSpec extends FlatSpec with Matchers { @@ -152,7 +153,7 @@ class XmlCompareSpec extends FlatSpec with Matchers { XmlCompare.compare( , , - Set.empty + DiffOptions.empty ) shouldBe XmlDiffers("different namespace prefix", "t", "e", Seq("t:test")) } @@ -160,7 +161,7 @@ class XmlCompareSpec extends FlatSpec with Matchers { XmlCompare.compare( , , - Set.empty + DiffOptions.empty ) shouldBe XmlEqual } @@ -168,7 +169,7 @@ class XmlCompareSpec extends FlatSpec with Matchers { XmlCompare.compare( , , - Set(IgnoreNamespace) + DiffOptions(IgnoreNamespace) ) shouldBe XmlEqual } @@ -176,7 +177,7 @@ class XmlCompareSpec extends FlatSpec with Matchers { XmlCompare.compare( , , - Set(IgnoreNamespace) + DiffOptions(IgnoreNamespace) ) shouldBe XmlEqual } @@ -184,7 +185,7 @@ class XmlCompareSpec extends FlatSpec with Matchers { XmlCompare.compare( , , - Set(StrictAttributeOrdering) + DiffOptions(StrictAttributeOrdering) ) shouldBe XmlEqual } @@ -192,7 +193,7 @@ class XmlCompareSpec extends FlatSpec with Matchers { XmlCompare.compare( , , - Set(StrictAttributeOrdering) + DiffOptions(StrictAttributeOrdering) ) shouldBe XmlDiffers( "different attribute ordering", Seq("first", "second"), @@ -205,7 +206,7 @@ class XmlCompareSpec extends FlatSpec with Matchers { XmlCompare.compare( , , - Set(IgnoreChildOrder) + DiffOptions(IgnoreChildOrder) ) shouldBe XmlEqual } @@ -213,7 +214,7 @@ class XmlCompareSpec extends FlatSpec with Matchers { XmlCompare.compare( , , - Set(IgnoreChildOrder) + DiffOptions(IgnoreChildOrder) ) shouldBe XmlEqual } @@ -221,7 +222,7 @@ class XmlCompareSpec extends FlatSpec with Matchers { XmlCompare.compare( , , - Set(IgnoreChildOrder) + DiffOptions(IgnoreChildOrder) ) shouldBe XmlEqual } @@ -229,7 +230,7 @@ class XmlCompareSpec extends FlatSpec with Matchers { XmlCompare.compare( , , - Set(IgnoreChildOrder) + DiffOptions(IgnoreChildOrder) ) shouldBe XmlEqual } } diff --git a/xml-scalatest/src/main/scala/software/purpledragon/xml/scalatest/XmlMatchers.scala b/xml-scalatest/src/main/scala/software/purpledragon/xml/scalatest/XmlMatchers.scala index 7ee7e49..78d43a8 100644 --- a/xml-scalatest/src/main/scala/software/purpledragon/xml/scalatest/XmlMatchers.scala +++ b/xml-scalatest/src/main/scala/software/purpledragon/xml/scalatest/XmlMatchers.scala @@ -40,19 +40,18 @@ trait XmlMatchers { * result should beXml(1) * }}} * - * If unspecified this will use [[software.purpledragon.xml.compare.XmlCompare.DefaultOptions XmlCompare.DefaultOptions]] - * during the comparison. This can be overridden with a global implicit of - * [[software.purpledragon.xml.compare.options.DiffOptions DiffOptions]] or on an individual basis: + * If unspecified this will use [[DiffOptions.default]] during the comparison. This can be overridden with a global + * implicit of [[DiffOptions]] or on an individual basis: * * {{{ - * implicit val diffOptions: DiffOptions = Set(IgnoreNamespace) + * implicit val diffOptions: DiffOptions = DiffOptions(IgnoreNamespace) * result should beXml(1) * * // or - * result should beXml(1)(Set.empty) + * result should beXml(1)(DiffOptions.empty) * }}} */ - def beXml(expected: Node)(implicit options: DiffOptions = XmlCompare.DefaultOptions): Matcher[Node] = + def beXml(expected: Node)(implicit options: DiffOptions = DiffOptions.default): Matcher[Node] = new XmlMatcher(expected, options) private class XmlMatcher(expected: Node, options: DiffOptions) extends Matcher[Node] { diff --git a/xml-scalatest/src/test/scala/software/purpledragon/xml/scalatest/XmlMatchersSpec.scala b/xml-scalatest/src/test/scala/software/purpledragon/xml/scalatest/XmlMatchersSpec.scala index 4fb2cfb..b4969a8 100644 --- a/xml-scalatest/src/test/scala/software/purpledragon/xml/scalatest/XmlMatchersSpec.scala +++ b/xml-scalatest/src/test/scala/software/purpledragon/xml/scalatest/XmlMatchersSpec.scala @@ -68,7 +68,7 @@ class XmlMatchersSpec extends FlatSpec with Matchers with XmlMatchers { } "beXml(xml)(options)" should "not match XML with different namespace" in { - val matcher = beXml(text)(Set.empty) + val matcher = beXml(text)(DiffOptions.empty) val matchResult = matcher(text) matchResult.matches shouldBe false @@ -76,7 +76,7 @@ class XmlMatchersSpec extends FlatSpec with Matchers with XmlMatchers { } "beXml(xml) with implicit options" should "not match XML with different namespace" in { - implicit val options: DiffOptions = Set.empty + implicit val options: DiffOptions = DiffOptions.empty val matcher = beXml(text) val matchResult = matcher(text) diff --git a/xml-specs2/src/main/scala/software/purpledragon/xml/specs2/XmlMatchers.scala b/xml-specs2/src/main/scala/software/purpledragon/xml/specs2/XmlMatchers.scala index f9e3556..acd5756 100644 --- a/xml-specs2/src/main/scala/software/purpledragon/xml/specs2/XmlMatchers.scala +++ b/xml-specs2/src/main/scala/software/purpledragon/xml/specs2/XmlMatchers.scala @@ -41,33 +41,31 @@ trait XmlMatchers { * result must beXml(1) * }}} * - * If unspecified this will use [[software.purpledragon.xml.compare.XmlCompare.DefaultOptions XmlCompare.DefaultOptions]] - * during the comparison. This can be overridden with a global implicit of - * [[software.purpledragon.xml.compare.options.DiffOptions DiffOptions]] or on an individual basis: + * If unspecified this will use [[DiffOptions.default]] during the comparison. This can be overridden with a global + * implicit of [[DiffOptions]] or on an individual basis: * * {{{ - * implicit val diffOptions: DiffOptions = Set(IgnoreNamespace) + * implicit val diffOptions: DiffOptions = DiffOptions(IgnoreNamespace) * result must beXml(1) * * // or - * result must beXml(1)(Set.empty) + * result must beXml(1)(DiffOptions.empty) * }}} */ - def beXml(expected: Node)(implicit options: DiffOptions = XmlCompare.DefaultOptions): Matcher[Node] = { - actual: Node => - val diff = XmlCompare.compare(expected, actual, options) + def beXml(expected: Node)(implicit options: DiffOptions = DiffOptions.default): Matcher[Node] = { actual: Node => + val diff = XmlCompare.compare(expected, actual, options) - val failureBuilder = new StringBuilder() - failureBuilder ++= "XML did not match" + val failureBuilder = new StringBuilder() + failureBuilder ++= "XML did not match" - if (diff.failurePath.nonEmpty) { - failureBuilder ++= " at " - diff.failurePath.addString(failureBuilder, "[", " / ", "]") - } + if (diff.failurePath.nonEmpty) { + failureBuilder ++= " at " + diff.failurePath.addString(failureBuilder, "[", " / ", "]") + } - failureBuilder ++= ": " - failureBuilder ++= diff.message + failureBuilder ++= ": " + failureBuilder ++= diff.message - (diff.isEqual, "XML matched", failureBuilder.toString()) + (diff.isEqual, "XML matched", failureBuilder.toString()) } } diff --git a/xml-specs2/src/test/scala/software/purpledragon/xml/specs2/XmlMatchersSpec.scala b/xml-specs2/src/test/scala/software/purpledragon/xml/specs2/XmlMatchersSpec.scala index fd3dde3..e277496 100644 --- a/xml-specs2/src/test/scala/software/purpledragon/xml/specs2/XmlMatchersSpec.scala +++ b/xml-specs2/src/test/scala/software/purpledragon/xml/specs2/XmlMatchersSpec.scala @@ -73,7 +73,7 @@ class XmlMatchersSpec extends Specification with XmlMatchers with Expectations { "beXml(xml)(options)" should { "not match XML with different namespace" in { - val matcher = beXml(text)(Set.empty) + val matcher = beXml(text)(DiffOptions.empty) val matchResult = matcher(createExpectable(text)) matchResult.isSuccess === false @@ -83,7 +83,7 @@ class XmlMatchersSpec extends Specification with XmlMatchers with Expectations { "beXml(xml) with implicit options" should { "not match XML with different namespace" in { - implicit val options: DiffOptions = Set.empty + implicit val options: DiffOptions = DiffOptions.empty val matcher = beXml(text) val matchResult = matcher(createExpectable(text)) From 447e70ce4876f8e7051e3f473973927300e313da Mon Sep 17 00:00:00 2001 From: Michael Stringer Date: Sun, 7 Jun 2020 11:06:27 +0100 Subject: [PATCH 3/7] Bump sbt & scala versions --- build.sbt | 4 ++-- project/build.properties | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build.sbt b/build.sbt index 9282d6c..c820542 100644 --- a/build.sbt +++ b/build.sbt @@ -5,8 +5,8 @@ import sbtrelease.ReleasePlugin.autoImport._ inThisBuild( Seq( organization := "software.purpledragon.xml", - scalaVersion := "2.13.1", - crossScalaVersions := Seq(scalaVersion.value, "2.11.12", "2.12.10"), + scalaVersion := "2.13.2", + crossScalaVersions := Seq(scalaVersion.value, "2.11.12", "2.12.11"), licenses += ("Apache-2.0", url("https://opensource.org/licenses/Apache-2.0")), developers := List( Developer("stringbean", "Michael Stringer", "@the_stringbean", url("https://github.com/stringbean")) diff --git a/project/build.properties b/project/build.properties index 8522443..654fe70 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.3.2 +sbt.version=1.3.12 From d2b2b155e8802c823eff0dad1b1c8f45173d62ed Mon Sep 17 00:00:00 2001 From: Michael Stringer Date: Sun, 7 Jun 2020 11:11:06 +0100 Subject: [PATCH 4/7] Bump scalatest & specs2 versions --- xml-compare/build.sbt | 2 +- .../test/scala/software/purpledragon/xml/XmlUtilsSpec.scala | 5 +++-- .../xml/compare/NormalisedNodeOrderingSpec.scala | 5 +++-- .../software/purpledragon/xml/compare/XmlCompareSpec.scala | 5 +++-- xml-scalatest/build.sbt | 2 +- .../purpledragon/xml/scalatest/XmlMatchersSpec.scala | 5 +++-- xml-specs2/build.sbt | 2 +- 7 files changed, 15 insertions(+), 11 deletions(-) diff --git a/xml-compare/build.sbt b/xml-compare/build.sbt index 6c3a0f7..66b644e 100644 --- a/xml-compare/build.sbt +++ b/xml-compare/build.sbt @@ -1,5 +1,5 @@ name := "xml-compare" libraryDependencies ++= Seq( - "org.scalatest" %% "scalatest" % "3.0.8" % Test + "org.scalatest" %% "scalatest" % "3.1.2" % Test ) diff --git a/xml-compare/src/test/scala/software/purpledragon/xml/XmlUtilsSpec.scala b/xml-compare/src/test/scala/software/purpledragon/xml/XmlUtilsSpec.scala index 3c876e4..5d6f601 100644 --- a/xml-compare/src/test/scala/software/purpledragon/xml/XmlUtilsSpec.scala +++ b/xml-compare/src/test/scala/software/purpledragon/xml/XmlUtilsSpec.scala @@ -16,9 +16,10 @@ package software.purpledragon.xml -import org.scalatest.{FlatSpec, Matchers} +import org.scalatest.flatspec.AnyFlatSpec +import org.scalatest.matchers.should.Matchers -class XmlUtilsSpec extends FlatSpec with Matchers { +class XmlUtilsSpec extends AnyFlatSpec with Matchers { "XmlUtils.extractAttributes" should "return empty values for no attributes" in { XmlUtils.extractAttributes() shouldBe (Nil, Map.empty[String, String]) } diff --git a/xml-compare/src/test/scala/software/purpledragon/xml/compare/NormalisedNodeOrderingSpec.scala b/xml-compare/src/test/scala/software/purpledragon/xml/compare/NormalisedNodeOrderingSpec.scala index 508a811..faba257 100644 --- a/xml-compare/src/test/scala/software/purpledragon/xml/compare/NormalisedNodeOrderingSpec.scala +++ b/xml-compare/src/test/scala/software/purpledragon/xml/compare/NormalisedNodeOrderingSpec.scala @@ -16,11 +16,12 @@ package software.purpledragon.xml.compare -import org.scalatest.{FlatSpec, Matchers} +import org.scalatest.flatspec.AnyFlatSpec +import org.scalatest.matchers.should.Matchers import scala.xml.{Comment, Node, PCData, Text} -class NormalisedNodeOrderingSpec extends FlatSpec with Matchers { +class NormalisedNodeOrderingSpec extends AnyFlatSpec with Matchers { private implicit val ordering: Ordering[Node] = NormalisedNodeOrdering "NormalisedNodeOrdering" should "order nodes by type" in { diff --git a/xml-compare/src/test/scala/software/purpledragon/xml/compare/XmlCompareSpec.scala b/xml-compare/src/test/scala/software/purpledragon/xml/compare/XmlCompareSpec.scala index 1473ebc..2ad8baf 100644 --- a/xml-compare/src/test/scala/software/purpledragon/xml/compare/XmlCompareSpec.scala +++ b/xml-compare/src/test/scala/software/purpledragon/xml/compare/XmlCompareSpec.scala @@ -16,11 +16,12 @@ package software.purpledragon.xml.compare -import org.scalatest.{FlatSpec, Matchers} +import org.scalatest.flatspec.AnyFlatSpec +import org.scalatest.matchers.should.Matchers import software.purpledragon.xml.compare.options.DiffOption._ import software.purpledragon.xml.compare.options.DiffOptions -class XmlCompareSpec extends FlatSpec with Matchers { +class XmlCompareSpec extends AnyFlatSpec with Matchers { "compare with defaults" should "match same empty element" in { XmlCompare.compare(, ) shouldBe XmlEqual diff --git a/xml-scalatest/build.sbt b/xml-scalatest/build.sbt index aeb5c25..588db11 100644 --- a/xml-scalatest/build.sbt +++ b/xml-scalatest/build.sbt @@ -1,5 +1,5 @@ name := "xml-scalatest" libraryDependencies ++= Seq( - "org.scalatest" %% "scalatest" % "3.0.8" % Provided + "org.scalatest" %% "scalatest" % "3.1.2" % Provided ) diff --git a/xml-scalatest/src/test/scala/software/purpledragon/xml/scalatest/XmlMatchersSpec.scala b/xml-scalatest/src/test/scala/software/purpledragon/xml/scalatest/XmlMatchersSpec.scala index b4969a8..31538d4 100644 --- a/xml-scalatest/src/test/scala/software/purpledragon/xml/scalatest/XmlMatchersSpec.scala +++ b/xml-scalatest/src/test/scala/software/purpledragon/xml/scalatest/XmlMatchersSpec.scala @@ -16,10 +16,11 @@ package software.purpledragon.xml.scalatest -import org.scalatest.{FlatSpec, Matchers} +import org.scalatest.flatspec.AnyFlatSpec +import org.scalatest.matchers.should.Matchers import software.purpledragon.xml.compare.options.DiffOptions -class XmlMatchersSpec extends FlatSpec with Matchers with XmlMatchers { +class XmlMatchersSpec extends AnyFlatSpec with Matchers with XmlMatchers { "beXml(xml)" should "match identical XML" in { val matcher = beXml(text) diff --git a/xml-specs2/build.sbt b/xml-specs2/build.sbt index e907227..accc974 100644 --- a/xml-specs2/build.sbt +++ b/xml-specs2/build.sbt @@ -1,5 +1,5 @@ name := "xml-specs2" libraryDependencies ++= Seq( - "org.specs2" %% "specs2-core" % "4.7.0" % Provided + "org.specs2" %% "specs2-core" % "4.9.4" % Provided ) From c3b31357e22d4824799a1f87354db81018e63902 Mon Sep 17 00:00:00 2001 From: Michael Stringer Date: Sun, 7 Jun 2020 11:12:24 +0100 Subject: [PATCH 5/7] Bump scala-xml version --- build.sbt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sbt b/build.sbt index c820542..1a2575c 100644 --- a/build.sbt +++ b/build.sbt @@ -24,7 +24,7 @@ inThisBuild( scalacOptions ++= Seq(s"-target:jvm-$javaVersion", "-deprecation", "-feature", "-unchecked"), // dependencies common for all sub-projects libraryDependencies ++= Seq( - "org.scala-lang.modules" %% "scala-xml" % "1.2.0" + "org.scala-lang.modules" %% "scala-xml" % "1.3.0" ), )) From e3c8d733120b4b75c332844da7de56d551d8d216 Mon Sep 17 00:00:00 2001 From: Michael Stringer Date: Sun, 7 Jun 2020 11:20:17 +0100 Subject: [PATCH 6/7] Update sbt plugins --- project/plugins.sbt | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/project/plugins.sbt b/project/plugins.sbt index 75f26a9..5def8fc 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,17 +1,17 @@ // code style addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "1.0.0") -addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.6.0") -addSbtPlugin("com.lucidchart" % "sbt-scalafmt" % "1.15") -addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.0.0") +addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.6.1") +addSbtPlugin("com.lucidchart" % "sbt-scalafmt" % "1.16") +addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.6.0") // artifact publishing -addSbtPlugin("org.foundweekends" % "sbt-bintray" % "0.5.4") -addSbtPlugin("com.jsuereth" % "sbt-pgp" % "2.0.0") -addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.11") +addSbtPlugin("org.foundweekends" % "sbt-bintray" % "0.5.6") +addSbtPlugin("com.jsuereth" % "sbt-pgp" % "2.0.1") +addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.13") // documentation -addSbtPlugin("com.eed3si9n" % "sbt-unidoc" % "0.4.2") +addSbtPlugin("com.eed3si9n" % "sbt-unidoc" % "0.4.3") addSbtPlugin("com.typesafe.sbt" % "sbt-ghpages" % "0.6.3") addSbtPlugin("com.typesafe.sbt" % "sbt-site" % "1.4.0") -addSbtPlugin("com.lightbend.paradox" % "sbt-paradox" % "0.6.5") +addSbtPlugin("com.lightbend.paradox" % "sbt-paradox" % "0.8.0") addSbtPlugin("com.thoughtworks.sbt-api-mappings" % "sbt-api-mappings" % "3.0.0") From 38f057bbfaa4242ca1be8b661190c10854d214fc Mon Sep 17 00:00:00 2001 From: Michael Stringer Date: Sun, 7 Jun 2020 12:01:54 +0100 Subject: [PATCH 7/7] Add tests for DiffOptions --- .../xml/compare/options/DiffOptions.scala | 16 ++++ .../xml/compare/options/DiffOptionsSpec.scala | 83 +++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 xml-compare/src/test/scala/software/purpledragon/xml/compare/options/DiffOptionsSpec.scala diff --git a/xml-compare/src/main/scala/software/purpledragon/xml/compare/options/DiffOptions.scala b/xml-compare/src/main/scala/software/purpledragon/xml/compare/options/DiffOptions.scala index 93b5004..3c18302 100644 --- a/xml-compare/src/main/scala/software/purpledragon/xml/compare/options/DiffOptions.scala +++ b/xml-compare/src/main/scala/software/purpledragon/xml/compare/options/DiffOptions.scala @@ -1,3 +1,19 @@ +/* + * Copyright 2017 Michael Stringer + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package software.purpledragon.xml.compare.options object DiffOptions { diff --git a/xml-compare/src/test/scala/software/purpledragon/xml/compare/options/DiffOptionsSpec.scala b/xml-compare/src/test/scala/software/purpledragon/xml/compare/options/DiffOptionsSpec.scala new file mode 100644 index 0000000..e7e9ad0 --- /dev/null +++ b/xml-compare/src/test/scala/software/purpledragon/xml/compare/options/DiffOptionsSpec.scala @@ -0,0 +1,83 @@ +/* + * Copyright 2017 Michael Stringer + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package software.purpledragon.xml.compare.options + +import org.scalatest.flatspec.AnyFlatSpec +import org.scalatest.matchers.should.Matchers + +class DiffOptionsSpec extends AnyFlatSpec with Matchers { + + "&" should "add an option" in { + val options = DiffOptions(DiffOption.IgnoreNamespace) & DiffOption.IgnoreChildOrder + options.options shouldBe Set(DiffOption.IgnoreNamespace, DiffOption.IgnoreChildOrder) + } + + it should "not add a duplicate option" in { + val options = DiffOptions(DiffOption.IgnoreNamespace) & DiffOption.IgnoreNamespace + options.options shouldBe Set(DiffOption.IgnoreNamespace) + } + + "&!" should "remove an option" in { + val options = DiffOptions(DiffOption.IgnoreNamespace, DiffOption.IgnoreChildOrder) &! DiffOption.IgnoreChildOrder + options.options shouldBe Set(DiffOption.IgnoreNamespace) + } + + it should "do nothing if option not present" in { + val options = DiffOptions(DiffOption.IgnoreNamespace) &! DiffOption.IgnoreChildOrder + options.options shouldBe Set(DiffOption.IgnoreNamespace) + } + + "+" should "add an option" in { + val options = DiffOptions(DiffOption.IgnoreNamespace) + DiffOption.IgnoreChildOrder + options.options shouldBe Set(DiffOption.IgnoreNamespace, DiffOption.IgnoreChildOrder) + } + + it should "not add a duplicate option" in { + val options = DiffOptions(DiffOption.IgnoreNamespace) + DiffOption.IgnoreNamespace + options.options shouldBe Set(DiffOption.IgnoreNamespace) + } + + "-" should "remove an option" in { + val options = DiffOptions(DiffOption.IgnoreNamespace, DiffOption.IgnoreChildOrder) - DiffOption.IgnoreChildOrder + options.options shouldBe Set(DiffOption.IgnoreNamespace) + } + + it should "do nothing if option not present" in { + val options = DiffOptions(DiffOption.IgnoreNamespace) - DiffOption.IgnoreChildOrder + options.options shouldBe Set(DiffOption.IgnoreNamespace) + } + + "isEnabled" should "return true if an option is enabled" in { + val options = DiffOptions(DiffOption.IgnoreNamespace) + options.isEnabled(DiffOption.IgnoreNamespace) shouldBe true + } + + it should "return false if an option is disabled" in { + val options = DiffOptions.empty + options.isEnabled(DiffOption.IgnoreNamespace) shouldBe false + } + + "isDisabled" should "return true if an option is disabled" in { + val options = DiffOptions(DiffOption.IgnoreNamespace) + options.isDisabled(DiffOption.IgnoreNamespace) shouldBe false + } + + it should "return false if an option is enabled" in { + val options = DiffOptions.empty + options.isDisabled(DiffOption.IgnoreNamespace) shouldBe true + } +}