/// \brief Exception thrown when ungetChar() is made to go before
/// the start of buffer.
- struct UngetError : public OutOfRange {
- UngetError(const char* file, size_t line, const char* what) :
+ struct UngetBeforeBeginning : public OutOfRange {
+ UngetBeforeBeginning(const char* file, size_t line, const char* what) :
OutOfRange(file, line, what)
{}
};
/// \brief Skips backward a single character in the input
/// source. The last-read character is unget.
+ ///
+ /// \throws UngetBeforeBeginning if we go backwards past the start
+ /// of reading, or backwards past the last time compact() was
+ /// called.
void ungetChar();
/// Forgets everything read so far, and skips back to the position
}
// Skipping past the start of buffer should throw.
- EXPECT_THROW(source_.ungetChar(), InputSource::UngetError);
+ EXPECT_THROW(source_.ungetChar(), InputSource::UngetBeforeBeginning);
}
// ungetAll() should skip back to the place where the InputSource
source_.compact();
// Ungetting here must throw.
- EXPECT_THROW(source_.ungetChar(), InputSource::UngetError);
+ EXPECT_THROW(source_.ungetChar(), InputSource::UngetBeforeBeginning);
for (size_t i = 0; i < str_length_; i++) {
EXPECT_EQ(str_[i], source_.getChar());
source_.ungetChar();
// Ungetting here must throw.
- EXPECT_THROW(source_.ungetChar(), InputSource::UngetError);
+ EXPECT_THROW(source_.ungetChar(), InputSource::UngetBeforeBeginning);
EXPECT_EQ(-1, source_.getChar());
EXPECT_TRUE(source_.atEOF());
source_.compact();
// Ungetting here must throw.
- EXPECT_THROW(source_.ungetChar(), InputSource::UngetError);
+ EXPECT_THROW(source_.ungetChar(), InputSource::UngetBeforeBeginning);
for (size_t i = 13; i < str_length_; i++) {
EXPECT_EQ(str_[i], source_.getChar());
source_.ungetAll();
// Ungetting here must throw.
- EXPECT_THROW(source_.ungetChar(), InputSource::UngetError);
+ EXPECT_THROW(source_.ungetChar(), InputSource::UngetBeforeBeginning);
for (size_t i = 13; i < str_length_; i++) {
EXPECT_EQ(str_[i], source_.getChar());
((line - 1) == source_.getCurrentLine())));
line = source_.getCurrentLine();
}
- }, InputSource::UngetError);
+ }, InputSource::UngetBeforeBeginning);
// Now we are back to where we started.
EXPECT_EQ(1, source_.getCurrentLine());