File: scan_file.t

package info (click to toggle)
libtest-fixme-perl 0.14-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 224 kB
  • ctags: 6
  • sloc: perl: 127; makefile: 2
file content (65 lines) | stat: -rw-r--r-- 1,596 bytes parent folder | download | duplicates (5)
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
use strict;
use warnings;

use Test::More tests => 7;

# Load the module.
use_ok 'Test::Fixme';

{    # Check that bad input is not accepted.
    ok !defined Test::Fixme::scan_file(), "no input";
    ok !defined Test::Fixme::scan_file( match => 'TEST' ), "no match";
    ok !defined Test::Fixme::scan_file( file => 't/dirs/normal/one.txt' ),
      "no file";

}

{    # Scan an empty file to get an empty arrayref.
    my $arrayref = Test::Fixme::scan_file(
        file  => 't/dirs/normal/four.pod',
        match => 'TEST'
    );
    ok eq_array( $arrayref, [] ), "empty file, empty array";
}

{    # Scan a file where there should be one hit.
    my $arrayref = Test::Fixme::scan_file(
        file  => 't/dirs/normal/one.txt',
        match => 'ijk'
    );

    my $expected = [
        {
            line  => 2,
            text  => "ghijkl",
            file  => 't/dirs/normal/one.txt',
            match => 'ijk'
        }
    ];

    ok eq_array( $arrayref, $expected ), "find one result";
}

{    # scan file that should have several hits.
    my $arrayref = Test::Fixme::scan_file(
        file  => 't/dirs/normal/two.pl',
        match => 'TEST'
    );

    my $expected = [
        {
            match => 'TEST',
            file  => 't/dirs/normal/two.pl',
            line  => 8,
            text  => "# TEST - test 1 (line 8)."
        },
        {
            match => 'TEST',
            file  => 't/dirs/normal/two.pl',
            line  => 10,
            text  => "# TEST - test 2 (line 10)."
        },
    ];

    ok eq_array( $arrayref, $expected ), "find two results";
}