Sha256: 3e17b1dae235fc6a1446c03bfaf59472ca3f458cf62380eacda1a6af0cb5049e

Contents?: true

Size: 1.3 KB

Versions: 1

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

require "minitest/autorun"
require "deblank"


describe Deblank::Optionparser do

  before do
    @parser = Deblank::Optionparser
    @arg = "test_รค.txt"
    @arg_win1252_labeled_as_cp850 = (+"test_\xE4.txt").force_encoding("CP850")
    @arg_win1252 = (+"test_\xE4.txt").force_encoding("Windows-1252")
  end

  it "can correct encoding from (seemingly) CP850 to Windows-1252" do
    arg = @arg_win1252_labeled_as_cp850
    _(arg.encoding).must_equal Encoding::CP850
    corrected_arg = @parser.correct_encoding(arg)
    _(corrected_arg.encoding).must_equal Encoding::Windows_1252
  end

  it "encodes (seemingly) CP850 encoded filenames into UTF-8" do
    options = @parser.parse!([@arg_win1252_labeled_as_cp850])
    filename = options[:files].first
    _(filename.encoding).must_equal Encoding::UTF_8
    _(filename).must_equal @arg
  end

  it "encodes Windows-1252 encoded filenames into UTF-8" do
    options = @parser.parse!([@arg_win1252])
    filename = options[:files].first
    _(filename.encoding).must_equal Encoding::UTF_8
    _(filename).must_equal @arg
  end

  it "encodes UTF-8 encoded filenames into UTF-8" do
    options = @parser.parse!([@arg])
    filename = options[:files].first
    _(filename.encoding).must_equal Encoding::UTF_8
    _(filename).must_equal @arg
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
deblank-0.2.0 test/test_optionparser.rb