File: text.t

package info (click to toggle)
libdata-fake-perl 0.006-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 324 kB
  • sloc: perl: 987; makefile: 7
file content (73 lines) | stat: -rw-r--r-- 1,919 bytes parent folder | download
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
use 5.008001;
use strict;
use warnings;
use Test::More 0.96;
use Test::Deep;

use Data::Fake::Text;

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

        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 ( 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, $n, $msg ) or diag $got;
    }
};

subtest 'fake_paragraphs' => sub {
    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, $n, $msg ) or diag $got;
    }
};

subtest 'scalar context' => sub {
    my @words = fake_words(2)->();
    is(scalar(@words), 1, "words");
    my @sentences = fake_sentences(2)->();
    is(scalar(@sentences), 1, "sentences");
    my @paragraphs = fake_paragraphs(2)->();
    is(scalar(@paragraphs), 1, "paragraphs");
};

done_testing;
#
# This file is part of Data-Fake
#
# This software is Copyright (c) 2015 by David Golden.
#
# This is free software, licensed under:
#
#   The Apache License, Version 2.0, January 2004
#

# vim: ts=4 sts=4 sw=4 et tw=75: