This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Remove +x from Term::ANSIColor test files.
[perl5.git] / cpan / Term-ANSIColor / t / module / stringify.t
1 #!/usr/bin/perl
2 #
3 # Test suite for stringify interaction.
4 #
5 # Copyright 2011 Revilo Reegiles
6 # Copyright 2011, 2014 Russ Allbery <rra@cpan.org>
7 #
8 # This program is free software; you may redistribute it and/or modify it
9 # under the same terms as Perl itself.
10
11 use strict;
12 use warnings;
13
14 use Test::More tests => 6;
15
16 # Create a dummy class that implements stringification.
17 ## no critic (Modules::ProhibitMultiplePackages)
18 package Test::Stringify;
19 use overload '""' => 'stringify';
20 sub new { return bless({}, 'Test::Stringify') }
21 sub stringify { return "Foo Bar\n" }
22
23 # Back to the main package.
24 package main;
25
26 # Load the module.
27 BEGIN {
28     delete $ENV{ANSI_COLORS_ALIASES};
29     delete $ENV{ANSI_COLORS_DISABLED};
30     use_ok('Term::ANSIColor', qw(colored));
31 }
32
33 # Some basic tests of colored without stringification.
34 my $result = colored(['blue', 'bold'], 'testing');
35 is($result, "\e[34;1mtesting\e[0m", 'colored with an array reference');
36 $result = colored("ok\n", 'bold blue');
37 is($result, "\e[1;34mok\n\e[0m", 'colored with a following string');
38
39 # Create a stringifiable object and repeat the tests.
40 my $test = Test::Stringify->new;
41 $result = colored($test . q{}, 'bold blue');
42 is($result, "\e[1;34mFoo Bar\n\e[0m", 'colored with forced stringification');
43 $result = colored($test, 'bold blue');
44 is($result, "\e[1;34mFoo Bar\n\e[0m", 'colored with a non-array reference');
45
46 # Create a hash reference and try stringifying it.
47 ## no critic (RegularExpressions::ProhibitEscapedMetacharacters)
48 my %foo = (foo => 'bar');
49 $result = colored(\%foo, 'bold blue');
50 like(
51     $result,
52     qr{ \e\[1;34m HASH\(.*\) \e\[0m }xms,
53     'colored with a hash reference'
54 );