From 8a1b7f6b5534bc02692f7a02d0dc287dc46ca4c1 Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Mon, 25 May 2020 05:22:17 +0530 Subject: utils: Do not return eof if matched at beginning. * email/utils.scm (read-while, read-bytes-till): Do not return eof if matched at beginning. Return empty string or bytevector respectively. * tests/utils.scm ("read-bytes-till returns empty bytevector on match at beginning", "read-while returns empty string on match at beginning"): New tests. --- tests/utils.scm | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/utils.scm b/tests/utils.scm index 7681c72..ce8fdb2 100644 --- a/tests/utils.scm +++ b/tests/utils.scm @@ -1,5 +1,5 @@ ;;; guile-email --- Guile email parser -;;; Copyright © 2019 Arun Isaac +;;; Copyright © 2019, 2020 Arun Isaac ;;; ;;; This file is part of guile-email. ;;; @@ -35,4 +35,15 @@ (call-with-input-string "" (cut read-while <> read identity)))) +(test-equal "read-bytes-till returns empty bytevector on match at beginning" + (call-with-port (open-bytevector-input-port #vu8(1 2 3)) + (cut read-bytes-till <> #vu8(1 2))) + #vu8()) + +(test-equal "read-while returns empty string on match at beginning" + (call-with-input-string "foo\nbar" + (lambda (port) + (read-while port get-line (negate (cut string-prefix? "foo" <>))))) + "") + (test-end "utils") -- cgit v1.2.3