syntax trefunge98 now supported
[language-befunge.git] / t / 2-ops / math_addition.t
blob38e281a9793f8eaa8fe0b25f4cdc66cb681dcef8
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 Language::Befunge::Ops;
13 use strict;
14 use warnings;
16 use Language::Befunge::Interpreter;
17 use Language::Befunge::IP;
18 use Language::Befunge::Ops;
19 use Test::More tests => 4;
21 my ($lbi, $ip, $v);
24 $lbi = Language::Befunge::Interpreter->new;
25 $ip  = Language::Befunge::IP->new;
26 $lbi->set_curip( $ip );
28 $ip->spush( 21, 42, 63 );
29 Language::Befunge::Ops::math_addition( $lbi );
30 is( $ip->spop, 105, 'math_addition pushes new value' );
31 is( $ip->spop, 21,  'math_addition pops only two values' );
33 SKIP: {
34     eval { require Test::Exception; Test::Exception->import; };
35     skip 'need Test::Exception', 2 unless defined $Test::Exception::VERSION;
36     # overflow
37     $ip->spush( 2**31-2, 3 );
38     throws_ok( sub { Language::Befunge::Ops::math_addition($lbi) },
39         qr/overflow/, 'math_addition barfs on overflow' );
40     # underflow
41     $ip->spush( -2**31+2, -3 );
42     throws_ok( sub { Language::Befunge::Ops::math_addition($lbi) },
43         qr/under/, 'math_addition barfs on underflow' );