2 # Copyright (C) 2001-2007, The Perl Foundation.
7 use lib qw( t . lib ../lib ../../lib ../../../lib );
9 use Parrot::Test tests => 20;
10 use Parrot::Test::PGE;
14 t/compilers/pge/pge_text.t - PGE::Text tests
18 These tests examine the ability of PGE to match text with brackets in it.
22 % prove t/compilers/pge/text_brk.t
26 ## First, test direct calls to PGE::Text::bracketed
28 pir_output_is( <<'CODE', <<'OUT', "bracketed" );
32 load_bytecode 'PGE.pbc'
33 load_bytecode 'PGE/Text.pir'
35 bracketed = get_global ['PGE::Text'], "bracketed"
37 $S0 = "{ nested { and } okay, () and <>, escaped \\}'s } okay"
40 $S0 = "{ nested \n{ and } okay, \n() and <>, escaped \\}'s } okay"
43 $S0 = "{ nested { and } okay, unbalanced ( and < , escaped \\}'s } okay"
44 $P0 = bracketed($S0, "{}")
46 $S0 = "{ unmatched nested { not okay, nor ( and < } not okay"
47 $P0 = bracketed($S0, "{}")
49 $S0 = "{ unbalanced nested [ even with } and ] to match not okay"
50 $P0 = bracketed($S0, "{}[]")
52 $S0 = "<a quoted \">\" unbalanced right bracket> okay"
53 $P0 = bracketed($S0, "<\">")
55 $S0 = "<quoted \">\" unbalanced of two quotes (`>>>\"\"\">>>>`)> okay"
56 $P0 = bracketed($S0, "<\"`>")
58 $S0 = "<a misquoted '>' bracket ends string>"
59 $P0 = bracketed($S0, "<\"`>")
82 ' bracket ends string>
85 ## Now, test calls as subrules
87 my $PTB = "^<PGE::Text::bracketed>\$";
88 p6rule_is( "{ nested { and } okay, () and <> pairs okay }", $PTB );
89 p6rule_is( "{ nested { and } okay, () <>, escaped \\}'s okay }", $PTB );
90 p6rule_isnt( "{ unmatched nested { not okay }", $PTB );
91 p6rule_isnt( "{ unmatched nested ( not okay }", $PTB );
93 ## parameterized with {}
94 $PTB = "^<PGE::Text::bracketed: {}>";
95 p6rule_is( "{ nested { } okay, unbalanced (, <, escaped \\} okay}", $PTB );
96 p6rule_isnt( "{ unmatched nested { not okay }", $PTB );
97 p6rule_isnt( "{ unmatched nested { not okay, nor ( and < }", $PTB );
99 ## parameterized with {}[]" (nested and quoted)
100 $PTB = '^<PGE::Text::bracketed: {}[]"`>';
101 p6rule_isnt( '{ unbalanced nested [ with } and ] not okay', $PTB );
102 p6rule_is( '{ balanced nested [ with ] and ( is } okay', $PTB );
103 p6rule_is( '{ a quoted "}" unbalanced right bracket} okay', $PTB );
104 p6rule_is( '{ quoted "}" unbalanced quotes (`}}}"""}}}}`)} okay', $PTB );
106 ## escaped bracket characters in regex, nesting not checked
107 ## There might be a better suited file for these tests
108 p6rule_is( '{ opening at start of string', '^\{' );
109 p6rule_is( 'opening { at end of string {', '\{$' );
110 p6rule_is( '} closing at start of string', '^\}' );
111 p6rule_is( 'closing } at end of string }', '\}$' );
112 p6rule_is( '[ opening at start of string', '^\[' );
113 p6rule_is( 'opening [ at end of string [', '\[$' );
114 p6rule_is( '] closing at start of string', '^\]' );
115 p6rule_is( 'closing ] at end of string ]', '\]$' );
119 # cperl-indent-level: 4
122 # vim: expandtab shiftwidth=4: