test/delimited_reader_test.rb in iostreams-0.9.0 vs test/delimited_reader_test.rb in iostreams-0.9.1

- old
+ new

@@ -12,10 +12,44 @@ @data << file.readline.strip end end end + describe '#initialize' do + it 'does not strip invalid characters' do + bad_lines = [ + "New M\xE9xico,NE", + 'good line', + "New M\xE9xico,SF" + ] + input = StringIO.new(bad_lines.join("\n")) + lines = [] + IOStreams::Delimited::Reader.open(input) do |io| + assert_equal false, io.strip_non_printable + assert_raises ArgumentError do + io.each { |line| lines << line } + end + end + end + + it 'strips invalid characters' do + bad_lines = [ + "New M\xE9xico,NE", + 'good line', + "New M\xE9xico,SF" + ] + fixed_lines = bad_lines.collect { |line| line.force_encoding('BINARY').gsub(/[^[:print:]|\r|\n]/, '') } + input = StringIO.new(bad_lines.join("\n")) + lines = [] + IOStreams::Delimited::Reader.open(input, strip_non_printable: true) do |io| + assert_equal true, io.strip_non_printable + io.each { |line| lines << line } + end + assert_equal fixed_lines, lines + end + end + describe '#each' do it 'each_line file' do lines = [] IOStreams::Delimited::Reader.open(@file_name) do |io| io.each { |line| lines << line } @@ -69,10 +103,10 @@ describe '.read' do it 'reads without delimiter' do result = IOStreams::Delimited::Reader.open(@file_name) do |io| io.read end - file = File.read(@file_name) + file = File.read(@file_name) assert_equal file, result end end end