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 # Library semantics. #
13 #--------------------------------------#
16 use Language::Befunge;
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' );
56 is( $out, "Hello world!\n" );
58 sel; # interact with IP
59 $bef->store_code( <<'END_OF_CODE' );
60 "OLEH" 4 ( S > :# #, _ q
64 is( $out, "Hello world!\n" );
66 sel; # unknown extension
67 $bef->store_code( <<'END_OF_CODE' );
75 sel; # negative fingerprint
76 $bef->store_code( <<'END_OF_CODE' );
79 eval { $bef->run_code; };
80 like( $@, qr/Attempt to build a fingerprint with a negative number/,
81 "loading a library with a negative fingerprint barfs" );
82 BEGIN { $tests += 4 };
87 $bef->store_code( <<'END_OF_CODE' );
88 "OLEH" 4 ( "OOF" 3 ( P q
93 BEGIN { $tests += 1 };
98 $bef->store_code( <<'END_OF_CODE' );
99 "OLEH" 4 ( "OOF" 3 ( S > :# #, _ q
103 is( $out, "Hello world!\n" );
104 BEGIN { $tests += 1 };
108 sel; # normal unloading.
109 $bef->store_code( <<'END_OF_CODE' );
110 "OLEH" 4 ( "OOF" 3 ( P ) P q
114 is( $out, "fooHello world!\n" );
116 sel; # unloading under stack.
117 $bef->store_code( <<'END_OF_CODE' );
118 "OLEH" 4 ( "OOF" 3 ( P "OLEH" 4 ) P #v S 2.q
123 is( $out, "foofoo1 " );
125 sel; # unloading non-loaded extension.
126 $bef->store_code( <<'END_OF_CODE' );
127 "OLEH" 4 ( "JAVA" 4 #v ) 2.q
134 sel; # negative fingerprint
135 $bef->store_code( <<'END_OF_CODE' );
138 eval { $bef->run_code; };
139 like( $@, qr/Attempt to build a fingerprint with a negative number/,
140 "unloading a library with a negative fingerprint barfs" );
141 BEGIN { $tests += 4 };
144 BEGIN { plan tests => $tests };