File: Sublike.t

package info (click to toggle)
libdevel-declare-parser-perl 0.17-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 192 kB
  • ctags: 144
  • sloc: perl: 891; makefile: 2
file content (58 lines) | stat: -rw-r--r-- 1,312 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
#!/usr/bin/perl
use strict;
use warnings;
use Test::More;
use Test::Exception::LessClever;

sub test { $_[-1]->( @_ ) }

BEGIN {
    use_ok( 'Devel::Declare::Parser::Sublike' );
    Devel::Declare::Interface::enhance( 'main', 'test', 'sublike' );
}

our $ran;

test( 'a', sub { $ran++, is( $_[0], 'a', "got name" ) });
is( $ran, 1, "ran enclosed" );

test a {
    $ran++;
    is( $_[0], 'a', "got name" );
}
is( $ran, 2, "ran multiline block no semicolon" );

test a {
    $ran++;
    is( $_[0], 'a', "got name" );
};
is( $ran, 3, "ran multiline block with semicolon" );

test a { $ran++; is( $_[0], 'a', "got name" ); };
is( $ran, 4, "ran singleline block with semicolon" );

test a { $ran++; is( $_[0], 'a', "got name" ); }
is( $ran, 5, "ran singleline block no semicolon" );

test 'quoted name' {
    $ran++;
    is( $_[0], 'quoted name', "got ' quoted name" );
}
is( $ran, 6, "ran singleline block no semicolon" );

test "quoted name" {
    $ran++;
    is( $_[0], 'quoted name', 'got " quoted name' );
}
is( $ran, 7, "ran singleline block no semicolon" );

test {
    $ran++;
    is( $_[0], undef, 'no name' );
}
is( $ran, 8, "ran with no name" );

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

done_testing();