CPU-Z80-Assembler
view release on metacpan or search on metacpan
t/Program-jumps.t view on Meta::CPAN
use_ok 'CPU::Z80::Assembler::Program';
use_ok 'CPU::Z80::Assembler::JumpOpcode';
use_ok 'CPU::Z80::Assembler::Opcode';
use_ok 'CPU::Z80::Assembler::Expr';
use_ok 'Asm::Preproc::Line';
use_ok 'Asm::Preproc::Token';
my($program, $bytes, $code, %labels);
sub NEW () {
my $caller_line = (caller)[2];
ok $caller_line, "[line $caller_line]";
isa_ok $program = CPU::Z80::Assembler::Program->new(),
'CPU::Z80::Assembler::Program';
$bytes = "";
$code = "";
%labels = ();
}
sub LABEL ($) {
my($label) = @_;
my $caller_line = (caller)[2];
ok $caller_line, "[line $caller_line]";
my $text = "$label:\n";
isa_ok my $line = Asm::Preproc::Line->new($text, "f.asm", 1),
'Asm::Preproc::Line';
$program->add_label($label, $line);
$bytes .= "";
$code .= $text;
$labels{$label} = length($bytes);
}
sub NOPs ($) {
my($num) = @_;
my $caller_line = (caller)[2];
ok $caller_line, "[line $caller_line]";
my $text = " NOP :" x $num . "\n";
isa_ok my $line = Asm::Preproc::Line->new($text, "f.asm", 1),
'Asm::Preproc::Line';
isa_ok my $nops = CPU::Z80::Assembler::Opcode->new(
child => [(0) x $num],
line => $line),
'CPU::Z80::Assembler::Opcode';
$program->add_opcodes($nops);
$bytes .= "\0" x $num;
$code .= $text;
}
sub JUMP ($$$$) {
my($instr, $short_opcodes, $long_opcodes, $instr_bytes) = @_;
my $caller_line = (caller)[2];
ok $caller_line, "[line $caller_line]";
my $label = (split(' ', $instr))[-1];
my $text = " ".$instr."\n";
isa_ok my $line = Asm::Preproc::Line->new($text, "f.asm", 1),
'Asm::Preproc::Line';
isa_ok my $t_name = Asm::Preproc::Token->new(NAME => $label, $line),
'Asm::Preproc::Token';
t/Program-jumps.t view on Meta::CPAN
'CPU::Z80::Assembler::JumpOpcode';
$program->add_opcodes($jump);
for (@$instr_bytes) {
$bytes .= chr($_ & 0xFF);
}
$code .= $text;
}
sub TEST () {
my $caller_line = (caller)[2];
is $program->bytes, $bytes, "[line $caller_line] assembled OK";
is $program->bytes, $bytes, "[line $caller_line] second run also OK";
is z80asm($code), $bytes, "[line $caller_line] z80asm OK";
while (my($label, $value) = each %labels) {
is $program->symbols->{$label}->evaluate, $value,
"[line $caller_line] label $label = $value";
}
}
t/test_utils.pl view on Meta::CPAN
use warnings;
use_ok 'Iterator::Simple::Lookahead';
use_ok 'Asm::Preproc::Line';
use_ok 'CPU::Z80::Assembler::Opcode';
sub opcodes {
my($start, $line_nr) = @_;
my @opcodes;
my $caller_line = (caller)[2];
ok $caller_line, "[line $caller_line] opcodes";
for (0..2) {
isa_ok my $line = Asm::Preproc::Line->new("line ".($line_nr+$_)."\n",
"f.asm", $line_nr+$_),
'Asm::Preproc::Line';
isa_ok my $opcode = CPU::Z80::Assembler::Opcode->new(
child => [ord($start)+$_],
line => $line
), 'CPU::Z80::Assembler::Opcode';
push @opcodes, $opcode;
}
@opcodes;
}
sub test_line { my($text, $line_nr, $file) = @_;
our $stream;
my $caller_line = (caller)[2];
my $token = $stream->next;
isa_ok $token, 'Asm::Preproc::Line';
is $text, $token->text, "[line $caller_line] text";
is $line_nr, $token->line_nr, "[line $caller_line] line_nr";
is $file, $token->file, "[line $caller_line] file";
}
sub test_token_line { my($text, $line_nr, $file) = @_;
our $stream;
our $line;
my $caller_line = (caller)[2];
ok my $token = $stream->peek, "[line $caller_line] peek";
isa_ok $line = $token->line, 'Asm::Preproc::Line';
is $line->text, $text, "[line $caller_line] text";
is $line->line_nr, $line_nr, "[line $caller_line] line_nr";
is $line->file, $file, "[line $caller_line] file";
}
sub test_token { my($type, $value) = @_;
our $stream;
our $line;
my $caller_line = (caller)[2];
ok my $token = $stream->next, "[line $caller_line] drop";
is $token->type, $type, "[line $caller_line] type";
is $token->value, $value, "[line $caller_line] value";
is $token->line->text, $line->text, "[line $caller_line] text";
is $token->line->line_nr, $line->line_nr, "[line $caller_line] line_nr";
is $token->line->file, $line->file, "[line $caller_line] file";
}
sub test_eof {
our $stream;
my $caller_line = (caller)[2];
is $stream->next, undef, "[line $caller_line] eof 1";
is $stream->next, undef, "[line $caller_line] eof 2";
}
1;
( run in 1.156 second using v1.01-cache-2.11-cpan-a3c8064c92c )