@@ -11,7 +11,7 @@ namespace databento::detail::tests {
1111TEST (BufferTests, TestWriteAllPastCapacity) {
1212 Buffer target{10 };
1313 target.Fill (4 );
14- target.ConsumeNoShift (2 );
14+ target.Consume (2 );
1515 ASSERT_EQ (target.WriteCapacity (), 6 );
1616 ASSERT_EQ (target.ReadCapacity (), 2 );
1717 ASSERT_EQ (target.Capacity (), 10 );
@@ -25,7 +25,7 @@ TEST(BufferTests, TestWriteAllPastCapacity) {
2525TEST (BufferTests, TestWriteAllShift) {
2626 Buffer target{20 };
2727 target.WriteAll (" TestWriteAllShift" , 17 );
28- target.ConsumeNoShift (4 );
28+ target.Consume (4 );
2929 ASSERT_EQ (target.WriteCapacity (), 3 );
3030 ASSERT_EQ (target.ReadCapacity (), 13 );
3131 ASSERT_EQ (target.Capacity (), 20 );
@@ -39,7 +39,7 @@ TEST(BufferTests, TestWriteAllShift) {
3939TEST (BufferTests, TestWriteRead) {
4040 Buffer target{10 };
4141 target.Fill (5 );
42- target.ConsumeNoShift (5 );
42+ target.Consume (5 );
4343 const auto write_len = target.Write (" BufferTests" , 11 );
4444 ASSERT_EQ (write_len, 10 );
4545 std::array<std::byte, 10 > read_buf{};
@@ -54,16 +54,42 @@ TEST(BufferTests, TestReserve) {
5454 ASSERT_EQ (target.ReadCapacity (), 0 );
5555 ASSERT_EQ (target.Capacity (), 120 );
5656 target.WriteAll (" TestReserve" , 11 );
57- target.ConsumeNoShift (4 );
57+ target.Consume (4 );
5858}
5959
60- TEST (BufferTests, TestConsumeShift) {
60+ TEST (BufferTests, TestConsumeDoesNotShift) {
61+ Buffer target{16 };
62+ target.Fill (12 );
63+ target.Consume (10 );
64+ ASSERT_EQ (target.ReadCapacity (), 2 );
65+ ASSERT_EQ (target.WriteCapacity (), 4 );
66+ }
67+
68+ TEST (BufferTests, TestShiftForSpace) {
6169 Buffer target{120 };
62- target.Fill (120 );
63- ASSERT_EQ (target.WriteCapacity (), 0 );
64- target.ConsumeNoShift (100 );
65- ASSERT_EQ (target.WriteCapacity (), 0 );
66- target.Consume (1 );
67- ASSERT_EQ (target.WriteCapacity (), 101 );
70+ target.Fill (40 );
71+ target.Consume (20 );
72+ ASSERT_EQ (target.WriteCapacity (), 80 );
73+ ASSERT_EQ (target.ReadCapacity (), 20 );
74+ // Writable space is sufficient: no shift
75+ target.ShiftForSpace (50 );
76+ ASSERT_EQ (target.WriteCapacity (), 80 );
77+ ASSERT_EQ (target.ReadCapacity (), 20 );
78+ // Writable space is insufficient: reclaim the consumed prefix
79+ target.ShiftForSpace (100 );
80+ ASSERT_EQ (target.WriteCapacity (), 100 );
81+ ASSERT_EQ (target.ReadCapacity (), 20 );
82+ // Nothing left to reclaim; shift is a no-op
83+ target.ShiftForSpace (1000 );
84+ ASSERT_EQ (target.WriteCapacity (), 100 );
85+ ASSERT_EQ (target.ReadCapacity (), 20 );
86+ }
87+
88+ TEST (BufferTests, TestShiftForSpaceNoopWhenUnconsumed) {
89+ Buffer target{16 };
90+ target.Fill (4 );
91+ target.ShiftForSpace (1000 );
92+ ASSERT_EQ (target.WriteCapacity (), 12 );
93+ ASSERT_EQ (target.ReadCapacity (), 4 );
6894}
6995} // namespace databento::detail::tests
0 commit comments