https://github.com/andyglow/scala-xml-diff
Scala XML Diff
https://github.com/andyglow/scala-xml-diff
Last synced: about 1 year ago
JSON representation
Scala XML Diff
- Host: GitHub
- URL: https://github.com/andyglow/scala-xml-diff
- Owner: andyglow
- License: lgpl-3.0
- Created: 2014-12-16T13:00:53.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2022-06-13T19:18:57.000Z (about 4 years ago)
- Last Synced: 2025-03-29T18:36:29.389Z (about 1 year ago)
- Language: Scala
- Size: 87.9 KB
- Stars: 9
- Watchers: 5
- Forks: 7
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: COPYING
Awesome Lists containing this project
README
# Scala XML Diff
[](https://cloud.drone.io/andyglow/scala-xml-diff)
[](https://codecov.io/gh/andyglow/scala-xml-diff)
[](https://search.maven.org/artifact/com.github.andyglow/scala-xml-diff_2.13/)
[](https://search.maven.org/artifact/com.github.andyglow/scala-xml-diff_3/)
Tool to compare `scala.xml.Node`s with detailed comparison result
## Usage
### build.sbt
```
libraryDependencies += "com.github.andyglow" %% "scala-xml-diff" % ${LATEST_VERSION} % Compile
```
#### Import
```scala
import com.github.andyglow.xml.diff._
```
#### REPL example
```scala
scala> =?=
res0: com.github.andyglow.xml.diff.package.XmlDiff = Eq
scala> =?=
res1: com.github.andyglow.xml.diff.package.XmlDiff = Neq(List(UnequalElem(foo,List(UnequalName(foo,bar)))))
scala> =?=
res2: com.github.andyglow.xml.diff.package.XmlDiff = Neq(List(UnequalElem(foo,List(UnequalAttribute(x,a,b)))))
scala> =?=
res3: com.github.andyglow.xml.diff.package.XmlDiff = Neq(List(
UnequalElem(foo,List(
UnequalElem(bar,List(
UnequalAttribute(key,val1,val2),
AbsentAttribute(key2,val2),
RedundantAttribute(key3,val3)))))))
// not ignoring whitespace
scala> foo =?= foo
res4: com.github.andyglow.xml.diff.package.XmlDiff = Neq(List(
UnequalElem(jaz,List(
AbsentNode(foo),
RedundantNode(foo )))))
// ignoring whitespace
scala> foo =#= foo
res5: com.github.andyglow.xml.diff.package.XmlDiff = Eq
```
#### Scalatest example
```scala
import org.scalatest.xml.XmlMatchers._
```
```scala
"MyRestService" must {
"generate proper xml" in {
val document: xml.NodeSeq = service.call(...)
document should beXml(
Invoice
0.6.2
...
)
}
// it is also possible to match negative scenarios
"be able to distinguish from " in {
should not beXml
}
// you then can match ignoring whitespace
"match not counting leading/trailing whitespaces" in {
x should beXml ( x , ignoreWhitespaces = true)
}
// the same could be done using not beXml
}
```