ported to test::output
[language-befunge.git] / t / 4-interpreter / befunge.t
blobd6b611e326434475c16e0f1e6f23fc916153d3bb
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 use strict;
12 use warnings;
14 use Language::Befunge;
16 use Test::More tests => 10;
17 use Test::Output;
19 my $bef;
22 # basic constructor.
23 $bef = Language::Befunge->new( {file => "t/_resources/q.bf"} );
24 stdout_is { $bef->run_code } '', 'constructor works';
27 # debug tests.
28 stderr_is { $bef->debug( "foo\n" ) } '',      'DEBUG is off by default';
29 $bef->set_DEBUG(1);
30 stderr_is { $bef->debug( "bar\n" ) } "bar\n", 'debug warns properly when DEBUG is on';
31 $bef->set_DEBUG(0);
32 stderr_is { $bef->debug( "baz\n" ) } '',      'debug does not warn when DEBUG is off';
35 # basic reading.
36 $bef = Language::Befunge->new;
37 $bef->read_file( 't/_resources/q.bf' );
38 stdout_is { $bef->run_code } '', 'basic reading';
41 # reading a non existent file.
42 eval { $bef->read_file( '/dev/a_file_that_is_not_likely_to_exist' ); };
43 like( $@, qr/line/, 'reading a non-existent file barfs' );
46 # basic storing.
47 $bef->store_code( <<'END_OF_CODE' );
49 END_OF_CODE
50 stdout_is { $bef->run_code } '', 'basic storing';
53 # interpreter must treat non-characters as if they were an 'r' instruction.
54 $bef->store_code( <<'END_OF_CODE' );
55 01-b0p#q1.2 q
56 END_OF_CODE
57 stdout_is { $bef->run_code } '1 2 ', 'non-chars treated as "r" instruction';
60 # interpreter must treat non-commands as if they were an 'r' instruction.
61 $bef->store_code( <<'END_OF_CODE' );
62 01+b0p#q1.2 q
63 END_OF_CODE
64 stdout_is { $bef->run_code } '1 2 ', 'non-commands treated as "r" instruction';
67 # befunge interpreter treats high/low instructions as unknown characters.
68 $bef->store_code( <<"END_OF_CODE" );
69 1#q.2h3.q
70 END_OF_CODE
71 stdout_is { $bef->run_code } '1 2 ', 'high/low treated as "r" instruction';