~ubuntu-branches/ubuntu/trusty/horae/trusty

« back to all changes in this revision

Viewing changes to 0CPAN/Config-IniFiles-2.39/t/03comments.t

  • Committer: Bazaar Package Importer
  • Author(s): Carlo Segre
  • Date: 2008-02-23 23:13:02 UTC
  • mfrom: (2.1.2 hardy)
  • Revision ID: james.westby@ubuntu.com-20080223231302-mnyyxs3icvrus4ke
Tags: 066-3
Apply patch to athena_parts/misc.pl for compatibility with 
perl-tk 804.28.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#
2
 
# Comment preservation
3
 
#
4
 
 
5
 
use strict;
6
 
use Test;
7
 
use Config::IniFiles;
8
 
 
9
 
BEGIN { plan tests => 15 }
10
 
 
11
 
my $ors = $\ || "\n";
12
 
my ($ini, $value);
13
 
 
14
 
# Get files from the 't' directory, portably
15
 
chdir('t') if ( -d 't' );
16
 
 
17
 
# test 1
18
 
# Load ini file and write as new file
19
 
$ini = new Config::IniFiles -file => "test.ini";
20
 
$ini->SetFileName("test03.ini");
21
 
$ini->SetWriteMode("0666");
22
 
unlink "test03.ini";
23
 
$ini->RewriteConfig;
24
 
$ini->ReadConfig;
25
 
ok($ini);
26
 
 
27
 
# test 2
28
 
# Section comments preserved
29
 
$value = 0;
30
 
if( open FILE, "<test03.ini" ) {
31
 
        $_ = join( '', <FILE> );
32
 
        $value = /\# This is a section comment[$ors]\[test1\]/;
33
 
        close FILE;
34
 
}
35
 
ok($value);
36
 
 
37
 
 
38
 
# test 3
39
 
# Parameter comments preserved
40
 
$value = /\# This is a parm comment[$ors]five=value5/;
41
 
ok($value);
42
 
 
43
 
 
44
 
# test 4
45
 
# Setting Section Comment
46
 
$ini->setval('foo','bar','qux');
47
 
ok($ini->SetSectionComment('foo', 'This is a section comment', 'This comment takes two lines!'));
48
 
 
49
 
# test 5
50
 
# Getting Section Comment
51
 
my @comment = $ini->GetSectionComment('foo');
52
 
ok( join('', @comment) eq '# This is a section comment# This comment takes two lines!');
53
 
 
54
 
#test 6
55
 
# Deleting Section Comment
56
 
$ini->DeleteSectionComment('foo');
57
 
# Should not exist!
58
 
ok(not defined $ini->GetSectionComment('foo'));
59
 
 
60
 
# test 7
61
 
# Setting Parameter Comment
62
 
ok($ini->SetParameterComment('foo', 'bar', 'This is a parameter comment', 'This comment takes two lines!'));
63
 
 
64
 
# test 8
65
 
# Getting Parameter Comment
66
 
@comment = $ini->GetParameterComment('foo', 'bar');
67
 
ok(join('', @comment) eq '# This is a parameter comment# This comment takes two lines!');
68
 
 
69
 
# test 9
70
 
# Deleting Parameter Comment
71
 
$ini->DeleteParameterComment('foo', 'bar');
72
 
# Should not exist!
73
 
ok(not defined $ini->GetSectionComment('foo', 'bar'));
74
 
 
75
 
 
76
 
# test 10
77
 
# Reading a section comment from the file
78
 
@comment = $ini->GetSectionComment('test1');
79
 
ok(join('', @comment) eq '# This is a section comment');
80
 
 
81
 
# test 11
82
 
# Reading a parameter comment from the file
83
 
@comment = $ini->GetParameterComment('test2', 'five');
84
 
ok(join('', @comment) eq '# This is a parm comment');
85
 
 
86
 
# test 12
87
 
# Reading a comment that starts with ';'
88
 
@comment = $ini->GetSectionComment('MixedCaseSect');
89
 
ok(join('', @comment) eq '; This is a semi-colon comment');
90
 
 
91
 
 
92
 
# Test 13
93
 
# Loading from a file with alternate comment characters
94
 
# and also test continuation characters (in one file)
95
 
$ini = Config::IniFiles->new(
96
 
  -file => "cmt.ini",
97
 
  -commentchar => '@',
98
 
  -allowcontinue => 1
99
 
);
100
 
ok($ini);
101
 
 
102
 
# Test 14
103
 
$value = $ini->GetParameterComment('Library', 'addmultf_lib');
104
 
ok ($value =~ /\@#\@CF Automatically created by 'config_project' at Thu Mar 21 08:46:54 2002/);
105
 
 
106
 
# Test 15
107
 
$value = $ini->val('turbo_library', 'TurboLibPaths');
108
 
ok ($value =~ m:\$WORKAREA/resources/c11_test_flow/vhdl_rtl\s+\$WORKAREA/resources/cstarlib_reg_1v5/vhdl_rtl:);
109
 
 
110
 
# Clean up when we're done
111
 
unlink "test03.ini";
112