@@ -194,7 +194,7 @@ CreateFakeModule(std::vector<std::unique_ptr<LineSequence>> line_sequences) {
194194 std::move (text_sp), line_table};
195195}
196196
197- TEST_F (LineTableTest, LowerAndUpperBound ) {
197+ TEST_F (LineTableTest, lower_bound ) {
198198 LineSequenceBuilder builder;
199199 builder.Entry (0 );
200200 builder.Entry (10 );
@@ -211,41 +211,63 @@ TEST_F(LineTableTest, LowerAndUpperBound) {
211211
212212 auto make_addr = [&](addr_t addr) { return Address (fixture->text_sp , addr); };
213213
214- // Both functions return the same value for boundary values. This way the
215- // index range for e.g. [0,10) is [0,1).
216214 EXPECT_EQ (table->lower_bound (make_addr (0 )), 0u );
217- EXPECT_EQ (table->upper_bound (make_addr (0 )), 0u );
215+ EXPECT_EQ (table->lower_bound (make_addr (9 )), 0u );
218216 EXPECT_EQ (table->lower_bound (make_addr (10 )), 1u );
219- EXPECT_EQ (table->upper_bound (make_addr (10 )), 1u );
217+ EXPECT_EQ (table->lower_bound (make_addr (19 )), 1u );
218+
219+ // Skips over the terminal entry.
220220 EXPECT_EQ (table->lower_bound (make_addr (20 )), 3u );
221- EXPECT_EQ (table->upper_bound (make_addr (20 )), 3u );
221+ EXPECT_EQ (table->lower_bound (make_addr (29 )), 3u );
222222
223- // In case there's no "real" entry at this address, they return the first real
224- // entry.
223+ // In case there's no "real" entry at this address, the function returns the
224+ // first real entry.
225225 EXPECT_EQ (table->lower_bound (make_addr (30 )), 5u );
226- EXPECT_EQ (table->upper_bound (make_addr (30 )), 5u );
227-
228226 EXPECT_EQ (table->lower_bound (make_addr (40 )), 5u );
229- EXPECT_EQ (table->upper_bound (make_addr (40 )), 5u );
230-
231- // For in-between values, their result differs by one. [9,19) maps to [0,2)
232- // because the first two entries contain a part of that range.
233- EXPECT_EQ (table->lower_bound (make_addr (9 )), 0u );
234- EXPECT_EQ (table->upper_bound (make_addr (9 )), 1u );
235- EXPECT_EQ (table->lower_bound (make_addr (19 )), 1u );
236- EXPECT_EQ (table->upper_bound (make_addr (19 )), 2u );
237- EXPECT_EQ (table->lower_bound (make_addr (29 )), 3u );
238- EXPECT_EQ (table->upper_bound (make_addr (29 )), 4u );
239227
240- // In a gap, they both return the first entry after the gap.
241- EXPECT_EQ (table->upper_bound (make_addr (39 )), 5u );
242- EXPECT_EQ (table->upper_bound (make_addr (39 )), 5u );
228+ // In a gap, return the first entry after the gap.
229+ EXPECT_EQ (table->lower_bound (make_addr (39 )), 5u );
243230
244- // And if there's no such entry, they return the size of the list.
231+ // And if there's no such entry, return the size of the list.
245232 EXPECT_EQ (table->lower_bound (make_addr (50 )), table->GetSize ());
246- EXPECT_EQ (table->upper_bound (make_addr (50 )), table->GetSize ());
247233 EXPECT_EQ (table->lower_bound (make_addr (59 )), table->GetSize ());
248- EXPECT_EQ (table->upper_bound (make_addr (59 )), table->GetSize ());
234+ }
235+
236+ TEST_F (LineTableTest, GetLineEntryIndexRange) {
237+ LineSequenceBuilder builder;
238+ builder.Entry (0 );
239+ builder.Entry (10 );
240+ builder.Entry (20 , LineSequenceBuilder::Terminal);
241+
242+ llvm::Expected<FakeModuleFixture> fixture = CreateFakeModule (builder.Build ());
243+ ASSERT_THAT_EXPECTED (fixture, llvm::Succeeded ());
244+
245+ LineTable *table = fixture->line_table ;
246+
247+ auto make_range = [&](addr_t addr, addr_t size) {
248+ return AddressRange (fixture->text_sp , addr, size);
249+ };
250+
251+ EXPECT_THAT (table->GetLineEntryIndexRange (make_range (0 , 10 )),
252+ testing::Pair (0 , 1 ));
253+ EXPECT_THAT (table->GetLineEntryIndexRange (make_range (0 , 20 )),
254+ testing::Pair (0 , 3 )); // Includes the terminal entry.
255+ // Partial overlap on one side.
256+ EXPECT_THAT (table->GetLineEntryIndexRange (make_range (3 , 7 )),
257+ testing::Pair (0 , 1 ));
258+ // On the other side
259+ EXPECT_THAT (table->GetLineEntryIndexRange (make_range (0 , 15 )),
260+ testing::Pair (0 , 2 ));
261+ // On both sides
262+ EXPECT_THAT (table->GetLineEntryIndexRange (make_range (2 , 3 )),
263+ testing::Pair (0 , 1 ));
264+ // Empty ranges
265+ EXPECT_THAT (table->GetLineEntryIndexRange (make_range (0 , 0 )),
266+ testing::Pair (0 , 0 ));
267+ EXPECT_THAT (table->GetLineEntryIndexRange (make_range (5 , 0 )),
268+ testing::Pair (0 , 0 ));
269+ EXPECT_THAT (table->GetLineEntryIndexRange (make_range (10 , 0 )),
270+ testing::Pair (1 , 1 ));
249271}
250272
251273TEST_F (LineTableTest, FindLineEntryByAddress) {
0 commit comments