You could make it less repetitive, but looks good apart from that.
#!perl
use strict;
use warnings;
use v5.10.0;
use Test::More tests => "5";
use FindBin qw($Bin);
BEGIN {
use_ok( 'Fancy::Open', qw(fancy_open) )
or die "Fancy::Open is not available\n";
}
diag( "Testing Fancy::Open $Fancy::Open::VERSION, Perl $], $^X" );
my $file = "$Bin/test-open.txt";
my @wanted = qw(
red orange yellow spring green teal cyan azure
blue violet magenta pink white black gray
);
is_deeply(
[ Fancy::Open::fancy_open($file) ],
[ @wanted ],
"testing a plain array"
);
is_deeply(
[ Fancy::Open::fancy_open($file, { 'before' => 'solid ' }) ],
[ map "solid $_", @wanted ],
"testing an array with before option"
);
is_deeply(
[ Fancy::Open::fancy_open($file, { 'after' => ' bead' }) ],
[ map "$_ bead", @wanted ],
"testing an array with after option"
);
is_deeply(
[ Fancy::Open::fancy_open($file, { 'before' => 'solid ', 'after' =>
+' bead' }) ],
[ map "solid $_ bead", @wanted ],
"testing an array with before and after options"
);
done_testing();
You might also want to test it on a file that ends with a "\n" and a file that doesn't end with a "\n", and see if the behaviour differs between them. Having checked your module, I don't think it will, but it might be useful to have a test for it, so you don't accidentally change that in the future without realizing it.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.