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::Vector;
18 use POSIX qw! tmpnam !;
26 my $bef = Language::Befunge->new;
29 # In order to see what happens...
32 open OUT, ">$file" or die $!;
38 open OUT, "<$file" or die $!;
51 $bef->store_code( <<'END_OF_CODE' );
57 BEGIN { $tests += 1 };
61 $bef->store_code( <<'END_OF_CODE' );
62 zzzfzzzfzz+zzzzz7zzzzzzz+zz,zzzq
67 BEGIN { $tests += 1 };
71 $bef->store_code( <<'END_OF_CODE' );
77 BEGIN { $tests += 1 };
81 $bef->store_code( <<'END_OF_CODE' );
87 BEGIN { $tests += 1 };
89 # Comments / Jump over.
91 $bef->store_code( <<'END_OF_CODE' );
92 2;this is a comment;1+.@
97 BEGIN { $tests += 1 };
101 $bef->store_code( <<'END_OF_CODE' );
108 $bef->store_code( <<'END_OF_CODE' );
115 $bef->store_code( <<'END_OF_CODE' );
122 BEGIN { $tests += 3 };
126 $bef->store_code( <<'END_OF_CODE' );
129 my $rv = $bef->run_code;
133 BEGIN { $tests += 2 };
135 # Repeat instruction (glurps).
136 sel; # normal repeat.
137 $bef->store_code( <<'END_OF_CODE' );
144 $bef->store_code( <<'END_OF_CODE' );
150 sel; # useless repeat.
151 $bef->store_code( <<'END_OF_CODE' );
158 sel; # repeat negative.
159 $bef->store_code( <<'END_OF_CODE' );
162 eval { $bef->run_code; };
164 ok( $@, qr/Attempt to repeat \('k'\) a negative number of times \(-5\)/ );
165 sel; # repeat forbidden char.
166 $bef->store_code( <<'END_OF_CODE' );
169 eval { $bef->run_code; };
171 ok( $@, qr/Attempt to repeat \('k'\) a forbidden instruction \(';'\)/ );
172 sel; # repeat repeat.
173 $bef->store_code( <<'END_OF_CODE' );
176 eval { $bef->run_code; };
178 ok( $@, qr/Attempt to repeat \('k'\) a repeat instruction \('k'\)/ );
179 sel; # move_curip() short circuits on a dead end
180 $bef->store_code( <<'END_OF_CODE' );
183 $bef->get_curip->set_position( Language::Befunge::Vector->new_zeroes(2) );
185 local $SIG{ALRM} = sub { die "timeout\n" };
187 $bef->move_curip(qr/ /);
191 ok( $@, qr/infinite loop/ );
192 BEGIN { $tests += 7 };
196 BEGIN { plan tests => $tests };