1use strict;
2use warnings;
3
4use FindBin;
5use File::ChangeNotify::Watcher::Default;
6use File::Spec;
7
8use Test::More;
9
10my $root = File::Spec->catfile( $FindBin::Bin, '..' );
11sub f { File::Spec->catfile( $root, @_ ) }
12
13my $watcher = File::ChangeNotify::Watcher::Default->new(
14    directories => f(),
15    exclude     => [
16        f('foo'),
17        f('bar'),
18        f( 'excluded', 'dir' ),
19        qr{(?:\\|/)r[^\\/]+$},
20        qr{(?:\\|/)\.[^\\/]*$},
21        sub { 0; },
22    ]
23);
24
25ok( !$watcher->_path_is_excluded( f('quux') ), 'included dir' );
26ok( $watcher->_path_is_excluded( f('foo') ),   'excluded dir' );
27ok(
28    !$watcher->_path_is_excluded( f( 'foo', 'bar' ) ),
29    'subdirs not excluded with string exclusion'
30);
31ok(
32    $watcher->_path_is_excluded( f( 'left', 'right' ) ),
33    'excluded by regex'
34);
35ok(
36    $watcher->_path_is_excluded( f('.hidden') ),
37    'excluding hidden dirs with regex'
38);
39ok(
40    !$watcher->_path_is_excluded( f( '.hidden', 'file' ) ),
41    'hidden dir regex does not exclude subdirs'
42);
43
44done_testing();
45