Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 35 lines (23 sloc) 0.997 kb
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
use v6;

use Test;

=begin pod

The ? case definitely shouldn't be a syntax error. The next question is
what the correct boolean value is for a Pair; always-true is now assumed
for consistency with the "one-key hash" semantics.

=end pod

#L<S02/Literals/>

plan 6;

# See thread "Stringification, numification, and booleanification of pairs" on
# p6l started by Ingo Blechschmidt:
# L<"http://www.nntp.perl.org/group/perl.perl6.language/23148">

{
my $true_pair = 1 => 1;
my $false_pair = 1 => 0;

lives_ok { ?$true_pair }, 'Taking the boolean of a true pair should live';
lives_ok { ?$false_pair }, 'Taking the boolean of a false pair should live';
ok (try { ?$true_pair }), 'A pair with a true value is true';
ok (try { ?$false_pair }), 'A pair with a false value is also true';

is $true_pair ?? 1 !! 0, 1, 'Ternary on a true pair returns first option';
is $false_pair ?? 1 !! 0, 1, 'Ternary on a false pair returns first option too';
}

# vim: ft=perl6
Something went wrong with that request. Please try again.