Skip to content

Commit 88262d5

Browse files
committed
fix closing byte vector input port + unit tests
1 parent 64e6bf0 commit 88262d5

File tree

7 files changed

+40
-18
lines changed

7 files changed

+40
-18
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
[![npm](https://img.shields.io/badge/npm-1.0.0%E2%80%93beta.17.3-blue.svg)](https://www.npmjs.com/package/@jcubic/lips)
99
![1.0.0 Complete](https://img.shields.io/github/milestones/progress-percent/jcubic/lips/1?label=1.0.0%20Complete)
1010
[![Build and test](https://github.com/jcubic/lips/actions/workflows/build.yaml/badge.svg?branch=devel&event=push)](https://github.com/jcubic/lips/actions/workflows/build.yaml)
11-
[![Coverage Status](https://coveralls.io/repos/github/jcubic/lips/badge.svg?branch=devel&f9d187f3e5e7714da90a616b472c4d99)](https://coveralls.io/github/jcubic/lips?branch=devel)
11+
[![Coverage Status](https://coveralls.io/repos/github/jcubic/lips/badge.svg?branch=devel&8bdfb9f67e52591ff37dd939e796cdb6)](https://coveralls.io/github/jcubic/lips?branch=devel)
1212
[![Join Gitter Chat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/jcubic/lips)
1313
![NPM Download Count](https://img.shields.io/npm/dm/@jcubic/lips)
1414
![JSDelivr Download count](https://img.shields.io/jsdelivr/npm/hm/@jcubic/lips)

dist/lips.esm.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/lips.esm.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/lips.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/lips.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lips.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6437,7 +6437,7 @@ InputByteVectorPort.prototype.close = function() {
64376437
throw new Error('Input-binary-port: port is closed');
64386438
};
64396439
});
6440-
this.char_ready = function() {
6440+
this.u8_ready = this.char_ready = function() {
64416441
return false;
64426442
};
64436443
};

tests/ports.scm

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,28 @@
206206
(lambda (t)
207207
(let ((p (open-input-bytevector #u8(#x10 #x20 #xFF #xFF #xFF))))
208208
(t.is (binary-port? p) true)
209-
(t.is (textual-port? p) false))))
209+
(t.is (textual-port? p) false)
210+
(close-input-port p))))
211+
212+
(test "ports: should close input-bytevector"
213+
(lambda (t)
214+
(let ((p (open-input-bytevector #u8(#x10 #x20 #xFF #xFF #xFF))))
215+
(close-input-port p)
216+
(t.is (to.throw (read-u8 p)) #t)
217+
(t.is (char-ready? p) #f)
218+
(t.is (u8-ready? p) #f))))
219+
220+
(test "ports: should return max elements from byte vector port"
221+
(lambda (t)
222+
(let ((port (open-input-bytevector #u8(#x10 #x20 #xFF #xFF #xFF))))
223+
(t.is (read-u8 port) #x10)
224+
(t.is (read-bytevector 100 port) #u8(#x20 #xFF #xFF #xFF))
225+
(close-port port))))
226+
227+
(test "ports: should read all elements from u8 byte vector port"
228+
(lambda (t)
229+
(let ((port (open-input-bytevector #u8(#x10 #x20 #xFF #xFF #xFF))))
230+
(t.is (with-input-from-port port read-bytevector) #u8(#x10 #x20 #xFF #xFF #xFF)))))
210231

211232
(test "ports: read from open-input-bytevector"
212233
(lambda (t)
@@ -220,7 +241,8 @@
220241
(while (not (eof-object? (peek-u8 p)))
221242
(result.push (read-u8 p)))
222243
(t.is result #(#x20 #xFF #xFF #xFF))
223-
(t.is (eof-object? (peek-u8 p)) true)))))
244+
(t.is (eof-object? (peek-u8 p)) true)
245+
(t.is (eof-object? (read-u8 p)) true)))))
224246

225247
(test "ports: textual-port?"
226248
(lambda (t)

0 commit comments

Comments
 (0)