Expand equality failure messages with a by-line diff.
This commit is contained in:
@@ -56,6 +56,8 @@
|
||||
#include <iomanip>
|
||||
#include <limits>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "gtest/gtest-message.h"
|
||||
#include "gtest/internal/gtest-string.h"
|
||||
@@ -171,6 +173,36 @@ class GTEST_API_ ScopedTrace {
|
||||
// c'tor and d'tor. Therefore it doesn't
|
||||
// need to be used otherwise.
|
||||
|
||||
namespace edit_distance {
|
||||
// Returns the optimal edits to go from 'left' to 'right'.
|
||||
// All edits cost the same, with replace having lower priority than
|
||||
// add/remove.
|
||||
// Simple implementation of the Wagner–Fischer algorithm.
|
||||
// See http://en.wikipedia.org/wiki/Wagner-Fischer_algorithm
|
||||
enum EditType { kMatch, kAdd, kRemove, kReplace };
|
||||
GTEST_API_ std::vector<EditType> CalculateOptimalEdits(
|
||||
const std::vector<size_t>& left, const std::vector<size_t>& right);
|
||||
|
||||
// Same as above, but the input is represented as strings.
|
||||
GTEST_API_ std::vector<EditType> CalculateOptimalEdits(
|
||||
const std::vector<std::string>& left,
|
||||
const std::vector<std::string>& right);
|
||||
|
||||
// Create a diff of the input strings in Unified diff format.
|
||||
GTEST_API_ std::string CreateUnifiedDiff(const std::vector<std::string>& left,
|
||||
const std::vector<std::string>& right,
|
||||
size_t context = 2);
|
||||
|
||||
} // namespace edit_distance
|
||||
|
||||
// Calculate the diff between 'left' and 'right' and return it in unified diff
|
||||
// format.
|
||||
// If not null, stores in 'total_line_count' the total number of lines found
|
||||
// in left + right.
|
||||
GTEST_API_ std::string DiffStrings(const std::string& left,
|
||||
const std::string& right,
|
||||
size_t* total_line_count);
|
||||
|
||||
// Constructs and returns the message for an equality assertion
|
||||
// (e.g. ASSERT_EQ, EXPECT_STREQ, etc) failure.
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user