File: comment.t

package info (click to toggle)
libconfig-gitlike-perl 1.18-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 300 kB
  • sloc: perl: 2,468; makefile: 2
file content (70 lines) | stat: -rw-r--r-- 1,551 bytes parent folder | download | duplicates (5)
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
use strict;
use warnings;

use Test::More;
use File::Spec;
use File::Temp qw/tempdir/;
use lib 't/lib';
use TestConfig;

my $config_dirname = tempdir( CLEANUP => !$ENV{CONFIG_GITLIKE_DEBUG} );
my $config_filename = File::Spec->catfile( $config_dirname, 'config' );

diag "config file is: $config_filename" if $ENV{TEST_VERBOSE};

my $config
    = TestConfig->new( confname => 'config', tmpdir => $config_dirname );
$config->load;

# Test add_comment.
$config->add_comment(
    filename => $config_filename,
    comment  => 'yo dawg',
);
my $expect = "# yo dawg\n";
is( $config->slurp, $expect, 'comment' );

# Make sure leading whitespace is maintained.
$config->add_comment(
    filename => $config_filename,
    comment  => '   for you.'
);

$expect .= "#    for you.\n";
is( $config->slurp, $expect, 'comment with ws' );

# Make sure it interacts well with configuration.
$config->set(
    key      => 'core.penguin',
    value    => 'little blue',
    filename => $config_filename
);

$config->add_comment(
    filename => $config_filename,
    comment  => "this is\n  for you\n  \n  you know",
    indented => 1,
);

$expect = <<'EOF'
# yo dawg
#    for you.
[core]
	penguin = little blue
# this is
  # for you
  # 
  # you know
EOF
    ;
is( $config->slurp, $expect, 'indented comment with newlines and config' );

$config->add_comment(
    filename  => $config_filename,
    comment   => '  gimme a semicolon',
    semicolon => 1,
);
$expect .= ";   gimme a semicolon\n";
is( $config->slurp, $expect, 'comment with semicolon' );

done_testing;