diff options
author | rm155 <86454369+rm155@users.noreply.github.com> | 2021-10-10 22:21:42 -0400 |
---|---|---|
committer | Sutou Kouhei <kou@cozmixng.org> | 2021-10-24 05:57:33 +0900 |
commit | ee948fc1b4cb1ad382beee709008bb93b8f6ba75 (patch) | |
tree | 323e979f3c67259699d838228d28a0ea4fb3ac92 /test/csv/interface | |
parent | 274882be62e5996d804e87103586feaeec381820 (diff) |
[ruby/csv] Add support for Ractor (https://github.com/ruby/csv/pull/218)
https://github.com/ruby/csv/commit/a802690e11
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/5010
Diffstat (limited to 'test/csv/interface')
-rw-r--r-- | test/csv/interface/test_read.rb | 32 | ||||
-rw-r--r-- | test/csv/interface/test_write.rb | 34 |
2 files changed, 66 insertions, 0 deletions
diff --git a/test/csv/interface/test_read.rb b/test/csv/interface/test_read.rb index b86c54fc9f..d73622d554 100644 --- a/test/csv/interface/test_read.rb +++ b/test/csv/interface/test_read.rb @@ -32,6 +32,24 @@ class TestCSVInterfaceRead < Test::Unit::TestCase assert_equal(@rows, rows) end + if respond_to?(:ractor) + ractor + def test_foreach_in_ractor + ractor = Ractor.new(@input.path) do |path| + rows = [] + CSV.foreach(path, col_sep: "\t", row_sep: "\r\n").each do |row| + rows << row + end + rows + end + rows = [ + ["1", "2", "3"], + ["4", "5"], + ] + assert_equal(rows, ractor.take) + end + end + def test_foreach_mode rows = [] CSV.foreach(@input.path, "r", col_sep: "\t", row_sep: "\r\n").each do |row| @@ -240,6 +258,20 @@ class TestCSVInterfaceRead < Test::Unit::TestCase CSV.read(@input.path, col_sep: "\t", row_sep: "\r\n")) end + if respond_to?(:ractor) + ractor + def test_read_in_ractor + ractor = Ractor.new(@input.path) do |path| + CSV.read(path, col_sep: "\t", row_sep: "\r\n") + end + rows = [ + ["1", "2", "3"], + ["4", "5"], + ] + assert_equal(rows, ractor.take) + end + end + def test_readlines assert_equal(@rows, CSV.readlines(@input.path, col_sep: "\t", row_sep: "\r\n")) diff --git a/test/csv/interface/test_write.rb b/test/csv/interface/test_write.rb index 8650ecd624..02c2c5c5ce 100644 --- a/test/csv/interface/test_write.rb +++ b/test/csv/interface/test_write.rb @@ -25,6 +25,21 @@ class TestCSVInterfaceWrite < Test::Unit::TestCase CSV end + if respond_to?(:ractor) + ractor + def test_generate_default_in_ractor + ractor = Ractor.new do + CSV.generate do |csv| + csv << [1, 2, 3] << [4, nil, 5] + end + end + assert_equal(<<-CSV, ractor.take) +1,2,3 +4,,5 + CSV + end + end + def test_generate_append csv_text = <<-CSV 1,2,3 @@ -101,6 +116,25 @@ a,b,c CSV end + + if respond_to?(:ractor) + ractor + def test_append_row_in_ractor + ractor = Ractor.new(@output.path) do |path| + CSV.open(path, "wb") do |csv| + csv << + CSV::Row.new([], ["1", "2", "3"]) << + CSV::Row.new([], ["a", "b", "c"]) + end + end + ractor.take + assert_equal(<<-CSV, File.read(@output.path, mode: "rb")) +1,2,3 +a,b,c + CSV + end + end + def test_append_hash CSV.open(@output.path, "wb", headers: true) do |csv| csv << [:a, :b, :c] |