xref: /openbsd/gnu/usr.bin/perl/t/op/bool.t (revision 4bdff4be)
1#!./perl
2
3BEGIN {
4    chdir 't' if -d 't';
5    require './test.pl';
6    set_up_inc('../lib');
7}
8
9use strict;
10use warnings;
11
12my $truevar  = (5 == 5);
13my $falsevar = (5 == 6);
14
15cmp_ok($truevar, '==', 1);
16cmp_ok($truevar, 'eq', "1");
17
18cmp_ok($falsevar, '==', 0);
19cmp_ok($falsevar, 'eq', "");
20
21{
22    # Check that boolean COW string buffer is safe to copy into new SVs and
23    # doesn't get corrupted by inplace mutations
24    my $x = $truevar;
25    $x =~ s/1/t/;
26
27    cmp_ok($x, 'eq', "t");
28    cmp_ok($truevar, 'eq', "1");
29
30    my $y = $truevar;
31    substr($y, 0, 1, "T");
32
33    cmp_ok($y, 'eq', "T");
34    cmp_ok($truevar, 'eq', "1");
35}
36
37done_testing();
38