Update test paths after flattening v0 layout
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
+50
@@ -0,0 +1,50 @@
|
|||||||
|
/**
|
||||||
|
* An interface that wraps files and strings.
|
||||||
|
* Allows stream–like reading from it.
|
||||||
|
*/
|
||||||
|
#ifndef BUFFER_H
|
||||||
|
#define BUFFER_H
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An interface to a source of textual data.
|
||||||
|
*/
|
||||||
|
typedef struct Buffer Buffer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Opens a file.
|
||||||
|
*
|
||||||
|
* @param path The path to the file.
|
||||||
|
* @returns The newly–opened buffer.
|
||||||
|
*/
|
||||||
|
Buffer* buffer_open_file(const char* path);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Opens a string.
|
||||||
|
*
|
||||||
|
* The string is not copied, and must not be free'd until the
|
||||||
|
* buffer itself has been closed.
|
||||||
|
*
|
||||||
|
* @param string The contents stored in the buffer.
|
||||||
|
* @returns A newly–opened buffer that reads from the string.
|
||||||
|
*/
|
||||||
|
Buffer* buffer_open_string(const char* string);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes the buffer.
|
||||||
|
*
|
||||||
|
* @param buffer The buffer to close.
|
||||||
|
*/
|
||||||
|
void buffer_close(Buffer* buffer);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads a single character from the buffer.
|
||||||
|
*
|
||||||
|
* If there are no more characters in the buffer,
|
||||||
|
* this returns `-1`.
|
||||||
|
*
|
||||||
|
* @param buffer The buffer to read from.
|
||||||
|
* @returns the next character in the buffer.
|
||||||
|
*/
|
||||||
|
char buffer_read(Buffer* buffer);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int main(int argc, char** argv) {
|
||||||
|
puts("Hello, world");
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
#include "test.h"
|
#include "test.h"
|
||||||
#include "../src/buffer.h"
|
#include "buffer.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
// @copilot add test for reading from a file.
|
// @copilot add test for reading from a file.
|
||||||
@@ -27,7 +27,7 @@ static void test_buffer_string_eof_after_content(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void test_buffer_file_reads_chars(void) {
|
static void test_buffer_file_reads_chars(void) {
|
||||||
Buffer* buf = buffer_open_file("v0/tests/test_buffer.txt");
|
Buffer* buf = buffer_open_file("v0/test_buffer.txt");
|
||||||
if (buf == NULL) fail("could not open file");
|
if (buf == NULL) fail("could not open file");
|
||||||
if (buffer_read(buf) != 'a') fail("expected 'a'");
|
if (buffer_read(buf) != 'a') fail("expected 'a'");
|
||||||
if (buffer_read(buf) != 'b') fail("expected 'b'");
|
if (buffer_read(buf) != 'b') fail("expected 'b'");
|
||||||
@@ -38,6 +38,6 @@ static void test_buffer_file_reads_chars(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void test_buffer_file_open_fail(void) {
|
static void test_buffer_file_open_fail(void) {
|
||||||
Buffer* buf = buffer_open_file("v0/tests/does_not_exist.txt");
|
Buffer* buf = buffer_open_file("v0/does_not_exist.txt");
|
||||||
if (buf != NULL) fail("expected NULL for non-existent file");
|
if (buf != NULL) fail("expected NULL for non-existent file");
|
||||||
}
|
}
|
||||||
+49
@@ -0,0 +1,49 @@
|
|||||||
|
/**
|
||||||
|
* Contains the interface for reading tokens from a file.
|
||||||
|
*/
|
||||||
|
#ifndef TOKEN_H
|
||||||
|
#define TOKEN_H
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
// Keywords
|
||||||
|
TOKEN_MODULE,
|
||||||
|
TOKEN_IMPORT,
|
||||||
|
TOKEN_SEMICOLON,
|
||||||
|
|
||||||
|
// Symbols
|
||||||
|
TOKEN_PARENT_OPEN,
|
||||||
|
TOKEN_PARENT_CLOSE,
|
||||||
|
TOKEN_BRACKET_OPEN,
|
||||||
|
TOKEN_BRACKET_CLOSE,
|
||||||
|
TOKEN_COMMA,
|
||||||
|
|
||||||
|
// Primitives
|
||||||
|
TOKEN_VOID,
|
||||||
|
|
||||||
|
// Variable
|
||||||
|
TOKEN_IDENTIFIER,
|
||||||
|
} Token;
|
||||||
|
|
||||||
|
typedef struct TokenStream TokenStream;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Opens a file and returns a TokenStream for it.
|
||||||
|
* @param path The path to the file.
|
||||||
|
* @returns A handle to the TokenStream.
|
||||||
|
*/
|
||||||
|
TokenStream* tokenstream_open(const char* path);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes a TokenStream.
|
||||||
|
* @param ts The TokenStream to close.
|
||||||
|
*/
|
||||||
|
void tokenstream_close(TokenStream* ts);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the next token from the TokenStream.
|
||||||
|
* @param ts The TokenStream to read from.
|
||||||
|
* @returns The next token read.
|
||||||
|
*/
|
||||||
|
Token tokenstream_next(TokenStream* ts);
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user