Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
catch issues with ? locations, passes tests
  • Loading branch information
Chris Fields committed Feb 26, 2012
1 parent 2c889e7 commit 0d64c7f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
20 changes: 10 additions & 10 deletions lib/Biome/Factory/FTLocationFactory.pm
Expand Up @@ -38,7 +38,7 @@ my ($LOC_CLASS, $DEF_STR);
sub BUILD {
my ($self) = @_;
$self->load_modules($self->locatable_class);
($LOC_CLASS, $DEF_STR) = ($self->locatable_class, $self->default_string);
($LOC_CLASS, $DEF_STR) = ($self->locatable_class, $self->default_strand);
}

sub from_string {
Expand Down Expand Up @@ -84,7 +84,7 @@ sub from_string {
$loc_obj = $self->_parse_range($splitlocs[0]);
$loc_obj->strand(-1);
} else {
$loc_obj = $self->locatable_class->new(-location_type => uc $oparg);
$loc_obj = $LOC_CLASS->new(-location_type => uc $oparg);
my @loc_objs = map {
my $sobj;
if (m{\(($LOCREG)\)}) {
Expand Down Expand Up @@ -120,7 +120,7 @@ sub from_string {
scalar(@loc_objs).", should be SplitLocationI");
}
if ($ct > 1) {
$loc = $self->locatable_class->new();
$loc = $LOC_CLASS->new();
$loc->add_sub_Locations(\@loc_objs);
return $loc;
} else {
Expand All @@ -137,10 +137,9 @@ my @STRING_ORDER = qw(start loc_type end);

sub _parse_range {
my ($self, $string) = @_;
return unless $string;

my %atts;
$atts{strand} = $self->default_strand;
$atts{strand} = $DEF_STR;

my @loc_data = split(/(\.{2}|\^|\:)/, $string);

Expand All @@ -157,7 +156,7 @@ sub _parse_range {
$str =~ s{[\[\]\(\)]+}{}g;
if ($str =~ /^([<>\?])?(\d+)?$/) {
$atts{"${order}_pos_type"} = $1 if $1;
$atts{$order} = $2;
$atts{$order} = $2 if $2;
} elsif ($str =~ /^(\d+)\.(\d+)$/) {
$atts{"${order}_pos_type"} = '.';
$atts{$order} = $1;
Expand All @@ -169,17 +168,18 @@ sub _parse_range {
$atts{location_type} = $str;
}
}

if ($atts{start_pos_type} && $atts{start_pos_type} eq '.' &&
(!$atts{end} && !$atts{end_pos_type})
) {
$atts{end} = $atts{start} + $atts{start_offset};
delete @atts{qw(start_offset start_pos_type end_pos_type)};
$atts{location_type} = '.';
}
$atts{end} ||= $atts{start} unless $atts{end_pos_type};

# TODO: will very likely bork w/o all atts defined...
return $self->locatable_class->new(%atts);
unless ($atts{end_pos_type} || !$atts{start}) {
$atts{end} ||= $atts{start}
}
return $LOC_CLASS->new(%atts);
}

}
Expand Down
24 changes: 12 additions & 12 deletions t/Factory/FTLocationFactory.t
Expand Up @@ -54,21 +54,21 @@ my %testcases = (
22, 22, "EXACT", 64, 64, "UNCERTAIN", "EXACT", 0, 1, undef],
"?22..?64" => [0,
22, 22, "UNCERTAIN", 64, 64, "UNCERTAIN", "EXACT", 0, 1, undef],
#"?..>393" => [0,
# undef, undef, "UNCERTAIN", 393, undef, "AFTER", "EXACT", 0, 1, undef],
#"<1..?" => [0,
# undef, 1, "BEFORE", undef, undef, "UNCERTAIN", "EXACT", 0, 1, undef],
#"?..536" => [0,
# undef, undef, "UNCERTAIN", 536, 536, "EXACT", "EXACT", 0, 1, undef],
#"1..?" => [0,
# 1, 1, "EXACT", undef, undef, "UNCERTAIN", "EXACT", 0, 1, undef],
#"?..?" => [0,
# undef, undef, "UNCERTAIN", undef, undef, "UNCERTAIN", "EXACT", 0, 1, undef],
"?..>393" => [0,
undef, undef, "UNCERTAIN", 393, undef, "AFTER", "EXACT", 0, 1, undef],
"<1..?" => [0,
undef, 1, "BEFORE", undef, undef, "UNCERTAIN", "EXACT", 0, 1, undef],
"?..536" => [0,
undef, undef, "UNCERTAIN", 536, 536, "EXACT", "EXACT", 0, 1, undef],
"1..?" => [0,
1, 1, "EXACT", undef, undef, "UNCERTAIN", "EXACT", 0, 1, undef],
"?..?" => [0,
undef, undef, "UNCERTAIN", undef, undef, "UNCERTAIN", "EXACT", 0, 1, undef],
"1..?12" => [0,
1, 1, "EXACT", 12, 12, "UNCERTAIN", "EXACT", 0, 1, undef],
# Not sure if this is legal...
#"?" => [0,
# undef, undef, "UNCERTAIN", undef, undef, "EXACT", "EXACT", 0, 1, undef],
"?" => [0,
undef, undef, "UNCERTAIN", undef, undef, "EXACT", "EXACT", 0, 1, undef],

# SPLITS

Expand Down

0 comments on commit 0d64c7f

Please sign in to comment.