tagged release 0.7.1
[parrot.git] / t / compilers / pge / pge_util.t
blobb131595826eb149724f4d2d309d85bb68633cbd6
1 #! perl
2 # Copyright (C) 2001-2007, The Perl Foundation.
3 # $Id$
5 use strict;
6 use warnings;
7 use lib qw( t . lib ../lib ../../lib );
8 use Test::More;
9 use Parrot::Test tests => 8;
10 use Parrot::Test::PGE;
12 =head1 NAME
14 t/library/pge_util.t - Parrot Grammar Engine tests of utility rules
16 =head1 SYNOPSIS
18         % prove -Ilib t/library/pge_util.t
20 =cut
22 my $str = "How will this\nstring choose\nto explode?\n\nTest";
23 p6rule_error_like(
24     $str,
25     "expl <PGE::Util::die: 'kaboom'>",
26     qr/^kaboom at line 3, near "ode\?\\n\\n/, "die"
29 pir_output_is( <<'CODE', <<'OUT', "split /\\:+/, 'Foo::Bar::baz'" );
31 .sub main :main
32   load_bytecode 'PGE.pbc'
33   load_bytecode 'PGE/Util.pir'
35   .local pmc split, p6rule, regex
36   split  = get_global ['PGE::Util'], 'split'
37   p6rule = compreg 'PGE::Perl6Regex'
38   regex  = p6rule('\:+')
40   $P0 = split(regex, "Foo::Bar::baz")
41   $S0 = join "\n", $P0
42   print $S0
43   print "\n"
44 .end
46 CODE
47 Foo
48 Bar
49 baz
50 OUT
52 pir_output_is( <<'CODE', <<'OUT', "split /\\:+/, 'Foo::'" );
54 .sub main :main
55   load_bytecode 'PGE.pbc'
56   load_bytecode 'PGE/Util.pir'
58   .local pmc split, p6rule, regex
59   split  = get_global ['PGE::Util'], 'split'
60   p6rule = compreg 'PGE::Perl6Regex'
61   regex  = p6rule('\:+')
63   $P0 = split(regex, "Foo::")
64   $S0 = join "\n", $P0
65   print $S0
66   print "\n"
67 .end
69 CODE
70 Foo
71 OUT
73 pir_output_is( <<'CODE', <<'OUT', "split /\\:+/, '::Foo'" );
75 .sub main :main
76   load_bytecode 'PGE.pbc'
77   load_bytecode 'PGE/Util.pir'
79   .local pmc split, p6rule, regex
80   split  = get_global ['PGE::Util'], 'split'
81   p6rule = compreg 'PGE::Perl6Regex'
82   regex  = p6rule('\:+')
84   $P0 = split(regex, "::Foo")
85   $S0 = join "\n", $P0
86   print $S0
87   print "\n"
88 .end
90 CODE
92 Foo
93 OUT
95 pir_output_is( <<'CODE', <<'OUT', "split /\\:+/, 'Foo'" );
97 .sub main :main
98   load_bytecode 'PGE.pbc'
99   load_bytecode 'PGE/Util.pir'
101   .local pmc split, p6rule, regex
102   split  = get_global ['PGE::Util'], 'split'
103   p6rule = compreg 'PGE::Perl6Regex'
104   regex  = p6rule('\:+')
106   $P0 = split(regex, "Foo")
107   $S0 = join "\n", $P0
108   print $S0
109   print "\n"
110 .end
112 CODE
116 pir_output_is( <<'CODE', <<'OUT', "split /\\:/, 'Foo::Bar'" );
118 .sub main :main
119   load_bytecode 'PGE.pbc'
120   load_bytecode 'PGE/Util.pir'
122   .local pmc split, p6rule, regex
123   split  = get_global ['PGE::Util'], 'split'
124   p6rule = compreg 'PGE::Perl6Regex'
125   regex  = p6rule('\:')
127   $P0 = split(regex, "Foo::Bar")
128   $S0 = join "\n", $P0
129   print $S0
130   print "\n"
131 .end
133 CODE
139 pir_output_is( <<'CODE', <<'OUT', "split /\\:/, 'Foo::Bar::Baz', 2" );
141 .sub main :main
142   load_bytecode 'PGE.pbc'
143   load_bytecode 'PGE/Util.pir'
145   .local pmc split, p6rule, regex
146   split  = get_global ['PGE::Util'], 'split'
147   p6rule = compreg 'PGE::Perl6Regex'
148   regex  = p6rule('\:+')
150   $P0 = split(regex, "Foo::Bar::Baz", 2)
151   $S0 = join "\n", $P0
152   print $S0
153   print "\n"
154 .end
156 CODE
158 Bar::Baz
161 pir_output_is( <<'CODE', <<'OUT', "split /(a)(b)/, 'abracadabra'" );
163 .sub main :main
164   load_bytecode 'PGE.pbc'
165   load_bytecode 'PGE/Util.pir'
167   .local pmc split, p6rule, regex
168   split  = get_global ['PGE::Util'], 'split'
169   p6rule = compreg 'PGE::Perl6Regex'
170   regex  = p6rule('(a)(b)')
172   $P0 = split(regex, "abracadabra")
173   $S0 = join "-", $P0
174   print $S0
175   print "\n"
176 .end
178 CODE
179 -a-b-racad-a-b-ra
182 # Local Variables:
183 #   mode: cperl
184 #   cperl-indent-level: 4
185 #   fill-column: 100
186 # End:
187 # vim: expandtab shiftwidth=4: