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