Acme-Aheui
view release on metacpan or search on metacpan
t/01_aheui.t view on Meta::CPAN
is( $first_in, $first_out );
is( $later_in, $later_out );
}
sub test_queue {
my ($interpreter, $storage_index) = @_;
# a push and a pop
my $in = $counter++;
$interpreter->_push($storage_index, $in);
my $out = $interpreter->_pop($storage_index);
is( $in, $out );
# pushes, pops
my ($in1, $in2, $in3) = ($counter++, $counter++, $counter++);
$interpreter->_push($storage_index, $in1);
$interpreter->_push($storage_index, $in2);
$interpreter->_push($storage_index, $in3);
my $out1 = $interpreter->_pop($storage_index);
my $out2 = $interpreter->_pop($storage_index);
my $out3 = $interpreter->_pop($storage_index);
is_deeply( [$in1, $in2, $in3], [$out1, $out2, $out3] );
# duplicate
my $first_in = $counter++;
my $later_in = $counter++;
$interpreter->_push($storage_index, $first_in);
$interpreter->_push($storage_index, $later_in);
$interpreter->_duplicate($storage_index);
my $out_dup1 = $interpreter->_pop($storage_index);
my $out_dup2 = $interpreter->_pop($storage_index);
is( $first_in, $out_dup1 );
is( $first_in, $out_dup2 );
$interpreter->_pop($storage_index);
# swap
$first_in = $counter++;
$later_in = $counter++;
$interpreter->_push($storage_index, $first_in);
$interpreter->_push($storage_index, $later_in);
$interpreter->_swap($storage_index);
my $first_out = $interpreter->_pop($storage_index);
my $later_out = $interpreter->_pop($storage_index);
is( $first_in, $later_out );
is( $later_in, $first_out );
}
my $interpreter = Acme::Aheui->new( source => '' );
for my $i (0..26) {
if ($i == 21) { # ã
queue
test_queue($interpreter, $i);
}
else { # '', ã±, ã´, ... ã
, ã
, .. ã
stack
test_stack($interpreter, $i);
}
}
}
{ # termination code
my $source = 'ë° í';
my ($stdout, $stderr, @result) = capture {
my $interpreter = Acme::Aheui->new( source => $source );
$interpreter->execute();
};
is( $stdout, '' );
is( $stderr, '' );
is( $result[0], 7 );
}
{ # hello world
my $source = << '__SOURCE__';
밤밣ë°ë¹ ë°£ë°ë°ë¿
ë¹ ë§£í빨ë°ë°¤ëë
ëë°¬íë¹ ë§£ë¶ëë¶
ë³»ë«ë°ë°ë·í¬ëë¶
ë«ëë«í¬ë©ëëë¶
ë«ë´í ë²ëë²ë¿ë
ë½ë½ë©ë©ëë²ë»ë
ë½ë©ë²ë©ë»ëëë²
__SOURCE__
my ($stdout, $stderr, @result) = capture {
my $interpreter = Acme::Aheui->new( source => $source );
$interpreter->execute();
};
is( $stdout, "Hello, world!\n" );
is( $stderr, '' );
}
{ # exit without infinite loop in case of null program
my ($stdout, $stderr, @result) = capture {
my $interpreter = Acme::Aheui->new( source => '' );
$interpreter->execute();
};
is( $stdout, '' );
is( $stderr, '' );
}
{ # exit without infinite loop in case of no initial command
my $source = "abc\ndef\nghi\n\n\n_ë°ë°§ëë§í\n";
my ($stdout, $stderr, @result) = capture {
my $interpreter = Acme::Aheui->new( source => $source );
$interpreter->execute();
};
is( $stdout, '' );
is( $stderr, '' );
}
{ # input number
my ($stdout, $stderr, @result) = capture {
my $stdin;
open($stdin,'<&STDIN');
*STDIN = *DATA;
my $interpreter = Acme::Aheui->new( source => 'ë°©ë¹ ë§ë§í' );
$interpreter->execute();
*STDIN = $stdin;
};
is( $stdout, '369369' );
is( $stderr, '' );
}
{ # input characters
my ($stdout, $stderr, @result) = capture {
my $stdin;
open($stdin,'<&STDIN');
*STDIN = *DATA;
my $interpreter = Acme::Aheui->new(
source => '밯밯맣맣í',
output_encoding => 'utf-8',
);
$interpreter->execute();
*STDIN = $stdin;
};
is( decode('utf-8', $stdout), '몽ì¦' );
is( $stderr, '' );
}
done_testing();
__DATA__
369
ì¦ëª½
( run in 2.078 seconds using v1.01-cache-2.11-cpan-140bd7fdf52 )