2 # Copyright (C) 2001-2007, Parrot 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.pbc'
35 bracketed = get_global ['PGE';'Text'], "bracketed"
37 jmpstack = new 'ResizableIntegerArray'
38 $S0 = "{ nested { and } okay, () and <>, escaped \\}'s } okay"
40 local_branch jmpstack, result
41 $S0 = "{ nested \n{ and } okay, \n() and <>, escaped \\}'s } okay"
43 local_branch jmpstack, result
44 $S0 = "{ nested { and } okay, unbalanced ( and < , escaped \\}'s } okay"
45 $P0 = bracketed($S0, "{}")
46 local_branch jmpstack, result
47 $S0 = "{ unmatched nested { not okay, nor ( and < } not okay"
48 $P0 = bracketed($S0, "{}")
49 local_branch jmpstack, result
50 $S0 = "{ unbalanced nested [ even with } and ] to match not okay"
51 $P0 = bracketed($S0, "{}[]")
52 local_branch jmpstack, result
53 $S0 = "<a quoted \">\" unbalanced right bracket> okay"
54 $P0 = bracketed($S0, "<\">")
55 local_branch jmpstack, result
56 $S0 = "<quoted \">\" unbalanced of two quotes (`>>>\"\"\">>>>`)> okay"
57 $P0 = bracketed($S0, "<\"`>")
58 local_branch jmpstack, result
59 $S0 = "<a misquoted '>' bracket ends string>"
60 $P0 = bracketed($S0, "<\"`>")
61 local_branch jmpstack, result
83 ' bracket ends string>
86 ## Now, test calls as subrules
88 my $PTB = "^<PGE::Text::bracketed>\$";
89 p6rule_is( "{ nested { and } okay, () and <> pairs okay }", $PTB );
90 p6rule_is( "{ nested { and } okay, () <>, escaped \\}'s okay }", $PTB );
91 p6rule_isnt( "{ unmatched nested { not okay }", $PTB );
92 p6rule_isnt( "{ unmatched nested ( not okay }", $PTB );
94 ## parameterized with {}
95 $PTB = "^<PGE::Text::bracketed: {}>";
96 p6rule_is( "{ nested { } okay, unbalanced (, <, escaped \\} okay}", $PTB );
97 p6rule_isnt( "{ unmatched nested { not okay }", $PTB );
98 p6rule_isnt( "{ unmatched nested { not okay, nor ( and < }", $PTB );
100 ## parameterized with {}[]" (nested and quoted)
101 $PTB = '^<PGE::Text::bracketed: {}[]"`>';
102 p6rule_isnt( '{ unbalanced nested [ with } and ] not okay', $PTB );
103 p6rule_is( '{ balanced nested [ with ] and ( is } okay', $PTB );
104 p6rule_is( '{ a quoted "}" unbalanced right bracket} okay', $PTB );
105 p6rule_is( '{ quoted "}" unbalanced quotes (`}}}"""}}}}`)} okay', $PTB );
107 ## escaped bracket characters in regex, nesting not checked
108 ## There might be a better suited file for these tests
109 p6rule_is( '{ opening at start of string', '^\{' );
110 p6rule_is( 'opening { at end of string {', '\{$' );
111 p6rule_is( '} closing at start of string', '^\}' );
112 p6rule_is( 'closing } at end of string }', '\}$' );
113 p6rule_is( '[ opening at start of string', '^\[' );
114 p6rule_is( 'opening [ at end of string [', '\[$' );
115 p6rule_is( '] closing at start of string', '^\]' );
116 p6rule_is( 'closing ] at end of string ]', '\]$' );
120 # cperl-indent-level: 4
123 # vim: expandtab shiftwidth=4: