syntax error fix in makefile.pl
[language-befunge.git] / t / 4-interpreter / unefunge.t
blob9b227b9da109606db168574c0e9d9381b2d51bb4
1 #!perl
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 #-----------------------------------#
12 #          Exported funcs.          #
13 #-----------------------------------#
15 use strict;
16 use Language::Befunge;
17 use POSIX qw! tmpnam !;
18 use Test;
20 # Vars.
21 my ($file, $fh);
22 my $tests;
23 my $out;
24 my $unef = Language::Befunge->new( {syntax=>'unefunge98'} );
25 BEGIN { $tests = 0 };
27 # In order to see what happens...
28 sub sel () {
29     $file = tmpnam();
30     open OUT, ">$file" or die $!;
31     $fh = select OUT;
33 sub slurp () {
34     select $fh;
35     close OUT;
36     open OUT, "<$file" or die $!;
37     my $content;
38     {
39         local $/;
40         $content = <OUT>;
41     }
42     close OUT;
43     unlink $file;
44     return $content;
47 # Basic constructor.
48 sel;
49 $unef = Language::Befunge->new( {file=>'t/_resources/q.bf', syntax=>'unefunge98'} );
50 $unef->run_code;
51 $out = slurp;
52 ok( $out, "" );
53 BEGIN { $tests += 1 };
55 # Basic reading.
56 $unef = Language::Befunge->new( {syntax=>'unefunge98'} );
57 sel;
58 $unef->read_file( "t/_resources/q.bf" );
59 $unef->run_code;
60 $out = slurp;
61 ok( $out, "" );
62 BEGIN { $tests += 1 };
64 # Basic storing.
65 sel;
66 $unef->store_code( <<'END_OF_CODE' );
68 END_OF_CODE
69 $unef->run_code;
70 $out = slurp;
71 ok( $out, "" );
72 BEGIN { $tests += 1 };
74 # Interpreter must treat non-characters as if they were an 'r' instruction.
75 sel;
76 $unef->store_code( <<'END_OF_CODE' );
77 01-ap#q1.2 q
78 END_OF_CODE
79 $unef->run_code;
80 $out = slurp;
81 ok( $out, "1 2 " );
82 BEGIN { $tests += 1 };
84 # Interpreter must treat non-commands as if they were an 'r' instruction.
85 sel;
86 $unef->store_code( <<'END_OF_CODE' );
87 01+ap#q1.2 q
88 END_OF_CODE
89 $unef->run_code;
90 $out = slurp;
91 ok( $out, "1 2 " );
92 BEGIN { $tests += 1 };
94 # Unefunge Interpreter treats North/South instructions as unknown characters.
95 sel;
96 $unef->store_code( <<"END_OF_CODE" );
97 1#q.2^3.q
98 END_OF_CODE
99 $unef->run_code;
100 $out = slurp;
101 ok( $out, "1 2 " );
102 BEGIN { $tests += 1 };
104 BEGIN { plan tests => $tests };