dsv 0.16.2 → 0.16.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f51c0809df8ce80d534a86623f7936def15b4dc005fc3fa02a6df1a3a4b26f32
4
- data.tar.gz: 29007e890ebe7230c885fcf09238ba2da51e59c948d90ab41cf406c88e61fa3d
3
+ metadata.gz: 954b11c8db584823303128861f9bd63437970544ecd2a517f48496ca2693491c
4
+ data.tar.gz: bea25558be05247647f04723c323ce94a564009a4899443ef16eca9c770b67cf
5
5
  SHA512:
6
- metadata.gz: a50224c24dbe0e7e8d9f5dd03024b6d13f7d62d5067ae30be8d899931ccc44e8c9f13604f159c1b608c29b91d9ff833f9bbb7d27c616b7984bb5332308b5e381
7
- data.tar.gz: 9d153d7278b130b0c8afb48d84ab791b65a2415ba2e881f8ed472540bc9db2143d92705492c60dee1a0afe5e1c9e44ab606717ad64e82820fa038c313b342cf6
6
+ metadata.gz: 599452dcb3e0330e041a4cc0ce015245ee2dc8cfa7ea71931f3cf326b079009ae94f3b3e107853704b8645e4260eec073bad19f70033b1913a2bb5b7186c2fe1
7
+ data.tar.gz: ca4f6bf54c866aae5532467dce0072fe25ac8908c591238e9e702f27392ebe36358bf26dca5b59d9c86fa5f4809d532bef1dbaef325ce2d1e7598c4f19bbb4e9
data/CHANGELOG CHANGED
@@ -1,5 +1,14 @@
1
1
  # dsv/CHANGELOG
2
2
 
3
+ ## 20261128
4
+
5
+ 0.16.3: ~ DSV: Its String literals are frozen, so as reading makes half as many objects.
6
+
7
+ 1. ~ DSV, DSV::File, DSV::String, DSV::Error, DSV::UnexpectedRow, DSV::UnquotedField, DSV::UnterminatedQuote, DSV::VERSION: Each file declares frozen_string_literal: true. A literal had been a new String each time it was reached, which in reading was several times for every quoted field.
8
+ 2. ~ test/dsv_test.rb: The default row separator and mode are tested to be frozen, and quoted fields to be read without a new copy of the quote character each time it is used.
9
+ 3. ~ test/helper.rb: + require 'objspace'
10
+ 4. ~ DSV::VERSION: /0.16.2/0.16.3/
11
+
3
12
  ## 20261127
4
13
 
5
14
  0.16.2: ~ DSV#read, ~ DSV#write: The columns selected are flattened once, not for every row.
data/lib/DSV/Error.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  # DSV/Error.rb
2
2
  # DSV::Error
3
3
 
4
+ # frozen_string_literal: true
5
+
4
6
  class DSV
5
7
  # The base of what dsv raises about the data, so that one rescue catches all of it.
6
8
  class Error < ::StandardError
data/lib/DSV/File.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  # DSV/File.rb
2
2
  # DSV::File
3
3
 
4
+ # frozen_string_literal: true
5
+
4
6
  require_relative '../dsv'
5
7
 
6
8
  class DSV
data/lib/DSV/String.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  # DSV/String.rb
2
2
  # DSV::String
3
3
 
4
+ # frozen_string_literal: true
5
+
4
6
  require_relative '../dsv'
5
7
 
6
8
  class DSV
@@ -1,6 +1,8 @@
1
1
  # DSV/UnexpectedRow.rb
2
2
  # DSV::UnexpectedRow
3
3
 
4
+ # frozen_string_literal: true
5
+
4
6
  class DSV
5
7
  # A row which contradicts its declared quote mode; mode is the mode in force, and line the one on which the row began, given by the reader once it knows it.
6
8
  class UnexpectedRow < Error
@@ -1,6 +1,8 @@
1
1
  # DSV/UnquotedField.rb
2
2
  # DSV::UnquotedField
3
3
 
4
+ # frozen_string_literal: true
5
+
4
6
  class DSV
5
7
  # A field with no quotes, under a quote mode which declares every field quoted.
6
8
  class UnquotedField < UnexpectedRow
@@ -1,6 +1,8 @@
1
1
  # DSV/UnterminatedQuote.rb
2
2
  # DSV::UnterminatedQuote
3
3
 
4
+ # frozen_string_literal: true
5
+
4
6
  class DSV
5
7
  # A quoted field which does not close by the end of the source; line is the one on which its row began.
6
8
  class UnterminatedQuote < Error
data/lib/DSV/VERSION.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  # DSV/VERSION.rb
2
2
  # DSV::VERSION
3
3
 
4
+ # frozen_string_literal: true
5
+
4
6
  class DSV
5
- VERSION = '0.16.2'
7
+ VERSION = '0.16.3'
6
8
  end
data/lib/dsv.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  # dsv.rb
2
2
  # DSV
3
3
 
4
+ # frozen_string_literal: true
5
+
4
6
  # Description: Delimiter-separated values: reading and writing CSV and its relatives, tabulated data to and from files and strings, with any delimiter on either side.
5
7
 
6
8
  require 'stringio'
data/test/dsv_test.rb CHANGED
@@ -396,6 +396,12 @@ describe DSV do
396
396
  _(DSV.new(DATA).quote).must_be_nil
397
397
  end
398
398
 
399
+ it "gives its own defaults frozen" do
400
+ csv = DSV.new("a,b\n")
401
+ _(csv.row_separator).must_be :frozen?
402
+ _(csv.mode).must_be :frozen?
403
+ end
404
+
399
405
  it "has its interface public and its internals private" do
400
406
  csv = DSV.new(DATA, headers: true)
401
407
  [:close, :read, :read_header, :parse, :columns, :columns=, :repeated_names, :parse_row, :write, :write_header, :write_row, :each, :attributes, :attributes=, :header_row?, :first_row, :to_a].each{|name| _(csv.public_methods).must_include name}
@@ -744,6 +750,21 @@ describe DSV do
744
750
  csv.quote = :single
745
751
  _(csv.read).must_equal [{0 => 'a', 1 => 'b'}]
746
752
  end
753
+
754
+ it "reads quoted fields without making a new copy of the quote character each time it is used" do
755
+ csv = DSV.new(%Q{"a","b"\n"c","d"\n})
756
+ quotes = []
757
+ GC.disable
758
+ begin
759
+ ObjectSpace.trace_object_allocations do
760
+ csv.read
761
+ ObjectSpace.each_object(::String){|s| quotes << s if ['"', '""'].include?(s) && ObjectSpace.allocation_sourcefile(s).to_s.end_with?('dsv.rb')}
762
+ end
763
+ ensure
764
+ GC.enable
765
+ end
766
+ _(quotes).must_be_empty
767
+ end
747
768
  end
748
769
 
749
770
  # Input which is not RFC 4180, read to the default rule: a quote is structure only where it opens a field, and a field it opens which does not close raises UnterminatedQuote.
data/test/helper.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'minitest/autorun'
4
4
  require 'minitest/mock'
5
+ require 'objspace'
5
6
  require 'stringio'
6
7
  require 'tmpdir'
7
8
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dsv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.2
4
+ version: 0.16.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - thoran