This commit is contained in:
+34
-2
@@ -1,9 +1,10 @@
|
||||
#include <assert.h>
|
||||
#include <criterion/criterion.h>
|
||||
#include <stdio.h>
|
||||
#include "cig.h"
|
||||
|
||||
Test(scanner, looks_like_float) {
|
||||
const char *buffer =
|
||||
char const *buffer =
|
||||
"1.0 true\n"
|
||||
"12.34 true\n"
|
||||
"0.5 true\n"
|
||||
@@ -22,7 +23,7 @@ Test(scanner, looks_like_float) {
|
||||
scanner_t scanner = make_scanner("test", buffer, allocator);
|
||||
while (!scan_eof(&scanner)) {
|
||||
bool does_look_like_float = looks_like_float(&scanner);
|
||||
bool does_look_like_int = looks_like_float(&scanner);
|
||||
bool does_look_like_int = looks_like_int(&scanner);
|
||||
while (*scanner.cur++ != ' ');
|
||||
bool expect;
|
||||
if (scan_literal(&scanner, "true")) {
|
||||
@@ -41,3 +42,34 @@ Test(scanner, looks_like_float) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Test(scanner, print_errors) {
|
||||
char const *buffer =
|
||||
"1.0 true\n"
|
||||
"12.34 true\n"
|
||||
"0.5 true\n"
|
||||
"9.99 true\n"
|
||||
"+1.2 true\n"
|
||||
"-3.14 true\n"
|
||||
"1 false\n"
|
||||
"42 false\n"
|
||||
"+7 false\n"
|
||||
"1. false\n"
|
||||
".5 false\n"
|
||||
"+. false\n"
|
||||
"abc false\n"
|
||||
"+x false\n";
|
||||
FILE *f = tmpfile();
|
||||
with_borrow(allocator) {
|
||||
scanner_t scanner = make_scanner(__FILE__, buffer, allocator);
|
||||
scan_result_t res1 = scan_error(&scanner, "ignore this\n");
|
||||
scan_result_t res2 = scan_error(&scanner, "and this\n");
|
||||
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