commit f566ffc16fde2f417d10c22196c61f9dacc0e5fb
parent 2ccd724e8b163165a721694f3dad171abcc4e3ce
Author: Sebastian <sebastian@sebsite.pw>
Date: Sat, 5 Aug 2023 20:11:54 -0400
format::ini: fix and test error line numbering
Signed-off-by: Sebastian <sebastian@sebsite.pw>
Diffstat:
2 files changed, 25 insertions(+), 3 deletions(-)
diff --git a/format/ini/+test.ha b/format/ini/+test.ha
@@ -50,14 +50,36 @@ trademark=™
const sc = scan(&buf);
defer finish(&sc);
- assert(next(&sc) as error is syntaxerr); // TODO: test line numbering?
+ assert(next(&sc) as error as syntaxerr == 1);
// Unterminated section header
const buf = memio::fixed(strings::toutf8("[dangling\n"));
const sc = scan(&buf);
defer finish(&sc);
- assert(next(&sc) as error is syntaxerr);
+ assert(next(&sc) as error as syntaxerr == 1);
+
+ // Line numbering and recovery
+ const buf = memio::fixed(strings::toutf8(
+"[a]
+b=c
+d=e
+[f]
+g=h
+
+i
+
+j=k
+"));
+ const sc = scan(&buf);
+ defer finish(&sc);
+
+ ini_test(&sc, "a", "b", "c");
+ ini_test(&sc, "a", "d", "e");
+ ini_test(&sc, "f", "g", "h");
+ assert(next(&sc) as error as syntaxerr == 7);
+ ini_test(&sc, "f", "j", "k");
+ assert(next(&sc) is io::EOF);
};
fn ini_test(
diff --git a/format/ini/scan.ha b/format/ini/scan.ha
@@ -58,7 +58,7 @@ export fn next(sc: *scanner) (entry | io::EOF | error) = {
case io::EOF =>
return io::EOF;
};
- sc.lineno += 1;
+ defer sc.lineno += 1;
free(sc.line);
sc.line = line;