You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**Special case for `<style>`-tags:** Even if the whitespace option is `Normalize`, whitespace inside quotes (`"` and `'` style quotes) is preserved as is. For example, the text inside the `content` style information in the following CSS will not be normalized: `p::after { content: " -.- "; }`.
98
-
99
-
**Special case for `<script>`-tags:** It is on the issues list to deal with whitespace properly inside `<script>`-tags.
97
+
**NOTE:** It is on the issues list to deal with whitespace properly inside `<style>` and `<script>`-tags, e.g. inside strings.
100
98
101
99
#### Perform case-_insensitve_ text comparison
102
100
To compare the text in two text nodes to eachother using a case-insensitive comparison, call the `IgnoreCase()` method on a `DiffBuilder` instance, e.g.:
@@ -159,6 +157,71 @@ var diffs = DiffBuilder
159
157
.Build();
160
158
```
161
159
160
+
### Attr Compare options
161
+
The library supports various ways to perform attribute comparison.
162
+
163
+
#### Strict name and value comparison
164
+
The *"name and value comparison"* is the base comparison option, and that will test if both the names and the values of the control and test attributes are equal. E.g.:
165
+
166
+
-`attr="foo"` is the same as `attr="foo"`
167
+
-`attr="foo"` is the NOT same as `attr="bar"`
168
+
-`foo="attr"` is the NOT same as `bar="attr"`
169
+
170
+
This comparison mode is on by default.
171
+
172
+
#### RegEx attribute value comparer
173
+
It is possible to specify a regular expression in the control attributes value, and add the `:regex` postfix to the *control* attributes name, to have the comparison performed using a Regex match test. E.g.
174
+
175
+
-`attr:regex="foo-\d{4}"` is the same as `attr="foo-2019"`
176
+
177
+
#### Ignore case attribute value comparer
178
+
To get the comparer to perform a case insensitive comparison of the values of the control and test attribute, add the `:ignoreCase` postfix to the *control* attributes name. E.g.
179
+
180
+
-`attr:ignoreCase="FOO"` is the same as `attr="foo"`
181
+
182
+
#### Combine ignore case and regex attribute value comparer
183
+
To perform a case insenstive regular expression match, combine `:ignoreCase` and `:regex` as a postfix to the *control* attributes name. The order you combine them does not matter. E.g.
184
+
185
+
-`attr:ignoreCase:regex="FOO-\d{4}"` is the same as `attr="foo-2019"`
186
+
-`attr:regex:ignoreCase="FOO-\d{4}"` is the same as `attr="foo-2019"`
187
+
188
+
#### Class attribute comparer
189
+
The class attribute is special in HTML. It can contain a space separated list of CSS classes, whoes order does not matter. Therefor the library will ignore the order the CSS classes is specified in the class attribute of the control and test elements, and instead just ensure that both have the same CSS classes added to it. E.g.
190
+
191
+
-`class="foo bar"` is the same as `class="bar foo"`
192
+
193
+
To enable the special handling of the class attribute, call the `WithClassAttributeComparer()` on a `DiffBuilder` instance, e.g.:
194
+
195
+
```csharp
196
+
vardiffs=DiffBuilder
197
+
.Compare(controlHtml)
198
+
.WithTest(testHtml)
199
+
.WithClassAttributeComparer()
200
+
.Build();
201
+
```
202
+
203
+
#### Boolean attributes comparer
204
+
Another special type of attributes are the [boolean attributes](https://www.w3.org/TR/html52/infrastructure.html#sec-boolean-attributes). To make comparing these more forgiving, the boolean attribute comparer will consider two boolean attributes equal, according to these rules:
205
+
206
+
- In **strict** mode, a boolean attribute's value is considered truthy if the value is missing, empty, or is the name of the attribute.
207
+
- In **loose** mode, a boolean attribute's value is considered truthy if the attribute is present on an element.
208
+
209
+
For example, in **strict** mode, the following are considered equal:
210
+
211
+
-`required` is the same as `required=""`
212
+
-`required=""` is the same as `required="required"`
213
+
-`required="required"` is the same as `required="required"`
214
+
215
+
To enable the special handling of boolean attributes, call the `WithBooleanAttributeComparer(BooleanAttributeComparision.Strict)` or `WithBooleanAttributeComparer(BooleanAttributeComparision.Loose)` on a `DiffBuilder` instance, e.g.:
Any attributes that starts with `diff:` are automatically filtered out before matching/comparing happens. E.g. `diff:whitespace="..."` does not show up as a missing diff when added to an control element.
0 commit comments