From 0da5ef84c1c95dc21fd62721cd5a0a31301fd3ab Mon Sep 17 00:00:00 2001 From: Taylor R Campbell Date: Sat, 8 Dec 2018 14:10:14 +0000 Subject: [PATCH] Export binary-port-position and set-binary-port-position!. Currently busted for output ports. --- src/runtime/runtime.pkg | 2 ++ tests/runtime/test-binary-port.scm | 26 +++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/runtime/runtime.pkg b/src/runtime/runtime.pkg index 76c0b85a0..e7daff07d 100644 --- a/src/runtime/runtime.pkg +++ b/src/runtime/runtime.pkg @@ -2596,6 +2596,7 @@ USA. binary-i/o-port? binary-input-port? binary-output-port? + binary-port-position binary-port? call-with-output-bytevector get-output-bytevector @@ -2605,6 +2606,7 @@ USA. read-bytevector read-bytevector! read-u8 + set-binary-port-position! textual->binary-port u8-ready? write-bytevector diff --git a/tests/runtime/test-binary-port.scm b/tests/runtime/test-binary-port.scm index 9a3f7b8c2..bc5308c00 100644 --- a/tests/runtime/test-binary-port.scm +++ b/tests/runtime/test-binary-port.scm @@ -179,4 +179,28 @@ USA. (assert-false (textual-port? port)) (assert-false (input-port? port)) (assert-true (output-port? port)) - (assert-false (i/o-port? port))) \ No newline at end of file + (assert-false (i/o-port? port))) + +(define-test 'position + (lambda () + (call-with-temporary-file-pathname + (lambda (pathname) + (call-with-binary-output-file pathname + (lambda (port) + (assert-= (binary-port-position port) 0) + (write-u8 42 port) + (expect-failure + (lambda () + (assert-= (binary-port-position port) 1))) + (write-bytevector (make-bytevector 1000 0) port) + (expect-failure + (lambda () + (assert-= (binary-port-position port) 1001))))) + (call-with-binary-input-file pathname + (lambda (port) + (assert-= (binary-port-position port) 0) + (assert-= (read-u8 port) 42) + (assert-= (binary-port-position port) 1) + (assert-equal (read-bytevector 1000 port) + (make-bytevector 1000 0)) + (assert-= (binary-port-position port) 1001))))))) \ No newline at end of file -- 2.25.1