1use strict; 2use warnings; 3 4use Test::More; 5use File::Spec; 6use File::Temp qw/tempdir/; 7use lib 't/lib'; 8use TestConfig; 9 10my $config_dirname = tempdir( CLEANUP => !$ENV{CONFIG_GITLIKE_DEBUG} ); 11my $config_filename = File::Spec->catfile( $config_dirname, 'config' ); 12 13diag "config file is: $config_filename" if $ENV{TEST_VERBOSE}; 14 15my $config 16 = TestConfig->new( confname => 'config', tmpdir => $config_dirname ); 17$config->load; 18 19# Test add_comment. 20$config->add_comment( 21 filename => $config_filename, 22 comment => 'yo dawg', 23); 24my $expect = "# yo dawg\n"; 25is( $config->slurp, $expect, 'comment' ); 26 27# Make sure leading whitespace is maintained. 28$config->add_comment( 29 filename => $config_filename, 30 comment => ' for you.' 31); 32 33$expect .= "# for you.\n"; 34is( $config->slurp, $expect, 'comment with ws' ); 35 36# Make sure it interacts well with configuration. 37$config->set( 38 key => 'core.penguin', 39 value => 'little blue', 40 filename => $config_filename 41); 42 43$config->add_comment( 44 filename => $config_filename, 45 comment => "this is\n for you\n \n you know", 46 indented => 1, 47); 48 49$expect = <<'EOF' 50# yo dawg 51# for you. 52[core] 53 penguin = little blue 54# this is 55 # for you 56 # 57 # you know 58EOF 59 ; 60is( $config->slurp, $expect, 'indented comment with newlines and config' ); 61 62$config->add_comment( 63 filename => $config_filename, 64 comment => ' gimme a semicolon', 65 semicolon => 1, 66); 67$expect .= "; gimme a semicolon\n"; 68is( $config->slurp, $expect, 'comment with semicolon' ); 69 70done_testing; 71