package ATR::CheckbarcodeTest;

use strict;
use warnings;
use base qw(McaTestCase);

use ATR::Checkbarcode_zeropadding_ok;

sub test_uglies {
    my $self = shift;

    my @ugly = ('AB 423C', qw( AB423 ab423c ZZ999 Ab423C AB423c AB42*3C ABC423D ));

    foreach my $ug (@ugly) {
	$self->fail("'$ug' passed barcodeShaped") if barcodeShaped($ug);
	my $ret = eval {
	    my @parts = Verifynumber($ug);
	    "got (@parts)";
	};
	$self->fail("'$ug' returned a Verifynumber") if defined $ret;
    }

    $self->assert_dies(qr/^Call /,
		       sub { Verifynumber("AM305P", "AM") },
		       sub { barcodeShaped("AM305P", "AM") },
		      );
}

sub test_bads {
    my $self = shift;

    my @bad = qw(AB423C AB00356C AM305Q AB7343D DJ52345E ZZ999Z AA000A );

    foreach my $bad (@bad) {
	$self->fail("'$bad' failed barcodeShaped") unless barcodeShaped($bad);
	my @parts = Verifynumber($bad);
	$self->fail("'$bad' returned (@parts)") if @parts;
    }
}

sub test_goods {
    my $self = shift;
    my %good = ( AM305P => [AM => 305],
		 AM0305E => [AM => '0305'],
		 AM00305S => [AM => '00305'],
		 AA0F => [AA => 0],
		 AA00B => [AA => '00'],
		 ZZ999C => [ZZ => 999],
	       );
    foreach my $scanned (keys %good) {
	my @exp = @{ $good{$scanned} };
	$self->assert_deep_equals(\@exp, [ Verifynumber($scanned) ]);
	$self->assert_str_equals(makeID(@exp), $scanned);
	$self->assert_str_equals(makeID($exp[0].$exp[1]), $scanned);
    }
}


1;
