Skip to content

Commit 337ce64

Browse files
committed
Fix Zlib::GzipWriter signatures
1 parent 17f5871 commit 337ce64

2 files changed

Lines changed: 118 additions & 3 deletions

File tree

stdlib/zlib/0/gzip_writer.rbs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ module Zlib
3838
# returns a GzipWriter object associated with that file. Further details of
3939
# this method are found in Zlib::GzipWriter.new and Zlib::GzipFile.wrap.
4040
#
41-
def self.open: (String filename) { (instance gz) -> void } -> instance
41+
def self.open: (String filename, ?Integer level, ?Integer strategy, **untyped opts) -> instance
42+
| (String filename, ?Integer level, ?Integer strategy, **untyped opts) { (instance gz) -> void } -> nil
4243

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

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

8889
# <!--
8990
# rdoc-file=ext/zlib/zlib.c
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
require_relative "../test_helper"
2+
require "zlib"
3+
require "tempfile"
4+
5+
class ZlibGzipWriterSingletonTest < Test::Unit::TestCase
6+
include TestHelper
7+
8+
library "zlib"
9+
testing "singleton(::Zlib::GzipWriter)"
10+
11+
def test_open
12+
Dir.mktmpdir do |tmpdir|
13+
path = File.join(tmpdir, "test.gz")
14+
result = assert_send_type "(String) -> Zlib::GzipWriter", Zlib::GzipWriter, :open, path
15+
result.close
16+
17+
assert_send_type "(String) { (Zlib::GzipWriter) -> void } -> nil",
18+
Zlib::GzipWriter, :open, path do |gz| end
19+
assert_send_type "(String, Integer, Integer) { (Zlib::GzipWriter) -> void } -> nil",
20+
Zlib::GzipWriter, :open, path, Zlib::DEFAULT_COMPRESSION, Zlib::DEFAULT_STRATEGY do |gz| end
21+
assert_send_type "(String, Integer, Integer, encoding: Encoding) { (Zlib::GzipWriter) -> void } -> nil",
22+
Zlib::GzipWriter, :open, path, Zlib::DEFAULT_COMPRESSION, Zlib::DEFAULT_STRATEGY, encoding: Encoding::UTF_8 do |gz| end
23+
24+
end
25+
end
26+
27+
def test_new
28+
assert_send_type "(StringIO) -> Zlib::GzipWriter",
29+
Zlib::GzipWriter, :new, StringIO.new
30+
assert_send_type "(StringIO, Integer) -> Zlib::GzipWriter",
31+
Zlib::GzipWriter, :new, StringIO.new, Zlib::DEFAULT_COMPRESSION
32+
assert_send_type "(StringIO, Integer, Integer) -> Zlib::GzipWriter",
33+
Zlib::GzipWriter, :new, StringIO.new, Zlib::DEFAULT_COMPRESSION, Zlib::DEFAULT_STRATEGY
34+
assert_send_type "(StringIO, Integer, Integer, encoding: Encoding) -> Zlib::GzipWriter",
35+
Zlib::GzipWriter, :new, StringIO.new, Zlib::DEFAULT_COMPRESSION, Zlib::DEFAULT_STRATEGY, encoding: Encoding::UTF_8
36+
end
37+
end
38+
39+
class ZlibGzipWriterInstanceTest < Test::Unit::TestCase
40+
include TestHelper
41+
42+
library "zlib"
43+
testing "::Zlib::GzipWriter"
44+
45+
def test_lshift
46+
assert_send_type "(String) -> Zlib::GzipWriter",
47+
Zlib::GzipWriter.new(StringIO.new), :<<, "hello"
48+
end
49+
50+
def test_comment=
51+
assert_send_type "(String) -> void",
52+
Zlib::GzipWriter.new(StringIO.new), :comment=, "hello"
53+
end
54+
55+
def test_flush
56+
assert_send_type "() -> Zlib::GzipWriter",
57+
Zlib::GzipWriter.new(StringIO.new), :flush
58+
assert_send_type "(Integer) -> Zlib::GzipWriter",
59+
Zlib::GzipWriter.new(StringIO.new), :flush, Zlib::SYNC_FLUSH
60+
end
61+
62+
def test_mtime=
63+
assert_send_type "(Time) -> void",
64+
Zlib::GzipWriter.new(StringIO.new), :mtime=, Time.now
65+
assert_send_type "(Integer) -> void",
66+
Zlib::GzipWriter.new(StringIO.new), :mtime=, 0
67+
end
68+
69+
def test_orig_name=
70+
assert_send_type "(String) -> void",
71+
Zlib::GzipWriter.new(StringIO.new), :orig_name=, "hello"
72+
end
73+
74+
def test_pos
75+
assert_send_type "() -> Integer",
76+
Zlib::GzipWriter.new(StringIO.new), :pos
77+
end
78+
79+
def test_print
80+
assert_send_type "(String) -> nil",
81+
Zlib::GzipWriter.new(StringIO.new), :print, "hello"
82+
end
83+
84+
def test_printf
85+
assert_send_type "(String) -> nil",
86+
Zlib::GzipWriter.new(StringIO.new), :printf, "hello"
87+
assert_send_type "(String, Integer) -> nil",
88+
Zlib::GzipWriter.new(StringIO.new), :printf, "%d", 1
89+
end
90+
91+
def test_putc
92+
assert_send_type "(String) -> String",
93+
Zlib::GzipWriter.new(StringIO.new), :putc, "h"
94+
assert_send_type "(Integer) -> Integer",
95+
Zlib::GzipWriter.new(StringIO.new), :putc, "h".ord
96+
end
97+
98+
def test_puts
99+
assert_send_type "() -> nil",
100+
Zlib::GzipWriter.new(StringIO.new), :puts
101+
assert_send_type "(String) -> nil",
102+
Zlib::GzipWriter.new(StringIO.new), :puts, "hello"
103+
end
104+
105+
def test_tell
106+
assert_send_type "() -> Integer",
107+
Zlib::GzipWriter.new(StringIO.new), :tell
108+
end
109+
110+
def test_write
111+
assert_send_type "(String) -> Integer",
112+
Zlib::GzipWriter.new(StringIO.new), :write, "hello"
113+
end
114+
end

0 commit comments

Comments
 (0)