1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
# Each filter should have access to blocks/block internals.
use Test::Base tests => 20 * 2;
run {};
package Test::Base::Filter;
use Test::More;
sub foo {
my $self = shift;
my $value = shift;
# Test access to Test::Base::Filter object.
ok ref($self),
'$self is an object';
is ref($self),
'Test::Base::Filter',
'$self is a Test:Base::Filter object';
like $value,
qr/^This is some .*text.\z/,
'Filter value is correct';
# Test access to Test::Base::Block object.
my $block = $self->current_block;
is ref($block),
'Test::Base::Block',
'Have a reference to our block object';
ok not($block->is_filtered),
'Block is not completely filtered yet';
my $name = shift || 'One';
is $block->name,
$name,
'name is correct';
my $description = shift || 'One';
is $block->description,
$description,
'description is correct';
my $original = shift || "This is some text.";
is $block->original_values->{xxx},
$original,
'Access to the original value';
my $seq_num = shift || 1;
cmp_ok $block->seq_num,
'==',
$seq_num,
'Sequence number (seq_num) is correct';
my $array_xxx = shift || ["This is some text."];
is_deeply $block->{xxx},
$array_xxx,
'Test raw content of $block->{xxx}';
my $method_xxx = shift || "This is some text.";
is $block->xxx,
$method_xxx,
'Test method content of $block->xxx';
# Test access to Test::Base object.
my $blocks = $block->blocks_object;
my $block_list = $blocks->block_list;
is ref($block_list),
'ARRAY',
'Have an array of all blocks';
is scalar(@$block_list),
'2',
'Is there 2 blocks?';
is $blocks->block_class,
"Test::Base::Block",
'block class';
is $blocks->filter_class,
"Test::Base::Filter",
'filter class';
is_deeply
$blocks->{_filters},
[qw(norm trim)],
'default filters are ok';
is $blocks->block_delim,
'===',
'block delimiter';
is $blocks->data_delim,
'---',
'data delimiter';
my $spec = <<END;
=== One
--- xxx foo: This is some text.
=== Two
This is the 2nd description.
Right here.
--- xxx chomp bar
This is some more text.
END
is $blocks->spec,
$spec,
'spec is ok';
is $block_list->[$seq_num - 1],
$block,
'test block ref in list';
}
sub bar {
my $self = shift;
my $value = shift;
$self->foo($value,
'Two',
"This is the 2nd description.\nRight here.",
"This is some more text.\n\n",
2,
["This is some more text."],
"This is some more text.",
);
}
__END__
=== One
--- xxx foo: This is some text.
=== Two
This is the 2nd description.
Right here.
--- xxx chomp bar
This is some more text.
|