diff options
| author | Joel Klinghed <the_jk@spawned.biz> | 2025-09-22 23:38:21 +0200 |
|---|---|---|
| committer | Joel Klinghed <the_jk@spawned.biz> | 2025-09-22 23:38:21 +0200 |
| commit | ce271f82f16ee89a18e7bfc9ed8eab7cbd6f37bc (patch) | |
| tree | 3e568faf83ae750aa244cca87b55951c7401ef03 /test/line.cc | |
| parent | 50348284f5d82ccfd65b0c803ba0ba895912ceff (diff) | |
Change io::Reader and company to return ReadError::Eof instead of 0.
It's debatable if Eof should be considered an error or not.
But it is pretty clear it generally is a special response that
needs special handling, so easier to keep with the unexpected lot.
Also keeps better at higher abstraction levels, such as the line
reader.
Diffstat (limited to 'test/line.cc')
| -rw-r--r-- | test/line.cc | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/test/line.cc b/test/line.cc index 71d75c5..e0ea002 100644 --- a/test/line.cc +++ b/test/line.cc @@ -12,7 +12,7 @@ TEST(line, empty) { EXPECT_EQ(0, reader->number()); auto line = reader->read(); ASSERT_FALSE(line.has_value()); - EXPECT_TRUE(line.error().eof); + EXPECT_EQ(io::ReadError::Eof, line.error()); EXPECT_EQ(0, reader->number()); } @@ -25,7 +25,7 @@ TEST(line, one_line) { EXPECT_EQ(1, reader->number()); line = reader->read(); ASSERT_FALSE(line.has_value()); - EXPECT_TRUE(line.error().eof); + EXPECT_EQ(io::ReadError::Eof, line.error()); EXPECT_EQ(1, reader->number()); } @@ -46,7 +46,7 @@ TEST(line, many_lines) { EXPECT_EQ(3, reader->number()); line = reader->read(); ASSERT_FALSE(line.has_value()); - EXPECT_TRUE(line.error().eof); + EXPECT_EQ(io::ReadError::Eof, line.error()); EXPECT_EQ(3, reader->number()); } @@ -67,7 +67,7 @@ TEST(line, many_lines_mixed) { EXPECT_EQ(3, reader->number()); line = reader->read(); ASSERT_FALSE(line.has_value()); - EXPECT_TRUE(line.error().eof); + EXPECT_EQ(io::ReadError::Eof, line.error()); EXPECT_EQ(3, reader->number()); } @@ -80,7 +80,7 @@ TEST(line, empty_line) { EXPECT_EQ(1, reader->number()); line = reader->read(); ASSERT_FALSE(line.has_value()); - EXPECT_TRUE(line.error().eof); + EXPECT_EQ(io::ReadError::Eof, line.error()); EXPECT_EQ(1, reader->number()); } @@ -101,7 +101,7 @@ TEST(line, max_line) { EXPECT_EQ(3, reader->number()); line = reader->read(); ASSERT_FALSE(line.has_value()); - EXPECT_TRUE(line.error().eof); + EXPECT_EQ(io::ReadError::Eof, line.error()); EXPECT_EQ(3, reader->number()); } @@ -110,8 +110,7 @@ TEST(line, read_error) { io_make_breaking(io::memory("foo bar fum\nfim zam"), /* offset */ 5)); auto line = reader->read(); ASSERT_FALSE(line.has_value()); - EXPECT_FALSE(line.error().eof); - EXPECT_EQ(io::ReadError::Error, line.error().io_error.value()); + EXPECT_EQ(io::ReadError::Error, line.error()); } TEST(line, read_error_newline) { @@ -119,8 +118,7 @@ TEST(line, read_error_newline) { io_make_breaking(io::memory("foo bar\r\nfim zam"), /* offset */ 8)); auto line = reader->read(); ASSERT_FALSE(line.has_value()); - EXPECT_FALSE(line.error().eof); - EXPECT_EQ(io::ReadError::Error, line.error().io_error.value()); + EXPECT_EQ(io::ReadError::Error, line.error()); } TEST(line, blocky) { @@ -134,7 +132,7 @@ TEST(line, blocky) { EXPECT_EQ("fim zam", line.value()); line = reader->read(); ASSERT_FALSE(line.has_value()); - EXPECT_TRUE(line.error().eof); + EXPECT_EQ(io::ReadError::Eof, line.error()); } TEST(line, blocky_newline) { @@ -148,7 +146,7 @@ TEST(line, blocky_newline) { EXPECT_EQ("fim zam", line.value()); line = reader->read(); ASSERT_FALSE(line.has_value()); - EXPECT_TRUE(line.error().eof); + EXPECT_EQ(io::ReadError::Eof, line.error()); } TEST(line, eof_newline) { @@ -158,7 +156,7 @@ TEST(line, eof_newline) { EXPECT_EQ("foo bar", line.value()); line = reader->read(); ASSERT_FALSE(line.has_value()); - EXPECT_TRUE(line.error().eof); + EXPECT_EQ(io::ReadError::Eof, line.error()); } TEST(line, max_newline) { @@ -171,7 +169,7 @@ TEST(line, max_newline) { EXPECT_EQ("r", line.value()); line = reader->read(); ASSERT_FALSE(line.has_value()); - EXPECT_TRUE(line.error().eof); + EXPECT_EQ(io::ReadError::Eof, line.error()); } TEST(line, max_line_overflow) { |
