|
| 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