Made test-suite work on its own

This commit is contained in:
Dan Hirsch 2013-11-01 12:39:01 -04:00
parent 64b5e307d2
commit ce0829de33
3 changed files with 5 additions and 9 deletions

View file

@ -565,7 +565,7 @@ HAMMER_FN_DECL(void, h_parse_result_free, HParseResult *result);
* Format token into a compact unambiguous form. Useful for parser test cases. * Format token into a compact unambiguous form. Useful for parser test cases.
* Caller is responsible for freeing the result. * Caller is responsible for freeing the result.
*/ */
HAMMER_FN_DECL(char*, h_write_result_unamb, const HParsedToken* tok); char* h_write_result_unamb(const HParsedToken* tok);
/** /**
* Format token to the given output stream. Indent starting at * Format token to the given output stream. Indent starting at
* [indent] spaces, with [delta] spaces between levels. * [indent] spaces, with [delta] spaces between levels.

View file

@ -80,14 +80,13 @@ void h_pprint(FILE* stream, const HParsedToken* tok, int indent, int delta) {
struct result_buf { struct result_buf {
char* output; char* output;
HAllocator *mm__;
size_t len; size_t len;
size_t capacity; size_t capacity;
}; };
static inline void ensure_capacity(struct result_buf *buf, int amt) { static inline void ensure_capacity(struct result_buf *buf, int amt) {
while (buf->len + amt >= buf->capacity) while (buf->len + amt >= buf->capacity)
buf->output = buf->mm__->realloc(buf->mm__, buf->output, buf->capacity *= 2); buf->output = realloc(buf->output, buf->capacity *= 2);
} }
static inline void append_buf(struct result_buf *buf, const char* input, int len) { static inline void append_buf(struct result_buf *buf, const char* input, int len) {
@ -160,13 +159,9 @@ static void unamb_sub(const HParsedToken* tok, struct result_buf *buf) {
char* h_write_result_unamb(const HParsedToken* tok) { char* h_write_result_unamb(const HParsedToken* tok) {
return h_write_result_unamb__m(&system_allocator, tok);
}
char* h_write_result_unamb__m(HAllocator* mm__, const HParsedToken* tok) {
struct result_buf buf = { struct result_buf buf = {
.output = mm__->alloc(mm__, 16), .output = malloc(16),
.len = 0, .len = 0,
.mm__ = mm__,
.capacity = 16 .capacity = 16
}; };
unamb_sub(tok, &buf); unamb_sub(tok, &buf);

View file

@ -109,7 +109,7 @@
} else { \ } else { \
char* cres = h_write_result_unamb(res->ast); \ char* cres = h_write_result_unamb(res->ast); \
g_check_string(cres, ==, result); \ g_check_string(cres, ==, result); \
system_allocator.free(&system_allocator, cres); \ free(cres); \
HArenaStats stats; \ HArenaStats stats; \
h_allocator_stats(res->arena, &stats); \ h_allocator_stats(res->arena, &stats); \
g_test_message("Parse used %zd bytes, wasted %zd bytes. " \ g_test_message("Parse used %zd bytes, wasted %zd bytes. " \
@ -161,6 +161,7 @@
} while(0) } while(0)
// This stuff needs to be made internal-only; it has no use in user-level test suites
#define g_check_terminal(grammar, parser) \ #define g_check_terminal(grammar, parser) \
g_check_hashtable_absent(grammar->nts, h_desugar(&system_allocator, NULL, parser)) g_check_hashtable_absent(grammar->nts, h_desugar(&system_allocator, NULL, parser))