File: 33exception.t

package info (click to toggle)
libparser-mgc-perl 0.23-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 460 kB
  • sloc: perl: 1,881; makefile: 2; sh: 1
file content (56 lines) | stat: -rw-r--r-- 1,127 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/perl

use v5.14;
use warnings;

use Test2::V0;

use File::Temp qw( tempfile );

package TestParser {
   use base qw( Parser::MGC );

   sub parse
   {
      my $self = shift;

      return $self->token_int;
   }
}

my $parser = TestParser->new;

isa_ok( $parser, [ "TestParser", "Parser::MGC" ], '$parser' );

my $value = $parser->from_string( "\t123" );

is( $value, 123, '->from_string' );

is( dies { $parser->from_string( "\t123." ) },
   qq[Expected end of input on line 1 at:\n].
   qq[\t123.\n].
   qq[\t   ^\n],
   'Exception from trailing input on string' );

is( dies { $parser->from_file( \*DATA ) },
   qq[Expected end of input on line 1 at:\n].
   qq[ 123.\n].
   qq[    ^\n],
   'Exception from trailing input on glob filehandle' );

my ( $fh, $filename ) = tempfile( "tmpfile.XXXXXX", UNLINK => 1 );
END { defined $filename and unlink $filename }

print $fh " 123.\n";
close $fh;

is( dies { $parser->from_file( $filename ) },
   qq[Expected end of input in $filename on line 1 at:\n].
   qq[ 123.\n].
   qq[    ^\n],
   'Exception from trailing input on named file' );

done_testing;

__DATA__
 123.