1Test2::Compare::Delta(3U)ser Contributed Perl DocumentatiToenst2::Compare::Delta(3)
2
3
4
6 Test2::Compare::Delta - Representation of differences between nested
7 data structures.
8
10 This is used by Test2::Compare. When data structures are compared a
11 delta will be returned. Deltas are a tree data structure that represent
12 all the differences between two other data structures.
13
15 CLASS METHODS
16 $class->add_column($NAME => sub { ... })
17 $class->add_column($NAME, %PARAMS)
18 This can be used to add columns to the table that it produced when
19 a comparison fails. The first argument should always be the column
20 name, which must be unique.
21
22 The first form simply takes a coderef that produces the value that
23 should be displayed in the column for any given delta. The
24 arguments passed into the sub are the delta, and the row ID.
25
26 Test2::Compare::Delta->add_column(
27 Foo => sub {
28 my ($delta, $id) = @_;
29 return $delta->... ? 'foo' : 'bar'
30 },
31 );
32
33 The second form allows you some extra options. The 'value' key is
34 required, and must be a coderef. All other keys are optional.
35
36 Test2::Compare::Delta->add_column(
37 'Foo', # column name
38 value => sub { ... }, # how to get the cell value
39 alias => 'FOO', # Display name (used in table header)
40 no_collapse => $bool, # Show column even if it has no values?
41 );
42
43 $bool = $class->remove_column($NAME)
44 This will remove the specified column. This will return true if the
45 column existed and was removed. This will return false if the
46 column did not exist. No exceptions are thrown. If a missing column
47 is a problem then you need to check the return yourself.
48
49 $class->set_column_alias($NAME, $ALIAS)
50 This can be used to change the table header, overriding the default
51 column names with new ones.
52
53 ATTRIBUTES
54 $bool = $delta->verified
55 $delta->set_verified($bool)
56 This will be true if the delta itself matched, if the delta matched
57 then the problem is in the delta's children, not the delta itself.
58
59 $aref = $delta->id
60 $delta->set_id([$type, $name])
61 ID for the delta, used to produce the path into the data structure.
62 An example is "['HASH' => 'foo']" which means the delta is in the
63 path "...->{'foo'}". Valid types are "HASH", "ARRAY", "SCALAR",
64 "META", and "METHOD".
65
66 $val = $delta->got
67 $delta->set_got($val)
68 Deltas are produced by comparing a received data structure 'got'
69 against a check data structure 'check'. The 'got' attribute
70 contains the value that was received for comparison.
71
72 $check = $delta->chk
73 $check = $delta->check
74 $delta->set_chk($check)
75 $delta->set_check($check)
76 Deltas are produced by comparing a received data structure 'got'
77 against a check data structure 'check'. The 'check' attribute
78 contains the value that was expected in the comparison.
79
80 "check" and "chk" are aliases for the same attribute.
81
82 $aref = $delta->children
83 $delta->set_children([$delta1, $delta2, ...])
84 A Delta may have child deltas. If it does then this is an arrayref
85 with those children.
86
87 $dne = $delta->dne
88 $delta->set_dne($dne)
89 Sometimes a comparison results in one side or the other not
90 existing at all, in which case this is set to the name of the
91 attribute that does not exist. This can be set to 'got' or 'check'.
92
93 $e = $delta->exception
94 $delta->set_exception($e)
95 This will be set to the exception in cases where the comparison
96 failed due to an exception being thrown.
97
98 OTHER
99 $string = $delta->render_got
100 Renders the string that should be used in a table to represent the
101 received value in a comparison.
102
103 $string = $delta->render_check
104 Renders the string that should be used in a table to represent the
105 expected value in a comparison.
106
107 $bool = $delta->should_show
108 This will return true if the delta should be shown in the table.
109 This is normally true for any unverified delta. This will also be
110 true for deltas that contain extra useful debug information.
111
112 $aref = $delta->filter_visible
113 This will produce an arrayref of "[ $path => $delta ]" for all
114 deltas that should be displayed in the table.
115
116 $aref = $delta->table_header
117 This returns an array ref of the headers for the table.
118
119 $string = $delta->table_op
120 This returns the operator that should be shown in the table.
121
122 $string = $delta->table_check_lines
123 This returns the defined lines (extra debug info) that should be
124 displayed.
125
126 $string = $delta->table_got_lines
127 This returns the generated lines (extra debug info) that should be
128 displayed.
129
130 $aref = $delta->table_rows
131 This returns an arrayref of table rows, each row is itself an
132 arrayref.
133
134 @table_lines = $delta->table
135 Returns all the lines of the table that should be displayed.
136
138 The source code repository for Test2-Suite can be found at
139 https://github.com/Test-More/Test2-Suite/.
140
142 Chad Granum <exodist@cpan.org>
143
145 Chad Granum <exodist@cpan.org>
146
148 Copyright 2018 Chad Granum <exodist@cpan.org>.
149
150 This program is free software; you can redistribute it and/or modify it
151 under the same terms as Perl itself.
152
153 See http://dev.perl.org/licenses/
154
155
156
157perl v5.30.1 2020-01-31 Test2::Compare::Delta(3)