add begin.t from Method::Signatures
[p5sagit/Function-Parameters.git] / t / lineno.t
1 use warnings;
2 use strict;
3
4 use Test::More tests => 11;
5
6 use Function::Parameters;
7
8 fun actual_location_of_line_with($marker) {
9         seek DATA, 0, 0 or die "seek DATA: $!";
10         my $loc = 0;
11         while (my $line = readline DATA) {
12                 $loc++;
13                 index($line, $marker) >= 0
14                         and return $loc;
15         }
16         undef
17 }
18
19 fun test_loc($marker) {
20         my $expected = actual_location_of_line_with $marker;
21         defined $expected or die "$marker: something done fucked up";
22         my $got = (caller)[2];
23         is $got, $expected, "location of '$marker'";
24 }
25
26 fun () {
27         test_loc 'LX simple';
28 }->();
29
30 test_loc 'LX -- 1';
31
32 fun 
33  (
34    )
35      {
36         test_loc 'LX creative formatting'; }
37 ->
38 (
39  );
40
41 test_loc 'LX -- 2';
42
43 fun () {
44         fun () {
45                 test_loc 'LX nested';
46         }->()
47 }->();
48
49 test_loc 'LX -- 3';
50
51 {
52         #local $TODO = 'expressions break line numbers???';
53
54         0
55         , fun {
56                         test_loc 'LX assign';
57                 }->()
58         ;
59
60         test_loc 'LX -- 4';
61 }
62
63 {
64         #local $TODO = 'newlines in prototype/attributes';
65
66         fun wtf :(
67
68         )
69         :
70         { test_loc 'LX -- 5 (inner)' }
71
72         test_loc 'LX -- 5 (bonus)';
73         wtf;
74         test_loc 'LX -- 5 (outer)';
75 }
76
77 __DATA__