Sha256: b580fd58a04a649d0a90b0ce2fe8212872c175f80da8316d4d6f67d27627c185

Contents?: true

Size: 1.42 KB

Versions: 12

Compression:

Stored size: 1.42 KB

Contents

require_relative 'test_helper'

class EncodeReaderTest < Minitest::Test
  describe IOStreams::Encode::Reader do
    let :bad_data do
      [
        "New M\xE9xico,NE".b,
        'good line',
        "New M\xE9xico,\x07SF".b
      ].join("\n").encode('BINARY')
    end

    let :cleansed_data do
      bad_data.gsub("\xE9".b, '')
    end

    let :stripped_data do
      cleansed_data.gsub("\x07", '')
    end

    describe '#read' do
      describe 'replacement' do
        it 'does not strip invalid characters' do
          input = StringIO.new(bad_data)
          IOStreams::Encode::Reader.open(input, encoding: 'UTF-8') do |io|
            assert_raises ::Encoding::UndefinedConversionError do
              io.read.encoding
            end
          end
        end

        it 'strips invalid characters' do
          input = StringIO.new(bad_data)
          data  =
            IOStreams::Encode::Reader.open(input, encoding: 'UTF-8', encode_replace: '') do |io|
              io.read
            end
          assert_equal cleansed_data, data
        end
      end

      describe 'printable' do
        it 'strips non-printable characters' do
          input = StringIO.new(bad_data)
          data  =
            IOStreams::Encode::Reader.open(input, encoding: 'UTF-8', encode_cleaner: :printable, encode_replace: '') do |io|
              io.read
            end
          assert_equal stripped_data, data
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
iostreams-0.20.3 test/encode_reader_test.rb
iostreams-0.20.2 test/encode_reader_test.rb
iostreams-0.20.1 test/encode_reader_test.rb
iostreams-0.20.0 test/encode_reader_test.rb
iostreams-0.19.0 test/encode_reader_test.rb
iostreams-0.18.0 test/encode_reader_test.rb
iostreams-0.17.3 test/encode_reader_test.rb
iostreams-0.17.2 test/encode_reader_test.rb
iostreams-0.17.1 test/encode_reader_test.rb
iostreams-0.17.0 test/encode_reader_test.rb
iostreams-0.16.2 test/encode_reader_test.rb
iostreams-0.16.1 test/encode_reader_test.rb