2019-07-27 09:47:19 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-05-12 12:16:55 -07:00
|
|
|
require_relative "helper"
|
2012-04-30 14:28:22 -04:00
|
|
|
|
2016-11-22 16:05:49 +01:00
|
|
|
require "puma/null_io"
|
|
|
|
|
|
|
|
class TestNullIO < Minitest::Test
|
2019-07-27 09:47:19 -07:00
|
|
|
parallelize_me!
|
|
|
|
|
2012-04-30 14:28:22 -04:00
|
|
|
attr_accessor :nio
|
2016-11-23 15:32:33 +01:00
|
|
|
|
2012-04-30 14:28:22 -04:00
|
|
|
def setup
|
|
|
|
self.nio = Puma::NullIO.new
|
|
|
|
end
|
|
|
|
|
2016-12-12 11:58:36 -05:00
|
|
|
def test_eof_returns_true
|
|
|
|
assert nio.eof?
|
|
|
|
end
|
|
|
|
|
2016-11-23 15:32:33 +01:00
|
|
|
def test_gets_returns_nil
|
|
|
|
assert_nil nio.gets
|
|
|
|
end
|
|
|
|
|
2021-01-04 17:52:23 +01:00
|
|
|
def test_string_returns_empty_string
|
|
|
|
assert_equal "", nio.string
|
|
|
|
end
|
|
|
|
|
2016-11-23 15:32:33 +01:00
|
|
|
def test_each_never_yields
|
2019-07-27 09:47:19 -07:00
|
|
|
nio.instance_variable_set(:@foo, :baz)
|
|
|
|
nio.each { @foo = :bar }
|
|
|
|
assert_equal :baz, nio.instance_variable_get(:@foo)
|
2016-11-23 15:32:33 +01:00
|
|
|
end
|
|
|
|
|
2012-04-30 14:28:22 -04:00
|
|
|
def test_read_with_no_arguments
|
|
|
|
assert_equal "", nio.read
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_read_with_nil_length
|
|
|
|
assert_equal "", nio.read(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_read_with_zero_length
|
|
|
|
assert_equal "", nio.read(0)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_read_with_positive_integer_length
|
|
|
|
assert_nil nio.read(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_read_with_length_and_buffer
|
|
|
|
buf = ""
|
2016-11-23 15:32:33 +01:00
|
|
|
assert_nil nio.read(1, buf)
|
2012-04-30 14:28:22 -04:00
|
|
|
assert_equal "", buf
|
|
|
|
end
|
2016-02-04 22:54:21 -06:00
|
|
|
|
|
|
|
def test_size
|
|
|
|
assert_equal 0, nio.size
|
|
|
|
end
|
2021-02-10 14:30:24 -08:00
|
|
|
|
|
|
|
def test_sync_returns_true
|
|
|
|
assert_equal true, nio.sync
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_flush_returns_self
|
|
|
|
assert_equal nio, nio.flush
|
|
|
|
end
|
2022-05-20 01:08:30 +03:00
|
|
|
|
2022-06-02 13:10:54 -05:00
|
|
|
def test_closed_returns_false
|
|
|
|
assert_equal false, nio.closed?
|
2022-05-20 01:08:30 +03:00
|
|
|
end
|
2012-04-30 14:28:22 -04:00
|
|
|
end
|