commit fd2e2bde1935c6a74b9573a51f349c55e655e302
parent 62bb49f3440e94311c7278344f050c552513aef7
Author: Armin Preiml <apreiml@strohwolke.at>
Date: Sat, 21 Dec 2024 13:34:38 +0100
bufio: fix EOF_GREEDY scan mode
Signed-off-by: Armin Preiml <apreiml@strohwolke.at>
Diffstat:
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/bufio/scanner.ha b/bufio/scanner.ha
@@ -204,7 +204,7 @@ export fn scan_bytes(
match (scan_readahead(scan)?) {
case io::EOF =>
- if (scan.opts & scan_options::EOF_DISCARD == 0) {
+ if (scan.opts == scan_options::EOF_DISCARD) {
return io::EOF;
};
if (len(scan.pending) == 0) {
diff --git a/bufio/scanner_test+test.ha b/bufio/scanner_test+test.ha
@@ -199,3 +199,16 @@ use types;
let line = scan_line(&scan) as const str;
assert(strings::compare(line, "hello") == 0);
};
+
+@test fn greedy_scan_uncomplete_line() void = {
+ let buf = memio::dynamic();
+ let scan = newscanner(&buf, types::SIZE_MAX, scan_options::EOF_GREEDY);
+
+ assert(scan_line(&scan) is io::EOF);
+
+ io::write(&buf, strings::toutf8("hello"))!;
+ io::seek(&buf, 0, io::whence::SET)!;
+
+ let line = scan_line(&scan) as const str;
+ assert(strings::compare(line, "hello") == 0);
+};