Skip to content

Commit

Permalink
Merge f539a22 into 7511e89
Browse files Browse the repository at this point in the history
  • Loading branch information
jjatria committed May 29, 2019
2 parents 7511e89 + f539a22 commit 2c4afac
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
3 changes: 3 additions & 0 deletions lib/Data/Fake/Text.pm
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ provide the number of words); the default is one.

sub fake_words {
my ($count) = @_;
$count = 1 unless defined $count;
require Text::Lorem;
$LOREM ||= Text::Lorem->new;
return sub { $LOREM->words( _transform($count) ) };
Expand All @@ -52,6 +53,7 @@ number of sentences); the default is one.

sub fake_sentences {
my ($count) = @_;
$count = 1 unless defined $count;
return sub { "" }
if $count == 0;
require Text::Lorem;
Expand All @@ -73,6 +75,7 @@ number of paragraphs); the default is one.

sub fake_paragraphs {
my ($count) = @_;
$count = 1 unless defined $count;
require Text::Lorem;
$LOREM ||= Text::Lorem->new;
return sub { $LOREM->paragraphs( _transform($count) ) };
Expand Down
37 changes: 27 additions & 10 deletions t/text.t
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,46 @@ use Test::Deep;
use Data::Fake::Text;

subtest 'fake_words' => sub {
for my $i ( 0 .. 5 ) {
my $got = fake_words($i)->();
for my $i ( undef, 0 .. 5 ) {
my @args = defined $i ? $i : ();
my $got = fake_words(@args)->();
ok( defined($got), "word is defined" );
is( scalar split( / /, $got ), $i, "word list of length $i" );

my $n = defined $i ? $i : 1;
my $msg = "word list of length $n";
$msg .= " (default)" unless defined $i;

is( scalar split( / /, $got ), $n, $msg );
}
};

subtest 'fake_sentences' => sub {
for my $i ( 0 .. 5 ) {
my $got = fake_sentences($i)->();
for my $i ( undef, 0 .. 5 ) {
my @args = defined $i ? $i : ();
my $got = fake_sentences(@args)->();
ok( defined($got), "sentence is defined" );

my $n = defined $i ? $i : 1;
my $msg = "sentence list of length $n";
$msg .= " (default)" unless defined $i;

my $count =()= ( $got =~ /\./g );
is( $count, $i, "sentence list of length $i" ) or diag $got;
is( $count, $n, $msg ) or diag $got;
}
};

subtest 'fake_paragraphs' => sub {
for my $i ( 0 .. 5 ) {
my $got = fake_paragraphs($i)->();
for my $i ( undef, 0 .. 5 ) {
my @args = defined $i ? $i : ();
my $got = fake_paragraphs(@args)->();
ok( defined($got), "paragraph is defined" );

my $n = defined $i ? ( $i == 0 ? 0 : 2 * $i - 1 ) : 1;
my $msg = "paragraph list of length $n";
$msg .= " (default)" unless defined $i;

my $count = scalar split /^/, $got;
is( $count, ( $i == 0 ? 0 : 2 * $i - 1 ), "paragraph list of length $i" )
or diag $got;
is( $count, $n, $msg ) or diag $got;
}
};

Expand Down

0 comments on commit 2c4afac

Please sign in to comment.