Skip to content

Commit

Permalink
fix closing byte vector input port + unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed Jan 16, 2024
1 parent 64e6bf0 commit 88262d5
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[![npm](https://img.shields.io/badge/npm-1.0.0%E2%80%93beta.17.3-blue.svg)](https://www.npmjs.com/package/@jcubic/lips)
![1.0.0 Complete](https://img.shields.io/github/milestones/progress-percent/jcubic/lips/1?label=1.0.0%20Complete)
[![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)
[![Coverage Status](https://coveralls.io/repos/github/jcubic/lips/badge.svg?branch=devel&f9d187f3e5e7714da90a616b472c4d99)](https://coveralls.io/github/jcubic/lips?branch=devel)
[![Coverage Status](https://coveralls.io/repos/github/jcubic/lips/badge.svg?branch=devel&8bdfb9f67e52591ff37dd939e796cdb6)](https://coveralls.io/github/jcubic/lips?branch=devel)
[![Join Gitter Chat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/jcubic/lips)
![NPM Download Count](https://img.shields.io/npm/dm/@jcubic/lips)
![JSDelivr Download count](https://img.shields.io/jsdelivr/npm/hm/@jcubic/lips)
Expand Down
10 changes: 5 additions & 5 deletions dist/lips.esm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/lips.esm.min.js

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions dist/lips.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/lips.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/lips.js
Original file line number Diff line number Diff line change
Expand Up @@ -6437,7 +6437,7 @@ InputByteVectorPort.prototype.close = function() {
throw new Error('Input-binary-port: port is closed');
};
});
this.char_ready = function() {
this.u8_ready = this.char_ready = function() {
return false;
};
};
Expand Down
26 changes: 24 additions & 2 deletions tests/ports.scm
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,28 @@
(lambda (t)
(let ((p (open-input-bytevector #u8(#x10 #x20 #xFF #xFF #xFF))))
(t.is (binary-port? p) true)
(t.is (textual-port? p) false))))
(t.is (textual-port? p) false)
(close-input-port p))))

(test "ports: should close input-bytevector"
(lambda (t)
(let ((p (open-input-bytevector #u8(#x10 #x20 #xFF #xFF #xFF))))
(close-input-port p)
(t.is (to.throw (read-u8 p)) #t)
(t.is (char-ready? p) #f)
(t.is (u8-ready? p) #f))))

(test "ports: should return max elements from byte vector port"
(lambda (t)
(let ((port (open-input-bytevector #u8(#x10 #x20 #xFF #xFF #xFF))))
(t.is (read-u8 port) #x10)
(t.is (read-bytevector 100 port) #u8(#x20 #xFF #xFF #xFF))
(close-port port))))

(test "ports: should read all elements from u8 byte vector port"
(lambda (t)
(let ((port (open-input-bytevector #u8(#x10 #x20 #xFF #xFF #xFF))))
(t.is (with-input-from-port port read-bytevector) #u8(#x10 #x20 #xFF #xFF #xFF)))))

(test "ports: read from open-input-bytevector"
(lambda (t)
Expand All @@ -220,7 +241,8 @@
(while (not (eof-object? (peek-u8 p)))
(result.push (read-u8 p)))
(t.is result #(#x20 #xFF #xFF #xFF))
(t.is (eof-object? (peek-u8 p)) true)))))
(t.is (eof-object? (peek-u8 p)) true)
(t.is (eof-object? (read-u8 p)) true)))))

(test "ports: textual-port?"
(lambda (t)
Expand Down

0 comments on commit 88262d5

Please sign in to comment.