summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2023-08-07 20:10:54 -0700
committerKaz Kylheku <kaz@kylheku.com>2023-08-07 20:10:54 -0700
commit44453f30dd81ffa1e995662fd75a675b5b208406 (patch)
treebe5b301f1899521e63e6d9d1c6facdcd3dbf77ce /tests
parentc46898c74e39fc56e67e5bc03c574a3144362634 (diff)
downloadtxr-44453f30dd81ffa1e995662fd75a675b5b208406.tar.gz
txr-44453f30dd81ffa1e995662fd75a675b5b208406.tar.bz2
txr-44453f30dd81ffa1e995662fd75a675b5b208406.zip
close-stream: new : protocol from close method.
* stream.c (close_stream): If the underlying method returns the colon symbol :, then keep the cached close_result as nil, so that the method can be called again, but return t to the caller to indicate success. * tests/018/close-delegate.tl: Test case added. * tests/018/close-delegate.expected: Updated. * txr.1: Documented.
Diffstat (limited to 'tests')
-rw-r--r--tests/018/close-delegate.expected5
-rw-r--r--tests/018/close-delegate.tl20
2 files changed, 24 insertions, 1 deletions
diff --git a/tests/018/close-delegate.expected b/tests/018/close-delegate.expected
index 227f9f67..de68447f 100644
--- a/tests/018/close-delegate.expected
+++ b/tests/018/close-delegate.expected
@@ -1,3 +1,6 @@
close called, count 2
close called, count 1
-20
+40
+close called, count 2
+close called, count 1
+40
diff --git a/tests/018/close-delegate.tl b/tests/018/close-delegate.tl
index 4cf1d650..64a1dc91 100644
--- a/tests/018/close-delegate.tl
+++ b/tests/018/close-delegate.tl
@@ -18,3 +18,23 @@
(get-lines s))
len
prinl)
+
+(defstruct refcount-close-alt stream-wrap
+ stream
+ (count 1)
+
+ (:method close (me throw-on-error-p)
+ (put-line `close called, count @{me.count}`)
+ (when (plusp me.count)
+ (if (zerop (dec me.count))
+ (close-stream me.stream throw-on-error-p)
+ :))))
+
+(flow
+ (with-stream (s (make-struct-delegate-stream
+ (new refcount-close-alt
+ count 2
+ stream (open-file *load-path*))))
+ (get-lines s))
+ len
+ prinl)