Acme-Aheui
view release on metacpan or search on metacpan
t/01_aheui.t view on Meta::CPAN
#!/usr/bin/env perl
use utf8;
use strict;
use warnings;
use Test::More;
use Capture::Tiny ':all';
use Encode qw/decode/;
BEGIN {
use_ok( 'Acme::Aheui' );
}
{ # new interpreter and its internal codespace
my $source = "ê°ê°\r\ní¢í£\nA *";
my $interpreter = Acme::Aheui->new( source => $source );
ok( $interpreter );
is( $$interpreter{_codespace}[0][0]{cho}, 0 );
is( $$interpreter{_codespace}[0][0]{jung}, 0 );
is( $$interpreter{_codespace}[0][0]{jong}, 0 );
is( $$interpreter{_codespace}[0][1]{cho}, 0 );
is( $$interpreter{_codespace}[0][1]{jung}, 0 );
is( $$interpreter{_codespace}[0][1]{jong}, 1 );
is( $$interpreter{_codespace}[1][0]{cho}, 18 );
is( $$interpreter{_codespace}[1][0]{jung}, 20 );
is( $$interpreter{_codespace}[1][0]{jong}, 26 );
is( $$interpreter{_codespace}[1][1]{cho}, 18 );
is( $$interpreter{_codespace}[1][1]{jung}, 20 );
is( $$interpreter{_codespace}[1][1]{jong}, 27 );
is( $$interpreter{_codespace}[2][0]{cho}, -1 );
is( $$interpreter{_codespace}[2][0]{jung}, -1 );
is( $$interpreter{_codespace}[2][0]{jong}, -1 );
is( $$interpreter{_codespace}[2][1]{cho}, -1 );
is( $$interpreter{_codespace}[2][1]{jung}, -1 );
is( $$interpreter{_codespace}[2][1]{jong}, -1 );
is( $$interpreter{_codespace}[2][2]{cho}, -1 );
is( $$interpreter{_codespace}[2][2]{jung}, -1 );
is( $$interpreter{_codespace}[2][2]{jong}, -1 );
}
{ # move cursor
my $source = <<'__SOURCE__';
ê°ëë¤
ë¼ë§
ë°ì¬ììì°¨
ì¹´
ííí
__SOURCE__
my $interpreter = Acme::Aheui->new( source => $source );
is( $interpreter->{_x}, 0 );
is( $interpreter->{_y}, 0 );
is( $interpreter->{_dx}, 0 );
is( $interpreter->{_dy}, 1 );
$interpreter->{_dx} = 1;
$interpreter->{_dy} = 0;
$interpreter->_move_cursor();
is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [1, 0] );
$interpreter->_move_cursor();
is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [2, 0] );
$interpreter->_move_cursor();
is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [0, 0] );
$interpreter->_move_cursor();
is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [1, 0] );
$interpreter->{_dx} = -1;
$interpreter->_move_cursor();
is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [0, 0] );
$interpreter->_move_cursor();
is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [2, 0] );
$interpreter->_move_cursor();
is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [1, 0] );
$interpreter->_move_cursor();
is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [0, 0] );
$interpreter->_move_cursor();
is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [2, 0] );
$interpreter->{_dx} = 0;
$interpreter->{_dy} = 1;
$interpreter->_move_cursor();
is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [2, 1] );
$interpreter->_move_cursor();
is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [2, 2] );
$interpreter->_move_cursor();
is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [2, 3] );
$interpreter->_move_cursor();
is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [2, 4] );
$interpreter->_move_cursor();
is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [2, 0] );
$interpreter->_move_cursor();
is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [2, 1] );
$interpreter->{_dy} = -1;
$interpreter->_move_cursor();
is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [2, 0] );
$interpreter->_move_cursor();
is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [2, 4] );
$interpreter->{_dx} = 2;
$interpreter->{_dy} = 0;
$interpreter->_move_cursor();
is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [0, 4] );
$interpreter->_move_cursor();
is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [2, 4] );
$interpreter->_move_cursor();
is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [0, 4] );
$interpreter->{_dx} = -2;
$interpreter->_move_cursor();
is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [2, 4] );
$interpreter->_move_cursor();
is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [0, 4] );
$interpreter->_move_cursor();
is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [2, 4] );
$interpreter->{_dx} = 0;
$interpreter->{_dy} = 2;
$interpreter->_move_cursor();
is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [2, 0] );
$interpreter->_move_cursor();
is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [2, 2] );
$interpreter->_move_cursor();
is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [2, 4] );
$interpreter->{_dy} = -2;
$interpreter->_move_cursor();
is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [2, 2] );
$interpreter->_move_cursor();
is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [2, 0] );
$interpreter->_move_cursor();
is_deeply( [$interpreter->{_x}, $interpreter->{_y}], [2, 4] );
}
{ # storages
my $counter = 0;
sub test_stack {
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 $out3 = $interpreter->_pop($storage_index);
my $out2 = $interpreter->_pop($storage_index);
my $out1 = $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( $later_in, $out_dup1 );
is( $later_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, $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++);
( run in 2.611 seconds using v1.01-cache-2.11-cpan-98e64b0badf )