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;
t/01_aheui.t view on Meta::CPAN
{ # 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 1.882 second using v1.01-cache-2.11-cpan-5735350b133 )