File: normalize.t

package info (click to toggle)
libtest-file-perl 1.29-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 180 kB
  • ctags: 40
  • sloc: perl: 771; makefile: 2
file content (61 lines) | stat: -rw-r--r-- 1,623 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
use Test::More tests => 14;

use File::Spec;

use_ok( 'Test::File' );

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Try it when it should work
{
my $module = 'File::Spec::Unix';
use_ok( $module );
local @File::Spec::ISA = ( $module );

my $file       = '/foo/bar/baz';
my $normalized = Test::File::_normalize( $file );

is( $normalized, $file, "Normalize gives same path for unix" );
}

{
my $module = 'File::Spec::Win32';
use_ok( $module );
local @File::Spec::ISA = ( $module );

my $file       = '/foo/bar/baz';
my $normalized = Test::File::_normalize( $file );

isnt( $normalized, $file, "Normalize gives different path for Win32" );
is(   $normalized, '\foo\bar\baz', "Normalize gives right path for Win32" );
}

{
my $module = 'File::Spec::Mac';
use_ok( $module );
local @File::Spec::ISA = ( $module );

my $file       = '/foo/bar/baz';
my $normalized = Test::File::_normalize( $file );

isnt( $normalized, $file, "Normalize gives different path for Mac" );
is( $normalized, 'foo:bar:baz', "Normalize gives right path for Mac" );
}

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Try it when it shouldn't work
{
my $normalized = Test::File::_normalize( undef );
ok( ! defined $normalized, "Passing undef fails" );
}

{
my $normalized = Test::File::_normalize( '' );
ok( defined $normalized, "Passing empty string returns defined value" );
is( $normalized, '', "Passing empty string returns empty string" );
ok( ! $normalized, "Passing empty string fails" );
}

{
my $normalized = Test::File::_normalize();
ok( ! defined $normalized, "Passing nothing fails" );
}