@@ -39,6 +39,23 @@ def test_gets
3939 end
4040end
4141
42+ class StringIOSingletonTest < Test ::Unit ::TestCase
43+ include TestHelper
44+
45+ testing 'singleton(::StringIO)'
46+
47+ def test_open
48+ assert_send_type "() -> ::StringIO" ,
49+ StringIO , :open
50+ assert_send_type "(::String) -> ::StringIO" ,
51+ StringIO , :open , "abc"
52+ assert_send_type "(::String, ::String) -> ::StringIO" ,
53+ StringIO , :open , "abc" , "r"
54+ assert_send_type "() { (::StringIO) -> ::Integer } -> ::Integer" ,
55+ StringIO , :open do |io | io . write ( "a" ) end
56+ end
57+ end
58+
4259class StringIOTypeTest < Test ::Unit ::TestCase
4360 include TestHelper
4461
@@ -85,4 +102,74 @@ def test_readlines
85102 assert_send_type "(::String sep, ::Integer limit, chomp: boolish) -> ::Array[::String]" ,
86103 StringIO . new ( "\n " ) , :readlines , "\n " , 1 , chomp : true
87104 end
105+
106+ def test_pread
107+ assert_send_type "(Integer, Integer) -> String" ,
108+ StringIO . new ( "abcdef" ) , :pread , 3 , 0
109+ assert_send_type "(Integer, Integer, String) -> String" ,
110+ StringIO . new ( "abcdef" ) , :pread , 3 , 0 , +"buf"
111+ end
112+
113+ def test_read_nonblock
114+ assert_send_type "(int) -> String" ,
115+ StringIO . new ( "abc" ) , :read_nonblock , 2
116+ assert_send_type "(int, string) -> String" ,
117+ StringIO . new ( "abc" ) , :read_nonblock , 2 , +"buf"
118+ assert_send_type "(int, exception: true) -> String" ,
119+ StringIO . new ( "abc" ) , :read_nonblock , 2 , exception : true
120+ assert_send_type "(int, exception: false) -> String" ,
121+ StringIO . new ( "abc" ) , :read_nonblock , 2 , exception : false
122+ assert_send_type "(int, exception: false) -> nil" ,
123+ StringIO . new ( "" ) , :read_nonblock , 2 , exception : false
124+ end
125+
126+ def test_write_nonblock
127+ assert_send_type "(_ToS) -> Integer" ,
128+ StringIO . new ( +"" ) , :write_nonblock , "abc"
129+ assert_send_type "(_ToS, exception: true) -> Integer" ,
130+ StringIO . new ( +"" ) , :write_nonblock , "abc" , exception : true
131+ assert_send_type "(_ToS, exception: false) -> Integer" ,
132+ StringIO . new ( +"" ) , :write_nonblock , "abc" , exception : false
133+ end
134+
135+ def test_sysread
136+ assert_send_type "(Integer) -> String" ,
137+ StringIO . new ( "abc" ) , :sysread , 2
138+ assert_send_type "(Integer, String) -> String" ,
139+ StringIO . new ( "abc" ) , :sysread , 2 , +"buf"
140+ end
141+
142+ def test_ungetc
143+ assert_send_type "(String) -> nil" ,
144+ StringIO . new ( +"abc" ) , :ungetc , "x"
145+ assert_send_type "(Integer) -> nil" ,
146+ StringIO . new ( +"abc" ) , :ungetc , 65
147+ end
148+
149+ def test_set_encoding_by_bom
150+ assert_send_type "() -> Encoding" ,
151+ StringIO . new ( "\u{FEFF} abc" ) , :set_encoding_by_bom
152+ assert_send_type "() -> nil" ,
153+ StringIO . new ( "abc" ) , :set_encoding_by_bom
154+ end
155+
156+ def test_fcntl
157+ assert_send_type_error "(*untyped) -> bot" , NotImplementedError ,
158+ StringIO . new ( "abc" ) , :fcntl , 1 , 1
159+ end
160+
161+ def test_fsync
162+ assert_send_type "() -> Integer" ,
163+ StringIO . new ( "abc" ) , :fsync
164+ end
165+
166+ def test_internal_encoding
167+ assert_send_type "() -> nil" ,
168+ StringIO . new ( "abc" ) , :internal_encoding
169+ end
170+
171+ def test_external_encoding
172+ assert_send_type "() -> Encoding" ,
173+ StringIO . new ( "abc" ) , :external_encoding
174+ end
88175end
0 commit comments