Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions stdlib/zlib/0/gzip_writer.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ module Zlib
# returns a GzipWriter object associated with that file. Further details of
# this method are found in Zlib::GzipWriter.new and Zlib::GzipFile.wrap.
#
def self.open: (String filename) { (instance gz) -> void } -> instance
def self.open: (String filename, ?Integer level, ?Integer strategy, **untyped opts) -> instance
| (String filename, ?Integer level, ?Integer strategy, **untyped opts) { (instance gz) -> void } -> nil

# <!--
# rdoc-file=ext/zlib/zlib.c
Expand All @@ -64,7 +65,7 @@ module Zlib
# `flush` is same as in Zlib::Deflate#deflate. `Zlib::SYNC_FLUSH` is used if
# `flush` is omitted. It is no use giving flush `Zlib::NO_FLUSH`.
#
def flush: (?Integer flush) -> String
def flush: (?Integer flush) -> self

# <!--
# rdoc-file=ext/zlib/zlib.c
Expand All @@ -83,7 +84,7 @@ module Zlib
# compression started. Setting a value of 0 indicates no time stamp is
# available.
#
def mtime=: (path | IO file_name) -> Time
def mtime=: (Time | Integer) -> void

# <!--
# rdoc-file=ext/zlib/zlib.c
Expand Down
114 changes: 114 additions & 0 deletions test/stdlib/zlib/GzipWriter_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
require_relative "../test_helper"
require "zlib"
require "tempfile"

class ZlibGzipWriterSingletonTest < Test::Unit::TestCase
include TestHelper

library "zlib"
testing "singleton(::Zlib::GzipWriter)"

def test_open
Dir.mktmpdir do |tmpdir|
path = File.join(tmpdir, "test.gz")
result = assert_send_type "(String) -> Zlib::GzipWriter", Zlib::GzipWriter, :open, path
result.close

assert_send_type "(String) { (Zlib::GzipWriter) -> void } -> nil",
Zlib::GzipWriter, :open, path do |gz| end
assert_send_type "(String, Integer, Integer) { (Zlib::GzipWriter) -> void } -> nil",
Zlib::GzipWriter, :open, path, Zlib::DEFAULT_COMPRESSION, Zlib::DEFAULT_STRATEGY do |gz| end
assert_send_type "(String, Integer, Integer, encoding: Encoding) { (Zlib::GzipWriter) -> void } -> nil",
Zlib::GzipWriter, :open, path, Zlib::DEFAULT_COMPRESSION, Zlib::DEFAULT_STRATEGY, encoding: Encoding::UTF_8 do |gz| end

end
end

def test_new
assert_send_type "(StringIO) -> Zlib::GzipWriter",
Zlib::GzipWriter, :new, StringIO.new
assert_send_type "(StringIO, Integer) -> Zlib::GzipWriter",
Zlib::GzipWriter, :new, StringIO.new, Zlib::DEFAULT_COMPRESSION
assert_send_type "(StringIO, Integer, Integer) -> Zlib::GzipWriter",
Zlib::GzipWriter, :new, StringIO.new, Zlib::DEFAULT_COMPRESSION, Zlib::DEFAULT_STRATEGY
assert_send_type "(StringIO, Integer, Integer, encoding: Encoding) -> Zlib::GzipWriter",
Zlib::GzipWriter, :new, StringIO.new, Zlib::DEFAULT_COMPRESSION, Zlib::DEFAULT_STRATEGY, encoding: Encoding::UTF_8
end
end

class ZlibGzipWriterInstanceTest < Test::Unit::TestCase
include TestHelper

library "zlib"
testing "::Zlib::GzipWriter"

def test_lshift
assert_send_type "(String) -> Zlib::GzipWriter",
Zlib::GzipWriter.new(StringIO.new), :<<, "hello"
end

def test_comment=
assert_send_type "(String) -> void",
Zlib::GzipWriter.new(StringIO.new), :comment=, "hello"
end

def test_flush
assert_send_type "() -> Zlib::GzipWriter",
Zlib::GzipWriter.new(StringIO.new), :flush
assert_send_type "(Integer) -> Zlib::GzipWriter",
Zlib::GzipWriter.new(StringIO.new), :flush, Zlib::SYNC_FLUSH
end

def test_mtime=
assert_send_type "(Time) -> void",
Zlib::GzipWriter.new(StringIO.new), :mtime=, Time.now
assert_send_type "(Integer) -> void",
Zlib::GzipWriter.new(StringIO.new), :mtime=, 0
end

def test_orig_name=
assert_send_type "(String) -> void",
Zlib::GzipWriter.new(StringIO.new), :orig_name=, "hello"
end

def test_pos
assert_send_type "() -> Integer",
Zlib::GzipWriter.new(StringIO.new), :pos
end

def test_print
assert_send_type "(String) -> nil",
Zlib::GzipWriter.new(StringIO.new), :print, "hello"
end

def test_printf
assert_send_type "(String) -> nil",
Zlib::GzipWriter.new(StringIO.new), :printf, "hello"
assert_send_type "(String, Integer) -> nil",
Zlib::GzipWriter.new(StringIO.new), :printf, "%d", 1
end

def test_putc
assert_send_type "(String) -> String",
Zlib::GzipWriter.new(StringIO.new), :putc, "h"
assert_send_type "(Integer) -> Integer",
Zlib::GzipWriter.new(StringIO.new), :putc, "h".ord
end

def test_puts
assert_send_type "() -> nil",
Zlib::GzipWriter.new(StringIO.new), :puts
assert_send_type "(String) -> nil",
Zlib::GzipWriter.new(StringIO.new), :puts, "hello"
end

def test_tell
assert_send_type "() -> Integer",
Zlib::GzipWriter.new(StringIO.new), :tell
end

def test_write
assert_send_type "(String) -> Integer",
Zlib::GzipWriter.new(StringIO.new), :write, "hello"
end
end