Commit ba711544 authored by Mukund Sivaraman's avatar Mukund Sivaraman
Browse files

[2369] Fix vector::erase() call in InputSource

The single-argument variant of vector::erase() deletes just one element
of the vector, not an entire range.  Tests have been fixed to check
that the range from start to the current buffer position is dropped
correctly.
parent 51e26dc9
......@@ -107,7 +107,7 @@ InputSource::compact() {
if (buffer_pos_ == buffer_.size()) {
buffer_.clear();
} else {
buffer_.erase(buffer_.begin() + buffer_pos_);
buffer_.erase(buffer_.begin(), buffer_.begin() + buffer_pos_);
}
buffer_pos_ = 0;
......
......@@ -172,13 +172,18 @@ TEST_F(InputSourceTest, compactDuring) {
size_t line = source_.getCurrentLine();
EXPECT_EQ(2, line);
// Now, unget a couple of characters. This should cause the
// buffer_pos_ to be not equal to the size of the buffer.
source_.ungetChar();
source_.ungetChar();
source_.saveLine();
source_.compact();
// Ungetting here must throw.
EXPECT_THROW(source_.ungetChar(), InputSource::UngetError);
for (size_t i = 15; i < str_length_; i++) {
for (size_t i = 13; i < str_length_; i++) {
EXPECT_EQ(str_[i], source_.getChar());
EXPECT_FALSE(source_.atEOF());
}
......@@ -198,7 +203,7 @@ TEST_F(InputSourceTest, compactDuring) {
// Ungetting here must throw.
EXPECT_THROW(source_.ungetChar(), InputSource::UngetError);
for (size_t i = 15; i < str_length_; i++) {
for (size_t i = 13; i < str_length_; i++) {
EXPECT_EQ(str_[i], source_.getChar());
EXPECT_FALSE(source_.atEOF());
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment