| 1 |
.\" -*- mode: troff; coding: utf-8 -*- |
| 2 |
.\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45) |
| 3 |
.\" |
| 4 |
.\" Standard preamble: |
| 5 |
.\" ======================================================================== |
| 6 |
.de Sp \" Vertical space (when we can't use .PP) |
| 7 |
.if t .sp .5v |
| 8 |
.if n .sp |
| 9 |
.. |
| 10 |
.de Vb \" Begin verbatim text |
| 11 |
.ft CW |
| 12 |
.nf |
| 13 |
.ne \\$1 |
| 14 |
.. |
| 15 |
.de Ve \" End verbatim text |
| 16 |
.ft R |
| 17 |
.fi |
| 18 |
.. |
| 19 |
.\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. |
| 20 |
.ie n \{\ |
| 21 |
. ds C` "" |
| 22 |
. ds C' "" |
| 23 |
'br\} |
| 24 |
.el\{\ |
| 25 |
. ds C` |
| 26 |
. ds C' |
| 27 |
'br\} |
| 28 |
.\" |
| 29 |
.\" Escape single quotes in literal strings from groff's Unicode transform. |
| 30 |
.ie \n(.g .ds Aq \(aq |
| 31 |
.el .ds Aq ' |
| 32 |
.\" |
| 33 |
.\" If the F register is >0, we'll generate index entries on stderr for |
| 34 |
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index |
| 35 |
.\" entries marked with X<> in POD. Of course, you'll have to process the |
| 36 |
.\" output yourself in some meaningful fashion. |
| 37 |
.\" |
| 38 |
.\" Avoid warning from groff about undefined register 'F'. |
| 39 |
.de IX |
| 40 |
.. |
| 41 |
.nr rF 0 |
| 42 |
.if \n(.g .if rF .nr rF 1 |
| 43 |
.if (\n(rF:(\n(.g==0)) \{\ |
| 44 |
. if \nF \{\ |
| 45 |
. de IX |
| 46 |
. tm Index:\\$1\t\\n%\t"\\$2" |
| 47 |
.. |
| 48 |
. if !\nF==2 \{\ |
| 49 |
. nr % 0 |
| 50 |
. nr F 2 |
| 51 |
. \} |
| 52 |
. \} |
| 53 |
.\} |
| 54 |
.rr rF |
| 55 |
.\" ======================================================================== |
| 56 |
.\" |
| 57 |
.IX Title "Test2::Compare::Delta 3perl" |
| 58 |
.TH Test2::Compare::Delta 3perl 2025-11-16 "perl v5.40.1" "Perl Programmers Reference Guide" |
| 59 |
.\" For nroff, turn off justification. Always turn off hyphenation; it makes |
| 60 |
.\" way too many mistakes in technical documents. |
| 61 |
.if n .ad l |
| 62 |
.nh |
| 63 |
.SH NAME |
| 64 |
Test2::Compare::Delta \- Representation of differences between nested data |
| 65 |
structures. |
| 66 |
.SH DESCRIPTION |
| 67 |
.IX Header "DESCRIPTION" |
| 68 |
This is used by Test2::Compare. When data structures are compared a |
| 69 |
delta will be returned. Deltas are a tree data structure that represent all the |
| 70 |
differences between two other data structures. |
| 71 |
.SH METHODS |
| 72 |
.IX Header "METHODS" |
| 73 |
.SS "CLASS METHODS" |
| 74 |
.IX Subsection "CLASS METHODS" |
| 75 |
.ie n .IP "$class\->add_column($NAME => sub { ... })" 4 |
| 76 |
.el .IP "\f(CW$class\fR\->add_column($NAME => sub { ... })" 4 |
| 77 |
.IX Item "$class->add_column($NAME => sub { ... })" |
| 78 |
.PD 0 |
| 79 |
.ie n .IP "$class\->add_column($NAME, %PARAMS)" 4 |
| 80 |
.el .IP "\f(CW$class\fR\->add_column($NAME, \f(CW%PARAMS\fR)" 4 |
| 81 |
.IX Item "$class->add_column($NAME, %PARAMS)" |
| 82 |
.PD |
| 83 |
This can be used to add columns to the table that it produced when a comparison |
| 84 |
fails. The first argument should always be the column name, which must be |
| 85 |
unique. |
| 86 |
.Sp |
| 87 |
The first form simply takes a coderef that produces the value that should be |
| 88 |
displayed in the column for any given delta. The arguments passed into the sub |
| 89 |
are the delta, and the row ID. |
| 90 |
.Sp |
| 91 |
.Vb 6 |
| 92 |
\& Test2::Compare::Delta\->add_column( |
| 93 |
\& Foo => sub { |
| 94 |
\& my ($delta, $id) = @_; |
| 95 |
\& return $delta\->... ? \*(Aqfoo\*(Aq : \*(Aqbar\*(Aq |
| 96 |
\& }, |
| 97 |
\& ); |
| 98 |
.Ve |
| 99 |
.Sp |
| 100 |
The second form allows you some extra options. The \f(CW\*(Aqvalue\*(Aq\fR key is required, |
| 101 |
and must be a coderef. All other keys are optional. |
| 102 |
.Sp |
| 103 |
.Vb 6 |
| 104 |
\& Test2::Compare::Delta\->add_column( |
| 105 |
\& \*(AqFoo\*(Aq, # column name |
| 106 |
\& value => sub { ... }, # how to get the cell value |
| 107 |
\& alias => \*(AqFOO\*(Aq, # Display name (used in table header) |
| 108 |
\& no_collapse => $bool, # Show column even if it has no values? |
| 109 |
\& ); |
| 110 |
.Ve |
| 111 |
.ie n .IP "$bool = $class\->remove_column($NAME)" 4 |
| 112 |
.el .IP "\f(CW$bool\fR = \f(CW$class\fR\->remove_column($NAME)" 4 |
| 113 |
.IX Item "$bool = $class->remove_column($NAME)" |
| 114 |
This will remove the specified column. This will return true if the column |
| 115 |
existed and was removed. This will return false if the column did not exist. No |
| 116 |
exceptions are thrown. If a missing column is a problem then you need to check |
| 117 |
the return yourself. |
| 118 |
.ie n .IP "$class\->set_column_alias($NAME, $ALIAS)" 4 |
| 119 |
.el .IP "\f(CW$class\fR\->set_column_alias($NAME, \f(CW$ALIAS\fR)" 4 |
| 120 |
.IX Item "$class->set_column_alias($NAME, $ALIAS)" |
| 121 |
This can be used to change the table header, overriding the default column |
| 122 |
names with new ones. |
| 123 |
.SS ATTRIBUTES |
| 124 |
.IX Subsection "ATTRIBUTES" |
| 125 |
.ie n .IP "$bool = $delta\->verified" 4 |
| 126 |
.el .IP "\f(CW$bool\fR = \f(CW$delta\fR\->verified" 4 |
| 127 |
.IX Item "$bool = $delta->verified" |
| 128 |
.PD 0 |
| 129 |
.ie n .IP $delta\->set_verified($bool) 4 |
| 130 |
.el .IP \f(CW$delta\fR\->set_verified($bool) 4 |
| 131 |
.IX Item "$delta->set_verified($bool)" |
| 132 |
.PD |
| 133 |
This will be true if the delta itself matched, if the delta matched then the |
| 134 |
problem is in the delta's children, not the delta itself. |
| 135 |
.ie n .IP "$aref = $delta\->id" 4 |
| 136 |
.el .IP "\f(CW$aref\fR = \f(CW$delta\fR\->id" 4 |
| 137 |
.IX Item "$aref = $delta->id" |
| 138 |
.PD 0 |
| 139 |
.ie n .IP "$delta\->set_id([$type, $name])" 4 |
| 140 |
.el .IP "\f(CW$delta\fR\->set_id([$type, \f(CW$name\fR])" 4 |
| 141 |
.IX Item "$delta->set_id([$type, $name])" |
| 142 |
.PD |
| 143 |
ID for the delta, used to produce the path into the data structure. An |
| 144 |
example is \f(CW\*(C`[\*(AqHASH\*(Aq => \*(Aqfoo\*(Aq]\*(C'\fR which means the delta is in the path |
| 145 |
\&\f(CW\*(C`...\->{\*(Aqfoo\*(Aq}\*(C'\fR. Valid types are \f(CW\*(C`HASH\*(C'\fR, \f(CW\*(C`ARRAY\*(C'\fR, \f(CW\*(C`SCALAR\*(C'\fR, \f(CW\*(C`META\*(C'\fR, and |
| 146 |
\&\f(CW\*(C`METHOD\*(C'\fR. |
| 147 |
.ie n .IP "$val = $delta\->got" 4 |
| 148 |
.el .IP "\f(CW$val\fR = \f(CW$delta\fR\->got" 4 |
| 149 |
.IX Item "$val = $delta->got" |
| 150 |
.PD 0 |
| 151 |
.ie n .IP $delta\->set_got($val) 4 |
| 152 |
.el .IP \f(CW$delta\fR\->set_got($val) 4 |
| 153 |
.IX Item "$delta->set_got($val)" |
| 154 |
.PD |
| 155 |
Deltas are produced by comparing a received data structure 'got' against a |
| 156 |
check data structure 'check'. The 'got' attribute contains the value that was |
| 157 |
received for comparison. |
| 158 |
.ie n .IP "$check = $delta\->chk" 4 |
| 159 |
.el .IP "\f(CW$check\fR = \f(CW$delta\fR\->chk" 4 |
| 160 |
.IX Item "$check = $delta->chk" |
| 161 |
.PD 0 |
| 162 |
.ie n .IP "$check = $delta\->check" 4 |
| 163 |
.el .IP "\f(CW$check\fR = \f(CW$delta\fR\->check" 4 |
| 164 |
.IX Item "$check = $delta->check" |
| 165 |
.ie n .IP $delta\->set_chk($check) 4 |
| 166 |
.el .IP \f(CW$delta\fR\->set_chk($check) 4 |
| 167 |
.IX Item "$delta->set_chk($check)" |
| 168 |
.ie n .IP $delta\->set_check($check) 4 |
| 169 |
.el .IP \f(CW$delta\fR\->set_check($check) 4 |
| 170 |
.IX Item "$delta->set_check($check)" |
| 171 |
.PD |
| 172 |
Deltas are produced by comparing a received data structure 'got' against a |
| 173 |
check data structure 'check'. The 'check' attribute contains the value that was |
| 174 |
expected in the comparison. |
| 175 |
.Sp |
| 176 |
\&\f(CW\*(C`check\*(C'\fR and \f(CW\*(C`chk\*(C'\fR are aliases for the same attribute. |
| 177 |
.ie n .IP "$aref = $delta\->children" 4 |
| 178 |
.el .IP "\f(CW$aref\fR = \f(CW$delta\fR\->children" 4 |
| 179 |
.IX Item "$aref = $delta->children" |
| 180 |
.PD 0 |
| 181 |
.ie n .IP "$delta\->set_children([$delta1, $delta2, ...])" 4 |
| 182 |
.el .IP "\f(CW$delta\fR\->set_children([$delta1, \f(CW$delta2\fR, ...])" 4 |
| 183 |
.IX Item "$delta->set_children([$delta1, $delta2, ...])" |
| 184 |
.PD |
| 185 |
A Delta may have child deltas. If it does then this is an arrayref with those |
| 186 |
children. |
| 187 |
.ie n .IP "$dne = $delta\->dne" 4 |
| 188 |
.el .IP "\f(CW$dne\fR = \f(CW$delta\fR\->dne" 4 |
| 189 |
.IX Item "$dne = $delta->dne" |
| 190 |
.PD 0 |
| 191 |
.ie n .IP $delta\->set_dne($dne) 4 |
| 192 |
.el .IP \f(CW$delta\fR\->set_dne($dne) 4 |
| 193 |
.IX Item "$delta->set_dne($dne)" |
| 194 |
.PD |
| 195 |
Sometimes a comparison results in one side or the other not existing at all, in |
| 196 |
which case this is set to the name of the attribute that does not exist. This |
| 197 |
can be set to 'got' or 'check'. |
| 198 |
.ie n .IP "$e = $delta\->exception" 4 |
| 199 |
.el .IP "\f(CW$e\fR = \f(CW$delta\fR\->exception" 4 |
| 200 |
.IX Item "$e = $delta->exception" |
| 201 |
.PD 0 |
| 202 |
.ie n .IP $delta\->set_exception($e) 4 |
| 203 |
.el .IP \f(CW$delta\fR\->set_exception($e) 4 |
| 204 |
.IX Item "$delta->set_exception($e)" |
| 205 |
.PD |
| 206 |
This will be set to the exception in cases where the comparison failed due to |
| 207 |
an exception being thrown. |
| 208 |
.SS OTHER |
| 209 |
.IX Subsection "OTHER" |
| 210 |
.ie n .IP "$string = $delta\->render_got" 4 |
| 211 |
.el .IP "\f(CW$string\fR = \f(CW$delta\fR\->render_got" 4 |
| 212 |
.IX Item "$string = $delta->render_got" |
| 213 |
Renders the string that should be used in a table to represent the received |
| 214 |
value in a comparison. |
| 215 |
.ie n .IP "$string = $delta\->render_check" 4 |
| 216 |
.el .IP "\f(CW$string\fR = \f(CW$delta\fR\->render_check" 4 |
| 217 |
.IX Item "$string = $delta->render_check" |
| 218 |
Renders the string that should be used in a table to represent the expected |
| 219 |
value in a comparison. |
| 220 |
.ie n .IP "$bool = $delta\->should_show" 4 |
| 221 |
.el .IP "\f(CW$bool\fR = \f(CW$delta\fR\->should_show" 4 |
| 222 |
.IX Item "$bool = $delta->should_show" |
| 223 |
This will return true if the delta should be shown in the table. This is |
| 224 |
normally true for any unverified delta. This will also be true for deltas that |
| 225 |
contain extra useful debug information. |
| 226 |
.ie n .IP "$aref = $delta\->filter_visible" 4 |
| 227 |
.el .IP "\f(CW$aref\fR = \f(CW$delta\fR\->filter_visible" 4 |
| 228 |
.IX Item "$aref = $delta->filter_visible" |
| 229 |
This will produce an arrayref of \f(CW\*(C`[ $path => $delta ]\*(C'\fR for all deltas that |
| 230 |
should be displayed in the table. |
| 231 |
.ie n .IP "$aref = $delta\->table_header" 4 |
| 232 |
.el .IP "\f(CW$aref\fR = \f(CW$delta\fR\->table_header" 4 |
| 233 |
.IX Item "$aref = $delta->table_header" |
| 234 |
This returns an array ref of the headers for the table. |
| 235 |
.ie n .IP "$string = $delta\->table_op" 4 |
| 236 |
.el .IP "\f(CW$string\fR = \f(CW$delta\fR\->table_op" 4 |
| 237 |
.IX Item "$string = $delta->table_op" |
| 238 |
This returns the operator that should be shown in the table. |
| 239 |
.ie n .IP "$string = $delta\->table_check_lines" 4 |
| 240 |
.el .IP "\f(CW$string\fR = \f(CW$delta\fR\->table_check_lines" 4 |
| 241 |
.IX Item "$string = $delta->table_check_lines" |
| 242 |
This returns the defined lines (extra debug info) that should be displayed. |
| 243 |
.ie n .IP "$string = $delta\->table_got_lines" 4 |
| 244 |
.el .IP "\f(CW$string\fR = \f(CW$delta\fR\->table_got_lines" 4 |
| 245 |
.IX Item "$string = $delta->table_got_lines" |
| 246 |
This returns the generated lines (extra debug info) that should be displayed. |
| 247 |
.ie n .IP "$aref = $delta\->table_rows" 4 |
| 248 |
.el .IP "\f(CW$aref\fR = \f(CW$delta\fR\->table_rows" 4 |
| 249 |
.IX Item "$aref = $delta->table_rows" |
| 250 |
This returns an arrayref of table rows, each row is itself an arrayref. |
| 251 |
.ie n .IP "@table_lines = $delta\->table" 4 |
| 252 |
.el .IP "\f(CW@table_lines\fR = \f(CW$delta\fR\->table" 4 |
| 253 |
.IX Item "@table_lines = $delta->table" |
| 254 |
Returns all the lines of the table that should be displayed. |
| 255 |
.SH SOURCE |
| 256 |
.IX Header "SOURCE" |
| 257 |
The source code repository for Test2\-Suite can be found at |
| 258 |
\&\fIhttps://github.com/Test\-More/Test2\-Suite/\fR. |
| 259 |
.SH MAINTAINERS |
| 260 |
.IX Header "MAINTAINERS" |
| 261 |
.IP "Chad Granum <[email protected]>" 4 |
| 262 |
.IX Item "Chad Granum <[email protected]>" |
| 263 |
.SH AUTHORS |
| 264 |
.IX Header "AUTHORS" |
| 265 |
.PD 0 |
| 266 |
.IP "Chad Granum <[email protected]>" 4 |
| 267 |
.IX Item "Chad Granum <[email protected]>" |
| 268 |
.PD |
| 269 |
.SH COPYRIGHT |
| 270 |
.IX Header "COPYRIGHT" |
| 271 |
Copyright 2018 Chad Granum <[email protected]>. |
| 272 |
.PP |
| 273 |
This program is free software; you can redistribute it and/or |
| 274 |
modify it under the same terms as Perl itself. |
| 275 |
.PP |
| 276 |
See \fIhttp://dev.perl.org/licenses/\fR |