Add stream structure and utilities

This commit is contained in:
2026-08-30 02:18:30 +01:00
parent a51686c8f0
commit c1b2e29c07
9 changed files with 237 additions and 0 deletions
+50
View File
@@ -0,0 +1,50 @@
// vim:fileencoding=utf-8:foldmethod=marker
#include "test_stream.h"
#define COUNT 3
WpTestFuncResult test_stream_at_end(void) {
b8 result = true;
c8 characters[COUNT] = {'a', 'b', 'c'};
WpC8Stream stream = wpStream(c8, characters, COUNT);
for (u32 i = 0; i < COUNT; ++i) {
wpStreamConsume(c8, &stream);
result = result && (i == 2 ? wpStreamAtEnd(c8, &stream) : !wpStreamAtEnd(c8, &stream));
}
return wpTesterResult(result);
}
WpTestFuncResult test_stream_peek(void) {
b8 result = true;
c8 characters[COUNT] = {'a', 'b', 'c'};
WpC8Stream stream = wpStream(c8, characters, COUNT);
c8 *c = NULL;
while (!wpStreamAtEnd(c8, &stream)) {
c = wpStreamPeek(c8, &stream);
wpStreamConsume(c8, &stream);
result = result && (wpStreamAtEnd(c8, &stream) ? c == NULL : c != NULL);
}
return wpTesterResult(result);
}
WpTestFuncResult test_stream_consume(void) {
b8 result = true;
c8 characters[COUNT] = {'a', 'b', 'c'};
WpC8Stream stream = wpStream(c8, characters, COUNT);
c8 *c = NULL;
for (u32 i = 0; i <= COUNT; ++i) {
c = wpStreamConsume(c8, &stream);
result = result && (i == COUNT ? c == NULL : c != NULL);
}
return wpTesterResult(result);
}