3 # This file is part of Language::Befunge.
4 # Copyright (c) 2001-2008 Jerome Quelin, all rights reserved.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the same terms as Perl itself.
11 #---------------------------------#
13 #---------------------------------#
16 use Language::Befunge;
17 use Language::Befunge::IP;
18 use Language::Befunge::Vector;
19 use POSIX qw! tmpnam !;
27 my $bef = Language::Befunge->new;
30 # In order to see what happens...
33 open OUT, ">$file" or die $!;
39 open OUT, "<$file" or die $!;
52 $bef->store_code( <<'END_OF_CODE' );
58 BEGIN { $tests += 1 };
62 $bef->store_code( <<'END_OF_CODE' );
63 zzzfzzzfzz+zzzzz7zzzzzzz+zz,zzzq
68 BEGIN { $tests += 1 };
72 $bef->store_code( <<'END_OF_CODE' );
78 BEGIN { $tests += 1 };
82 $bef->store_code( <<'END_OF_CODE' );
88 BEGIN { $tests += 1 };
90 # Comments / Jump over.
92 $bef->store_code( <<'END_OF_CODE' );
93 2;this is a comment;1+.@
98 BEGIN { $tests += 1 };
102 $bef->store_code( <<'END_OF_CODE' );
109 $bef->store_code( <<'END_OF_CODE' );
116 $bef->store_code( <<'END_OF_CODE' );
123 BEGIN { $tests += 3 };
127 $bef->store_code( <<'END_OF_CODE' );
130 my $rv = $bef->run_code;
134 BEGIN { $tests += 2 };
136 # Repeat instruction (glurps).
137 sel; # normal repeat.
138 $bef->store_code( <<'END_OF_CODE' );
143 ok( $out, "7 5 3 " );
145 $bef->store_code( <<'END_OF_CODE' );
151 sel; # useless repeat.
152 $bef->store_code( <<'END_OF_CODE' );
160 sel; # repeat negative.
161 $bef->store_code( <<'END_OF_CODE' );
164 eval { $bef->run_code; };
167 sel; # repeat forbidden char.
168 $bef->store_code( <<'END_OF_CODE' );
171 eval { $bef->run_code; };
174 sel; # repeat repeat.
175 $bef->store_code( <<'END_OF_CODE' );
178 eval { $bef->run_code; };
181 sel; # move_ip() short circuits on a dead end
182 $bef->store_code( <<'END_OF_CODE' );
185 $bef->set_curip( Language::Befunge::IP->new );
186 $bef->get_curip->set_position( Language::Befunge::Vector->new_zeroes(2) );
188 local $SIG{ALRM} = sub { die "timeout\n" };
190 $bef->move_ip($bef->get_curip, qr/ /);
194 ok( $@, qr/infinite loop/ );
195 BEGIN { $tests += 7 };
199 BEGIN { plan tests => $tests };