Skip to content

Commit

Permalink
Testing InputStreamLike with and without available member
Browse files Browse the repository at this point in the history
  • Loading branch information
JaroslavTulach committed Jun 20, 2024
1 parent 8d0684c commit bfa60b4
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions test/Base_Tests/src/System/Input_Stream_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,33 @@ import Standard.Base.System.Input_Stream.Input_Stream
from Standard.Test import all

polyglot java import org.enso.base_test_helpers.RangeStream
polyglot java import org.enso.base.Stream_Utils

main filter=Nothing =
suite = Test.build suite_builder->
add_specs suite_builder
suite.run_with_filter filter


foreign js is_like data available = """
let at = 0
let is = {
read : function(arr, off, len) {
let cnt = 0;
while (len-- > 0) {
arr[off++] = data[at++];
cnt++;
}
return cnt;
}
}
if (available) {
is.available = function() {
return data.length - at;
};
}
return is;

add_specs suite_builder = suite_builder.group "Input Stream" group_builder->
group_builder.specify "should be peekable if backed by memory" <|
Managed_Resource.bracket (Input_Stream.from_bytes [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) (.close) stream->
Expand Down Expand Up @@ -61,3 +82,33 @@ add_specs suite_builder = suite_builder.group "Input Stream" group_builder->
promoted_stream.peek_bytes 10 . should_equal [100, 101, 102, 103, 104]
# The read still succeeds - ensuring there isn't some early EOF
promoted_stream.read_n_bytes 10 . should_equal [100, 101, 102, 103, 104]

group_builder.specify "read without available" <|
stream_like = is_like [20, 5, 1, 10] False
is = Stream_Utils.asInputStream stream_like
is.available . should_equal 0

is.read . should_equal 20
is.read . should_equal 5

is.available . should_equal 0

is.read . should_equal 1
is.read . should_equal 10

is.available . should_equal 0

group_builder.specify "read with available" <|
stream_like = is_like [20, 6, 8, 23] True
is = Stream_Utils.asInputStream stream_like
is.available . should_equal 4

is.read . should_equal 20
is.read . should_equal 6

is.available . should_equal 2

is.read . should_equal 8
is.read . should_equal 23

is.available . should_equal 0

0 comments on commit bfa60b4

Please sign in to comment.