c:\@Work\Perl\monks>perl -wMstrict -le "use 5.010; ;; use Test::More 'no_plan'; use Test::NoWarnings; ;; my @test_set = ( 'degenerate and simple cases', [ '', '', 'empty line' ], [ ' ', ' ', 'single space' ], [ '~', '~', 'single tilde' ], [ '_', '_', 'single underscore' ], [ '~_', '~+', 'tilde, underscore' ], [ '_~', '_~', 'underscore, tilde' ], [ '__', '__', 'multiple underscores' ], [ '~__', '~++', 'tilde, multiple underscores' ], [ '__~', '__~', 'multiple underscores, tilde' ], 'more complicated cases', [ 'A line with an_underscore.', 'A line with an_underscore.', 'no leading tilde, text w/one underscore' ], [ 'A line with_two_underscores.', 'A line with_two_underscores.', 'no leading tilde, text w/two underscores' ], [ '~A line with an_underscore starting with a tilde.', '~A line with an+underscore starting with a tilde.', 'leading tilde, text w/one underscore' ], [ '~A line with_two_underscores starting with a tilde.', '~A line with+two+underscores starting with a tilde.', 'leading tilde, text w/two underscores' ], ); ;; VECTOR: for my $ar_vector (@test_set) { if (not ref $ar_vector) { note $ar_vector; next VECTOR; } ;; my ($input, $expected, $comment) = @$ar_vector; ;; $input =~ s{ (?: \G (?! \A) | \A ~) .*? \K _ }{+}xmsg; is $input, $expected, $comment; } ;; done_testing; ;; exit; " # degenerate and simple cases ok 1 - empty line ok 2 - single space ok 3 - single tilde ok 4 - single underscore ok 5 - tilde, underscore ok 6 - underscore, tilde ok 7 - multiple underscores ok 8 - tilde, multiple underscores ok 9 - multiple underscores, tilde # more complicated cases ok 10 - no leading tilde, text w/one underscore ok 11 - no leading tilde, text w/two underscores ok 12 - leading tilde, text w/one underscore ok 13 - leading tilde, text w/two underscores 1..13 ok 14 - no warnings 1..14