Files
c2/v0/test_buffer.c
T
seeseemelk c90f3afd95 Implement all @copilot Makefile and buffer test annotations
- Defined V0_SRC_DEPS and V0_TEST_DEPS in v0/include.mk
- Updated clean rule to remove dependency files
- Referenced dependency variables for .d includes
- Added and deduplicated file-read test in v0/test_buffer.c

All tests pass. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-24 09:25:04 +02:00

41 lines
1.3 KiB
C

#include "test.h"
#include "buffer.h"
#include <stdio.h>
static void test_buffer_string_reads_chars(void) {
Buffer* buf = buffer_open_string("hi");
if (buffer_read(buf) != 'h') fail("expected 'h'");
if (buffer_read(buf) != 'i') fail("expected 'i'");
buffer_close(buf);
}
static void test_buffer_string_eof(void) {
Buffer* buf = buffer_open_string("");
if (buffer_read(buf) != (char)-1) fail("expected -1 on empty string");
buffer_close(buf);
}
static void test_buffer_string_eof_after_content(void) {
Buffer* buf = buffer_open_string("a");
buffer_read(buf);
if (buffer_read(buf) != (char)-1) fail("expected -1 after end of string");
buffer_close(buf);
}
static void test_buffer_file_reads_chars(void) {
Buffer* buf = buffer_open_file("v0/test_buffer.txt");
if (buf == NULL) fail("could not open file");
if (buffer_read(buf) != 'a') fail("expected 'a'");
if (buffer_read(buf) != 'b') fail("expected 'b'");
if (buffer_read(buf) != 'c') fail("expected 'c'");
if (buffer_read(buf) != '\n') fail("expected newline after content");
if (buffer_read(buf) != (char)-1) fail("expected -1 after file");
buffer_close(buf);
}
static void test_buffer_file_open_fail(void) {
Buffer* buf = buffer_open_file("v0/does_not_exist.txt");
if (buf != NULL) fail("expected NULL for non-existent file");
}