aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2017-03-03 14:12:42 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2017-03-03 14:12:42 +0200
commit14c6474d73fae6aeaa77dd19e10cf5615448aefb (patch)
treef887ea9cac45d395a6337bb7954482f41a8a667e
parent8fbdd4a7c56de2752c866ce3283d3bdbca3ed8bb (diff)
downloadbeam-14c6474d73fae6aeaa77dd19e10cf5615448aefb.tar.gz
beam-14c6474d73fae6aeaa77dd19e10cf5615448aefb.tar.bz2
Locus: correctly handle uninitialized locations
-rw-r--r--lib/App/Beam/Config/Locus.pm13
-rw-r--r--t/locus.t6
2 files changed, 16 insertions, 3 deletions
diff --git a/lib/App/Beam/Config/Locus.pm b/lib/App/Beam/Config/Locus.pm
index 050e5bb..7d1087c 100644
--- a/lib/App/Beam/Config/Locus.pm
+++ b/lib/App/Beam/Config/Locus.pm
@@ -69,7 +69,9 @@ sub add {
Returns a string representation of the locus. The argument is optional.
If given, its string representation will be concatenated to the formatted
-locus with a ": " in between. This is useful for formatting error messages.
+locus with a ": " in between. If multiple arguments are supplied, their
+string representations will be concatenated, separated by horizontal
+space characters. This is useful for formatting error messages.
If the locus contains multiple file locations, the method tries to compact
them by representing contiguous line ranges as B<I<X>-I<Y>> and outputting
@@ -93,6 +95,7 @@ will produce the following:
sub format {
my $self = shift;
unless (exists($self->{string})) {
+ $self->{string} = '';
foreach my $file (sort {
$self->{table}{$a}{order} <=> $self->{table}{$b}{order}
}
@@ -124,7 +127,13 @@ sub format {
$self->{string} .= join(',', @ranges);
}
}
- return "$self->{string}: $_[0]" if @_;
+ if (@_) {
+ if ($self->{string} ne '') {
+ return "$self->{string}: " . join(' ', @_);
+ } else {
+ return join(' ', @_);
+ }
+ }
return $self->{string};
}
diff --git a/t/locus.t b/t/locus.t
index a08280b..19fc8cc 100644
--- a/t/locus.t
+++ b/t/locus.t
@@ -3,9 +3,12 @@ use strict;
use Test;
use App::Beam::Config::Locus;
-plan(tests => 7);
+plan(tests => 10);
my $loc = new App::Beam::Config::Locus;
+ok($loc->format, '');
+ok($loc->format('test', 'message'), 'test message');
+
$loc->add('foo', 10);
ok($loc->format, "foo:10");
@@ -17,6 +20,7 @@ ok($loc->format, "foo:10-13");
$loc->add('foo', 24);
$loc->add('foo', 28);
ok($loc->format, "foo:10-13,24,28");
+ok($loc->format('test', 'message'), "foo:10-13,24,28: test message");
$loc->add('bar', 1);
$loc->add('baz', 8);

Return to:

Send suggestions and report system problems to the System administrator.