From 9d2a5fee86ceae105315fab72bab25616de8908e Mon Sep 17 00:00:00 2001 From: David Given Date: Tue, 18 May 2021 21:09:31 +0200 Subject: [PATCH] Range ends default to range start. --- lib/proto.cc | 3 ++- tests/proto.cc | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/proto.cc b/lib/proto.cc index c35eabe7..a14ea801 100644 --- a/lib/proto.cc +++ b/lib/proto.cc @@ -172,7 +172,8 @@ void setProtoByString(google::protobuf::Message* message, const std::string& pat std::set iterate(const RangeProto& range) { std::set set; - for (unsigned i=range.start(); i<=range.end(); i+=range.step()) + int end = range.has_end()? range.end() : range.start(); + for (unsigned i=range.start(); i<=end; i+=range.step()) set.insert(i); return set; } diff --git a/tests/proto.cc b/tests/proto.cc index c57f2add..cf341063 100644 --- a/tests/proto.cc +++ b/tests/proto.cc @@ -125,6 +125,13 @@ static void test_range(void) AssertThat(iterate(r), Equals(std::set{1})); } + { + RangeProto r; + r.set_start(1); + + AssertThat(iterate(r), Equals(std::set{1})); + } + { RangeProto r; setRange(&r, "1-3");