Have Range::overlapsWith use positive logic
authorEdwin Vane <edwin.vane@intel.com>
Tue, 13 Aug 2013 18:11:16 +0000 (18:11 +0000)
committerEdwin Vane <edwin.vane@intel.com>
Tue, 13 Aug 2013 18:11:16 +0000 (18:11 +0000)
Improved test to catch missing case.

llvm-svn: 188304

clang/include/clang/Tooling/Refactoring.h
clang/unittests/Tooling/RefactoringTest.cpp

index efac016b199b1ff8621d83a363094c0972b26187..7ebac33a9a29f0eb939c43f6970304c035f67dc9 100644 (file)
@@ -48,9 +48,7 @@ public:
   /// @{
   /// \brief Whether this range overlaps with \p RHS or not.
   bool overlapsWith(Range RHS) const {
-    if ((Offset + Length) <= RHS.Offset || Offset >= (RHS.Offset + RHS.Length))
-      return false;
-    return true;
+    return Offset + Length > RHS.Offset && Offset < RHS.Offset + RHS.Length;
   }
 
   /// \brief Whether this range contains \p RHS or not.
index 81f9f040aeb7d5aa206355593db132d653354916..a88de1c9f4564720109cb664185da3adbc5df5e6 100644 (file)
@@ -353,6 +353,7 @@ TEST(Range, overlaps) {
   EXPECT_FALSE(Range(10, 10).overlapsWith(Range(0, 10)));
   EXPECT_FALSE(Range(0, 10).overlapsWith(Range(10, 10)));
   EXPECT_TRUE(Range(0, 10).overlapsWith(Range(2, 6)));
+  EXPECT_TRUE(Range(2, 6).overlapsWith(Range(0, 10)));
 }
 
 TEST(Range, contains) {