File: new_string.t

package info (click to toggle)
libconfigreader-simple-perl 1.28-3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze, wheezy
  • size: 212 kB
  • ctags: 27
  • sloc: perl: 696; makefile: 2
file content (81 lines) | stat: -rw-r--r-- 2,127 bytes parent folder | download | duplicates (7)
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
#!/usr/bin/perl
use strict;
use warnings;

use Test::More 'no_plan';

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
my $class  = 'ConfigReader::Simple';
my $method = 'new_string';

use_ok( $class );
can_ok( $class, $method );

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Test that it works with both Strings and Keys
# Has all valid keys
{
my $key = 'Cat';
my $cat = 'Buster';

my $config = $class->$method(
	Strings => [ \ "$key = $cat" ],
	Keys    => [ $key     ],
	);

isa_ok( $config, $class );

is( $config->get( $key ), $cat );
}

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Test that it works with only Strings
{
my $key = 'Cat';
my $cat = 'Mimi';

my $config = $class->$method(
	Strings => [ \ "$key = $cat" ],
	);

isa_ok( $config, $class );

is( $config->get( $key ), $cat );
}

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Test that it croaks with no arguments
{
eval { $class->$method() };
my $at = $@;
ok( defined $at, "$method fails with no arguments" );
like( $at, qr/must be an array reference/ );
}

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Test that it croaks with Strings containing a non-scalar ref
{
eval { $class->$method( Strings => [ 'Foo = Bar' ] ) };
my $at = $@;
ok( defined $at, "$method fails when string contains a non-reference" );
like( $at, qr/not a scalar reference/ );
}

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Test that it croaks when Strings value is not an array ref
{
eval { $class->$method( Strings => '', Keys => [] ) };
my $at = $@;
ok( defined $at, "$method fails when Keys value is the empty string" );
like( $at, qr/must be an array reference/ );
}

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# Test that it croaks when Keys value is not an array ref
{
eval { $class->$method( Strings => [ ], Keys => '' ) };
my $at = $@;
ok( defined $at, "$method fails when Keys value is the empty string" );
like( $at, qr/must be an array reference/ );
}