File: 02tree-create.t

package info (click to toggle)
libfile-find-object-perl 0.3.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 316 kB
  • sloc: perl: 1,813; makefile: 2
file content (170 lines) | stat: -rw-r--r-- 4,524 bytes parent folder | download | duplicates (2)
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/usr/bin/perl

use strict;
use warnings;

use Test::More tests => 22;

use File::Path;

use File::TreeCreate ();

{
    my $t = File::TreeCreate->new();

    # TEST
    ok( $t, "TreeCreate object was initialized" );

    # TEST
    is( $t->get_path("./t/file.txt"),
        File::Spec->catfile( File::Spec->curdir(), "t", "file.txt" ) );

    # TEST
    is( $t->get_path("./t/mydir/"),
        File::Spec->catdir( File::Spec->curdir(), "t", "mydir" ) );

    # TEST
    is(
        $t->get_path("./t/hello/there/world.jpg"),
        File::Spec->catfile(
            File::Spec->curdir(), "t", "hello", "there", "world.jpg"
        )
    );

    # TEST
    is(
        $t->get_path("./one/two/three/four/"),
        File::Spec->catdir(
            File::Spec->curdir(), "one", "two", "three", "four"
        )
    );
}

{
    my $t = File::TreeCreate->new();

    # TEST
    ok( $t->exist("./MANIFEST"), "Checking the exist() method" );

    # TEST
    ok( !$t->exist("./BKLASDJASFDJODIJASDOJASODJ.wok"),
        "Checking the exist() method" );

    # TEST
    ok( $t->is_file("./MANIFEST"), "Checking the is_file method" );

    # TEST
    ok( !$t->is_file("./t"), "Checking the is_file method - 2" );

    # TEST
    ok( !$t->is_dir("./MANIFEST"), "Checking the is_dir method - false" );

    # TEST
    ok( $t->is_dir("./t"), "Checking the is_dir method - true" );

    # TEST
    is( $t->cat("./t/sample-data/h.txt"), "Hello.", "Checking the cat method" );

    {
        mkdir( $t->get_path("./t/sample-data/tree-create-ls-test") );
        mkdir( $t->get_path("./t/sample-data/tree-create-ls-test/a") );
        {
            open my $out_fh, ">",
                $t->get_path("./t/sample-data/tree-create-ls-test/b.txt");
            print {$out_fh} "Yowza";
            close($out_fh);
        }
        mkdir( $t->get_path("./t/sample-data/tree-create-ls-test/c") );
        {
            open my $out_fh, ">",
                $t->get_path("./t/sample-data/tree-create-ls-test/h.xls");
            print {$out_fh} "FooBardom!\n";
            close($out_fh);
        }

        # TEST
        is_deeply(
            $t->ls("./t/sample-data/tree-create-ls-test"),
            [ "a", "b.txt", "c", "h.xls" ],
            "Testing the ls method",
        );

        # Cleanup
        rmtree( $t->get_path("./t/sample-data/tree-create-ls-test") );
    }

    {
        my $tree = {
            'name' => "tree-create--tree-test-1/",
            'subs' => [
                {
                    'name'     => "b.doc",
                    'contents' => "This file was spotted in the wild.",
                },
                {
                    'name' => "a/",
                },
                {
                    'name' => "foo/",
                    'subs' => [
                        {
                            'name' => "yet/",
                        },
                    ],
                },
            ],
        };

        $t->create_tree( "./t/sample-data/", $tree );

        # TEST
        is_deeply(
            $t->ls("./t/sample-data/tree-create--tree-test-1"),
            [ "a", "b.doc", "foo" ],
            "Testing the contents of the root tree"
        );

        # TEST
        ok( $t->is_dir("./t/sample-data/tree-create--tree-test-1/a"),
            "a is a dir" );

        # TEST
        is_deeply( $t->ls("./t/sample-data/tree-create--tree-test-1/a"),
            [], "Testing the contents of a" );

        # TEST
        is_deeply( $t->ls("./t/sample-data/tree-create--tree-test-1/foo"),
            ["yet"], "Testing the contents of foo" );

        # TEST
        ok( $t->is_dir("./t/sample-data/tree-create--tree-test-1/foo/yet"),
            "Testing that foo/yet is a dir" );

        # TEST
        is_deeply( $t->ls("./t/sample-data/tree-create--tree-test-1/foo/yet"),
            [], "Testing that foo/yet is a dir" );

        # TEST
        ok( $t->is_file("./t/sample-data/tree-create--tree-test-1/b.doc"),
            "Checking that b.doc is a file" );

        # TEST
        is(
            $t->cat("./t/sample-data/tree-create--tree-test-1/b.doc"),
            "This file was spotted in the wild.",
            "Checking for contents of b.doc"
        );

        # Cleanup
        rmtree( $t->get_path("./t/sample-data/tree-create--tree-test-1") );
    }
    {
        # TEST
        is(
            $t->get_path("s/hello"),
            File::Spec->catfile( "s", "hello" ),
            "Bug that eliminated ^[AnyChar]/ instead of ^\\./"
        );
    }
}