Skip to content

Commit ab3240e

Browse files
committed
Update docs with new options
1 parent 1d82def commit ab3240e

File tree

2 files changed

+52
-17
lines changed

2 files changed

+52
-17
lines changed

src/main/paradox/comparing-xml.md

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Comparing XML
22

33
A simple XML comparison can be performed using
4-
@scaladoc[`XmlCompare.compare`](software.purpledragon.xml.compare.XmlCompare$):
4+
@scaladoc[XmlCompare.compare](software.purpledragon.xml.compare.XmlCompare$):
55

66
```scala
77
// using XML literals:
@@ -11,8 +11,8 @@ val result = XmlCompare.compare(<test/>, <test/>) // == XmlEqual
1111
val success = XmlCompare.compare(<result><success/></result>, XML.loadFile("result.xml"))
1212
```
1313

14-
The way that XML is compared can be customised by supplying a `Set` of
15-
@scaladoc[`DiffOption`s](software.purpledragon.xml.compare.options.DiffOption$):
14+
The way that XML is compared can be customised by supplying
15+
@scaladoc[DiffOptions](software.purpledragon.xml.compare.options.DiffOptions):
1616

1717
```scala
1818
// this would result an XmlEqual
@@ -24,16 +24,16 @@ XmlCompare.compare(
2424
XmlCompare.compare(
2525
<test name="John" age="45"/>,
2626
<test age="45" name="John"/>,
27-
Set(DiffOption.StrictAttributeOrdering))
27+
DiffOptions(DiffOption.StrictAttributeOrdering))
2828
```
2929

3030
@ref:[Comparison Options](#comparison-options) contains details of the supported options.
3131

3232
## Comparison Results
3333

34-
`XmlCompare.compare` returns an @scaladoc[`XmlDiff`](software.purpledragon.xml.compare.XmlDiff) that will either be
35-
@scaladoc[`XmlEqual`](software.purpledragon.xml.compare.XmlEqual) or a detailed
36-
@scaladoc[`XmlDiffers`](software.purpledragon.xml.compare.XmlDiffers). If a simple
34+
`XmlCompare.compare` returns an @scaladoc[XmlDiff](software.purpledragon.xml.compare.XmlDiff) that will either be
35+
@scaladoc[XmlEqual](software.purpledragon.xml.compare.XmlEqual) or a detailed
36+
@scaladoc[XmlDiffers](software.purpledragon.xml.compare.XmlDiffers). If a simple
3737
pass/fail check is required then the `isEqual` method can be called on the result.
3838

3939
### XmlEqual
@@ -59,16 +59,33 @@ XmlDiffers(
5959

6060
## Comparison Options
6161

62-
By default the following options are used:
62+
### Building Options
63+
64+
Options can built by either passing them into
65+
@scaladoc[DiffOptions()](software.purpledragon.xml.compare.options.DiffOptions)) or by combining them:
66+
67+
```scala
68+
// these two are equivalent:
69+
DiffOptions(DiffOption.IgnoreNamespacePrefix, DiffOption.IgnoreNamespace)
70+
DiffOptions(DiffOption.IgnoreNamespacePrefix) & DiffOption.IgnoreNamespace
71+
```
72+
73+
74+
### Default Options
75+
76+
The default options (unspecified or
77+
@scaladoc[DiffOptions.default](software.purpledragon.xml.compare.options.DiffOptions$)) are:
6378

6479
* `IgnoreNamespacePrefix`
6580

66-
### IgnoreNamespacePrefix
81+
### Available Options
82+
83+
#### IgnoreNamespacePrefix
6784

6885
If enabled the prefixes associated with namespaces will be ignored. Differing namespaces will still cause a comparison
6986
error.
7087

71-
#### Example
88+
##### Example
7289

7390
This:
7491
```xml
@@ -80,11 +97,11 @@ would be considered equal to:
8097
<f:example xmlns:f="http://example.com">5</f:example>
8198
```
8299

83-
### IgnoreNamespace
100+
#### IgnoreNamespace
84101

85102
If enabled then namespaces will be ignored completely.
86103

87-
#### Example
104+
##### Example
88105

89106
This:
90107
```xml
@@ -96,12 +113,12 @@ would be considered equal to:
96113
<f:example xmlns:f="http://example.org">5</f:example>
97114
```
98115

99-
### StrictAttributeOrdering
116+
#### StrictAttributeOrdering
100117

101118
This adds an additional comparison on the ordering of element attributes. The presence of attributes will be checked
102119
_before_ the ordering.
103120

104-
#### Example
121+
##### Example
105122

106123
This:
107124

@@ -126,14 +143,14 @@ XmlDiffers(
126143
)
127144
```
128145

129-
### IgnoreChildOrder
146+
#### IgnoreChildOrder
130147

131148
If enabled the ordering of child elements will be ignored. This is handled by re-ordering child nodes using an arbitrary
132149
sorting algorithm before comparing them.
133150

134151
_Note: the first difference returned may be different if this option is enabled._
135152

136-
#### Example 1
153+
##### Example 1
137154

138155
This:
139156

@@ -152,7 +169,7 @@ would be considered equal to:
152169
</example>
153170
```
154171

155-
#### Example 2
172+
##### Example 2
156173

157174
This:
158175

xml-compare/src/main/scala/software/purpledragon/xml/compare/options/DiffOptions.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,36 @@ object DiffOptions {
2525
* - [[DiffOption.IgnoreNamespacePrefix IgnoreNamespacePrefix]]
2626
*/
2727
val default: DiffOptions = DiffOptions(DiffOption.IgnoreNamespacePrefix)
28+
29+
/**
30+
* Empty set of [[DiffOption DiffOption]]s.
31+
*/
2832
val empty: DiffOptions = DiffOptions()
2933

34+
/**
35+
* Creates a `DiffOptions` with the supplied list of [[DiffOption DiffOption]]s.
36+
*/
3037
def apply(options: DiffOption.DiffOption*): DiffOptions = DiffOptions(options.toSet)
3138
}
3239

40+
/**
41+
* Collection of [[DiffOption DiffOption]]s to control XML comparison.
42+
*
43+
* @param options set of enabled options.
44+
*/
3345
case class DiffOptions(options: Set[DiffOption.DiffOption]) {
46+
/** Creates a new `DiffOptions` with the supplied option added. */
3447
def &(option: DiffOption.DiffOption): DiffOptions = copy(options = options + option)
48+
/** Creates a new `DiffOptions` with the supplied option removed. */
3549
def &!(option: DiffOption.DiffOption): DiffOptions = copy(options = options - option)
3650

51+
/** Creates a new `DiffOptions` with the supplied option added. */
3752
def +(option: DiffOption.DiffOption): DiffOptions = copy(options = options + option)
53+
/** Creates a new `DiffOptions` with the supplied option removed. */
3854
def -(option: DiffOption.DiffOption): DiffOptions = copy(options = options - option)
3955

56+
/** Tests whether the supplied option is enabled. */
4057
def isEnabled(option: DiffOption.DiffOption): Boolean = options.contains(option)
58+
/** Tests whether the supplied option is disabled. */
4159
def isDisabled(option: DiffOption.DiffOption): Boolean = !options.contains(option)
4260
}

0 commit comments

Comments
 (0)