Skip to content

Commit ce908ae

Browse files
committed
1 parent b37a991 commit ce908ae

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

stdlib/csv/0/csv.rbs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3814,3 +3814,21 @@ class CSV::Table[out Elem] < Object
38143814
#
38153815
def values_at: (*untyped indices_or_headers) -> untyped
38163816
end
3817+
3818+
%a{annotate:rdoc:skip}
3819+
class Array[unchecked out Elem] < Object
3820+
# Equivalent to CSV::generate_line(self, options)
3821+
#
3822+
# ["CSV", "data"].to_csv
3823+
# #=> "CSV,data\n"
3824+
def to_csv: (**untyped options) -> String
3825+
end
3826+
3827+
%a{annotate:rdoc:skip}
3828+
class String
3829+
# Equivalent to CSV::parse_line(self, options)
3830+
#
3831+
# "CSV,data".parse_csv
3832+
# #=> ["CSV", "data"]
3833+
def parse_csv: (**untyped options) -> ::Array[String?]?
3834+
end

test/stdlib/CSV_test.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,31 @@ def test_headers
9696
csv, :headers
9797
end
9898
end
99+
100+
class CSVArrayTest < Test::Unit::TestCase
101+
include TestHelper
102+
103+
library "csv"
104+
testing "Array[untyped]"
105+
106+
def test_to_csv_with_array
107+
assert_send_type "() -> String",
108+
[1, 2, 3], :to_csv
109+
assert_send_type "(**untyped) -> String",
110+
[1, 2, 3], :to_csv, col_sep: '\t'
111+
end
112+
end
113+
114+
class CSVStringTest < Test::Unit::TestCase
115+
include TestHelper
116+
117+
library "csv"
118+
testing "String"
119+
120+
def test_parse_csv_with_string
121+
assert_send_type "() -> Array[String?]",
122+
"1,2,3", :parse_csv
123+
assert_send_type "(**untyped) -> Array[String?]",
124+
"1,2,3", :parse_csv, col_sep: '\t'
125+
end
126+
end

0 commit comments

Comments
 (0)