fix scanner_print_errors
This commit is contained in:
@@ -338,7 +338,7 @@ scan_result_t scan_f32(scanner_t *s);
|
|||||||
scan_result_t scan_identifier(scanner_t *s);
|
scan_result_t scan_identifier(scanner_t *s);
|
||||||
scan_result_t scan_string_literal(scanner_t *s);
|
scan_result_t scan_string_literal(scanner_t *s);
|
||||||
bool scanner_print_errors_func(FILE *fp, scan_result_t const *results, int results_len);
|
bool scanner_print_errors_func(FILE *fp, scan_result_t const *results, int results_len);
|
||||||
#define scanner_print_errors(FP, ...) scanner_print_errors_func(FP, &(scan_result_t[]){__VA_ARGS__}, sizeof((scan_result_t[]){__VA_ARGS__}))
|
#define scanner_print_errors(FP, ...) scanner_print_errors_func(FP, (scan_result_t const []){__VA_ARGS__}, sizeof((scan_result_t[]){__VA_ARGS__}) / sizeof(((scan_result_t[]){__VA_ARGS__})[0]))
|
||||||
bool looks_like_float(scanner_t *s);
|
bool looks_like_float(scanner_t *s);
|
||||||
bool looks_like_int(scanner_t *s);
|
bool looks_like_int(scanner_t *s);
|
||||||
|
|
||||||
|
|||||||
+11
-5
@@ -1,5 +1,6 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <criterion/criterion.h>
|
#include <criterion/criterion.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include "cig.h"
|
#include "cig.h"
|
||||||
|
|
||||||
Test(scanner, looks_like_float) {
|
Test(scanner, looks_like_float) {
|
||||||
@@ -58,12 +59,17 @@ Test(scanner, print_errors) {
|
|||||||
"+. false\n"
|
"+. false\n"
|
||||||
"abc false\n"
|
"abc false\n"
|
||||||
"+x false\n";
|
"+x false\n";
|
||||||
|
FILE *f = tmpfile();
|
||||||
with_borrow(allocator) {
|
with_borrow(allocator) {
|
||||||
scanner_t scanner = make_scanner("test", buffer, allocator);
|
scanner_t scanner = make_scanner(__FILE__, buffer, allocator);
|
||||||
while (!scan_eof(&scanner)) {
|
scan_result_t res1 = scan_error(&scanner, "ignore this\n");
|
||||||
// TODO
|
scan_result_t res2 = scan_error(&scanner, "and this\n");
|
||||||
cr_assert(false);
|
scan_result_t res3 = scan_value(.i64=10);
|
||||||
}
|
scan_result_t res4 = scan_value(.string_literal="foobar");
|
||||||
|
|
||||||
|
cr_assert(scanner_print_errors(f, res1, res2));
|
||||||
|
cr_assert(scanner_print_errors(f, res1, res2, res3, res4));
|
||||||
|
cr_assert(!scanner_print_errors(f, res3, res4));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user