/ externals / catch / src / catch2 / internal / catch_source_line_info.cpp
catch_source_line_info.cpp
 1  
 2  //              Copyright Catch2 Authors
 3  // Distributed under the Boost Software License, Version 1.0.
 4  //   (See accompanying file LICENSE.txt or copy at
 5  //        https://www.boost.org/LICENSE_1_0.txt)
 6  
 7  // SPDX-License-Identifier: BSL-1.0
 8  #include <catch2/internal/catch_source_line_info.hpp>
 9  
10  #include <cstring>
11  #include <ostream>
12  
13  namespace Catch {
14  
15      bool SourceLineInfo::operator == ( SourceLineInfo const& other ) const noexcept {
16          return line == other.line && (file == other.file || std::strcmp(file, other.file) == 0);
17      }
18      bool SourceLineInfo::operator < ( SourceLineInfo const& other ) const noexcept {
19          // We can assume that the same file will usually have the same pointer.
20          // Thus, if the pointers are the same, there is no point in calling the strcmp
21          return line < other.line || ( line == other.line && file != other.file && (std::strcmp(file, other.file) < 0));
22      }
23  
24      std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info ) {
25  #ifndef __GNUG__
26          os << info.file << '(' << info.line << ')';
27  #else
28          os << info.file << ':' << info.line;
29  #endif
30          return os;
31      }
32  
33  } // end namespace Catch