Skip to content

Commit d4c79b1

Browse files
committed
Compare buffer but ignore CR and LF.
1 parent a4fa5d7 commit d4c79b1

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

tests/buffer.hpp

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,30 @@ class Buffer
140140

141141
constexpr bool operator==(const Buffer &other) const
142142
{
143-
if (size != other.size)
143+
// Check if the buffer is the same, but ignore CR and LF.
144+
std::size_t i = 0, j = 0;
145+
while (i < size || j < other.size)
144146
{
145-
return false;
147+
i = std::min(i, size);
148+
j = std::min(j, other.size);
149+
if (buffer[i] == '\r' || buffer[i] == '\n')
150+
{
151+
i++;
152+
continue;
153+
}
154+
if (other.buffer[j] == '\r' || other.buffer[j] == '\n')
155+
{
156+
j++;
157+
continue;
158+
}
159+
if (buffer[i] != other.buffer[j])
160+
{
161+
return false;
162+
}
163+
i++;
164+
j++;
146165
}
147-
return std::memcmp(buffer, other.buffer, size) == 0;
166+
return true;
148167
}
149168

150169
constexpr bool operator!=(const Buffer &other) const
@@ -156,6 +175,12 @@ class Buffer
156175
{
157176
if (*this != other)
158177
{
178+
std::string str_cwd = std::filesystem::current_path().string();
179+
print_stderr("DEBUG: Dumping 'this.dmp' and 'other.dmp' into '{}' ...\n\tThis: {}\n\tOther: {}\n",
180+
colorize(str_cwd, CONTROL_UNDERLINE), colorize(id, CONTROL_UNDERLINE),
181+
colorize(other.id, CONTROL_UNDERLINE));
182+
dump(std::filesystem::path("this.dmp"));
183+
other.dump(std::filesystem::path("other.dmp"));
159184
error("compare_assert", "The data is different.");
160185
}
161186
success("compare_assert", "The data is the same.");

0 commit comments

Comments
 (0)