File: bool.t

package info (click to toggle)
rakudo 2016.12-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 19,200 kB
  • ctags: 1,323
  • sloc: perl: 45,091; java: 2,524; ansic: 1,761; cpp: 152; sh: 17; makefile: 15
file content (38 lines) | stat: -rw-r--r-- 1,240 bytes parent folder | download
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
35
36
37
38
use v6.c;
use Test;

plan 15;

{
    my @a;
    nok @a.Bool, '@a.Bool returns False for empty @a';
    nok ?@a,     '?@a returns False for empty @a';
    nok @a,      '@a in bool context returns False for empty @a';
    
    @a.push: 37;
    ok @a.Bool, '@a.Bool returns True for @a with one element';
    ok ?@a,     '?@a returns True for @a with one element';
    ok @a,      '@a in bool context returns True for @a with one element';

    @a.push: -23;
    ok @a.Bool, '@a.Bool returns True for @a with two elements';
    ok ?@a,     '?@a returns True for @a with two elements';
    ok @a,      '@a in bool context returns True for @a with two elements';
}

{
    my @a = 4..3;
    nok @a.Bool, '@a.Bool returns False for empty range in @a';
    nok ?@a,     '?@a returns False for empty range in @a';
    nok @a,      '@a in bool context returns False for empty range in @a';
    
    @a = 4..6;
    ok @a.Bool, '@a.Bool returns True for non-empty range in @a';
    ok ?@a,     '?@a returns True for non-empty range in @a';
    ok @a,      '@a in bool context returns True for non-empty range in @a';
}

# TODO: This could definitely use tests to make sure that @a.Bool only examines
# the first (few?) elements of @a.

# vim: ft=perl6