Class: CompositeReadIOTest
Defined Under Namespace
Classes: Part
Instance Method Summary
collapse
#capture_warnings, jruby?, rbx?, ssl_mode?, #test_default
#live_server, #live_server=, #live_server?
Instance Method Details
107
108
109
110
|
# File 'test/composite_read_io_test.rb', line 107
def bin(str)
str.force_encoding("BINARY") if str.respond_to?(:force_encoding)
str
end
|
#composite_io(*parts) ⇒ Object
#part(str) ⇒ Object
9
10
11
|
# File 'test/composite_read_io_test.rb', line 9
def part(str)
Part.new StringIO.new(str)
end
|
#test_compatible_with_copy_stream ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'test/composite_read_io_test.rb', line 75
def test_compatible_with_copy_stream
target_io = StringIO.new
def target_io.ensure_open_and_writable
end
io = composite_io(part("abcd"), part("1234"))
Faraday::Timer.timeout(1) do
IO.copy_stream(io, target_io)
end
assert_equal "abcd1234", target_io.string
end
|
#test_empty ⇒ Object
17
18
19
20
21
|
# File 'test/composite_read_io_test.rb', line 17
def test_empty
io = composite_io
assert_equal 0, io.length
assert_equal "", io.read
end
|
#test_empty_parts_returns_nil_for_limited_read ⇒ Object
27
28
29
30
|
# File 'test/composite_read_io_test.rb', line 27
def test_empty_parts_returns_nil_for_limited_read
io = composite_io(part(""), part(""))
assert_nil io.read(1)
end
|
#test_empty_returns_nil_for_limited_read ⇒ Object
23
24
25
|
# File 'test/composite_read_io_test.rb', line 23
def test_empty_returns_nil_for_limited_read
assert_nil composite_io.read(1)
end
|
#test_limited_from_multibyte ⇒ Object
97
98
99
100
101
102
103
104
|
# File 'test/composite_read_io_test.rb', line 97
def test_limited_from_multibyte
File.open(File.dirname(__FILE__) + '/multibyte.txt') do |utf8|
io = composite_io(part("\x86"), Part.new(utf8))
assert_equal bin("\x86\xE3\x83"), io.read(3)
assert_equal bin("\x95\xE3\x82"), io.read(3)
assert_equal bin("\xA1\xE3\x82\xA4\xE3\x83\xAB\n"), io.read(8)
end
end
|
#test_multipart_read_all ⇒ Object
32
33
34
35
36
|
# File 'test/composite_read_io_test.rb', line 32
def test_multipart_read_all
io = composite_io(part("abcd"), part("1234"))
assert_equal 8, io.length
assert_equal "abcd1234", io.read
end
|
#test_multipart_read_limited ⇒ Object
38
39
40
41
42
43
44
45
|
# File 'test/composite_read_io_test.rb', line 38
def test_multipart_read_limited
io = composite_io(part("abcd"), part("1234"))
assert_equal "abc", io.read(3)
assert_equal "d12", io.read(3)
assert_equal "34", io.read(3)
assert_equal nil, io.read(3)
assert_equal nil, io.read(3)
end
|
#test_multipart_read_limited_size_larger_than_part ⇒ Object
47
48
49
50
51
52
|
# File 'test/composite_read_io_test.rb', line 47
def test_multipart_read_limited_size_larger_than_part
io = composite_io(part("abcd"), part("1234"))
assert_equal "abcd12", io.read(6)
assert_equal "34", io.read(6)
assert_equal nil, io.read(6)
end
|
#test_multipart_read_with_blank_parts ⇒ Object
54
55
56
57
58
59
|
# File 'test/composite_read_io_test.rb', line 54
def test_multipart_read_with_blank_parts
io = composite_io(part(""), part("abcd"), part(""), part("1234"), part(""))
assert_equal "abcd12", io.read(6)
assert_equal "34", io.read(6)
assert_equal nil, io.read(6)
end
|
#test_multipart_rewind ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
|
# File 'test/composite_read_io_test.rb', line 61
def test_multipart_rewind
io = composite_io(part("abcd"), part("1234"))
assert_equal "abc", io.read(3)
assert_equal "d12", io.read(3)
io.rewind
assert_equal "abc", io.read(3)
assert_equal "d1234", io.read(5)
assert_equal nil, io.read(3)
io.rewind
assert_equal "ab", io.read(2)
end
|
#test_read_from_multibyte ⇒ Object
90
91
92
93
94
95
|
# File 'test/composite_read_io_test.rb', line 90
def test_read_from_multibyte
File.open(File.dirname(__FILE__) + '/multibyte.txt') do |utf8|
io = composite_io(part("\x86"), Part.new(utf8))
assert_equal bin("\x86\xE3\x83\x95\xE3\x82\xA1\xE3\x82\xA4\xE3\x83\xAB\n"), io.read
end
end
|