File: Codeblock.t

package info (click to toggle)
libdevel-declare-parser-perl 0.021-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 160 kB
  • sloc: perl: 878; makefile: 2
file content (78 lines) | stat: -rw-r--r-- 1,291 bytes parent folder | download | duplicates (5)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/perl
use strict;
use warnings;
use Test::More;
use Test::Exception::LessClever;

sub line {
    ( undef, undef, my $line ) = caller;
    return $line;
}

sub test {
    $_[0]->();
    $_[0];
}

BEGIN {
    use_ok( 'Devel::Declare::Parser::Codeblock' );
    Devel::Declare::Interface::enhance( 'main', 'test', 'codeblock' );
#    Devel::Declare::Parser::Codeblock->DEBUG(1);
}

our $ran;

test( sub { $ran++ });
ok( $ran, "ran enclosed" );

test { $ran++ }

is( $ran, 2, "ran block no semicolon" );

test { $ran++ };

is( $ran, 3, "ran block with semicolon" );

is( line(), 36, "Line numbers have not changed" );

test
{
    $ran++
}

is( $ran, 4, "ran newline block" );

ok( !eval 'test sub {1}; 1', "invalid syntax" );
like( $@, qr/Syntax error near: 'sub' at /, "Useful message" );

ok( !eval 'test a b c {1}; 1', "invalid syntax again" );
like( $@, qr/Syntax error near: 'a' and 'b' and 'c' at /, "Useful message again" );

test(
    sub { $ran++ }
);
is( $ran, 5, "ran enclosed" );

test(
    sub {
        $ran++
    }
);
is( $ran, 6, "ran enclosed" );

test
(
    sub {
        $ran++
    }
);
is( $ran, 7, "ran enclosed" );

my $ran2 = 0;
test( sub{ $ran++ }) && $ran2++;
ok( $ran2, "Works in check" );

is( line(), 75, "Line numbers have not changed" );


done_testing();