File: 08substring.t

package info (click to toggle)
libparser-mgc-perl 0.22-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 536 kB
  • sloc: perl: 1,881; makefile: 2; sh: 1
file content (44 lines) | stat: -rw-r--r-- 806 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
39
40
41
42
43
44
#!/usr/bin/perl

use v5.14;
use warnings;

use Test2::V0;

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

   our $Nonempty;

   sub parse
   {
      my $self = shift;

      [ ( $Nonempty ? $self->nonempty_substring_before( "!" ) : $self->substring_before( "!" ) ),
        $self->expect( "!" ) ];
   }
}

my $parser = TestParser->new;

{
   is( $parser->from_string( "Hello, world!" ),
      [ "Hello, world", "!" ],
      '"Hello, world!"' );

   is( $parser->from_string( "!" ),
      [ "", "!" ],
      '"!"' );
}

{
   local $TestParser::Nonempty = 1;

   is( dies { $parser->from_string( "!" ) },
      qq[Expected to find a non-empty substring before \(\?^u:\\!\) on line 1 at:\n] .
      qq[!\n] .
      qq[^\n],
      'Exception from ->nonempty_substring_before failure' );
}

done_testing;