Sha256: 72d331456a88d10c824ddab01bad1ce31c64802bf5784ebf298bcae646b5c551

Contents?: true

Size: 1.39 KB

Versions: 20

Compression:

Stored size: 1.39 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
          skip "Does not raise on JRuby" if defined?(JRuby)
          input = StringIO.new(bad_data)
          IOStreams::Encode::Reader.stream(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.stream(input, encoding: "UTF-8", replace: "", &:read)
          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.stream(input, encoding: "UTF-8", cleaner: :printable, replace: "", &:read)
          assert_equal stripped_data, data
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
iostreams-1.10.3 test/encode_reader_test.rb
iostreams-1.10.2 test/encode_reader_test.rb
iostreams-1.10.1 test/encode_reader_test.rb
iostreams-1.10.0 test/encode_reader_test.rb
iostreams-1.9.0 test/encode_reader_test.rb
iostreams-1.8.0 test/encode_reader_test.rb
iostreams-1.7.0 test/encode_reader_test.rb
iostreams-1.6.2 test/encode_reader_test.rb
iostreams-1.6.1 test/encode_reader_test.rb
iostreams-1.6.0 test/encode_reader_test.rb
iostreams-1.5.1 test/encode_reader_test.rb
iostreams-1.5.0 test/encode_reader_test.rb
iostreams-1.4.0 test/encode_reader_test.rb
iostreams-1.3.3 test/encode_reader_test.rb
iostreams-1.3.2 test/encode_reader_test.rb
iostreams-1.3.1 test/encode_reader_test.rb
iostreams-1.3.0 test/encode_reader_test.rb
iostreams-1.2.1 test/encode_reader_test.rb
iostreams-1.2.0 test/encode_reader_test.rb
iostreams-1.1.1 test/encode_reader_test.rb