Sha256: d06f94f0a447685441c8369d2b41c3395319b53c9c7a5a5ea56d4b9de334a860

Contents?: true

Size: 1.87 KB

Versions: 15

Compression:

Stored size: 1.87 KB

Contents

# encoding: UTF-8
require_relative "./test_helper"

class HTMLEntities::StringEncodingsTest < Test::Unit::TestCase

  def test_should_encode_ascii_to_ascii
    s = "<elan>".encode(Encoding::US_ASCII)
    assert_equal Encoding::US_ASCII, s.encoding

    t = HTMLEntities.new.encode(s)
    assert_equal "&lt;elan&gt;", t
    assert_equal Encoding::US_ASCII, t.encoding
  end

  def test_should_encode_utf8_to_utf8_if_needed
    s = "<élan>"
    assert_equal Encoding::UTF_8, s.encoding

    t = HTMLEntities.new.encode(s)
    assert_equal "&lt;élan&gt;", t
    assert_equal Encoding::UTF_8, t.encoding
  end

  def test_should_encode_utf8_to_ascii_if_possible
    s = "<elan>"
    assert_equal Encoding::UTF_8, s.encoding

    t = HTMLEntities.new.encode(s)
    assert_equal "&lt;elan&gt;", t
    assert_equal Encoding::US_ASCII, t.encoding
  end

  def test_should_encode_other_encoding_to_utf8
    s = "<élan>".encode(Encoding::ISO_8859_1)
    assert_equal Encoding::ISO_8859_1, s.encoding

    t = HTMLEntities.new.encode(s)
    assert_equal "&lt;élan&gt;", t
    assert_equal Encoding::UTF_8, t.encoding
  end

  def test_should_decode_ascii_to_utf8
    s = "&lt;&eacute;lan&gt;".encode(Encoding::US_ASCII)
    assert_equal Encoding::US_ASCII, s.encoding

    t = HTMLEntities.new.decode(s)
    assert_equal "<élan>", t
    assert_equal Encoding::UTF_8, t.encoding
  end

  def test_should_decode_utf8_to_utf8
    s = "&lt;&eacute;lan&gt;".encode(Encoding::UTF_8)
    assert_equal Encoding::UTF_8, s.encoding

    t = HTMLEntities.new.decode(s)
    assert_equal "<élan>", t
    assert_equal Encoding::UTF_8, t.encoding
  end

  def test_should_decode_other_encoding_to_utf8
    s = "&lt;&eacute;lan&gt;".encode(Encoding::ISO_8859_1)
    assert_equal Encoding::ISO_8859_1, s.encoding

    t = HTMLEntities.new.decode(s)
    assert_equal "<élan>", t
    assert_equal Encoding::UTF_8, t.encoding
  end
end

Version data entries

15 entries across 15 versions & 8 rubygems

Version Path
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/htmlentities-4.3.4/test/string_encodings_test.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/htmlentities-4.3.4/test/string_encodings_test.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/htmlentities-4.3.4/test/string_encodings_test.rb
metanorma-cli-1.3.4 gems/ruby/2.6.0/gems/htmlentities-4.3.4/test/string_encodings_test.rb
metanorma-cli-1.3.3.1 gems/ruby/2.6.0/gems/htmlentities-4.3.4/test/string_encodings_test.rb
jerska-htmlentities-4.3.3 test/string_encodings_test.rb
logstash-filter-htmlentities-0.1.0 vendor/bundle/jruby/1.9/gems/htmlentities-4.3.4/test/string_encodings_test.rb
megam_htmlentities-4.3.4 test/string_encodings_test.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/htmlentities-4.3.4/test/string_encodings_test.rb
solidus_backend-1.0.0.pre3 vendor/bundle/gems/htmlentities-4.3.4/test/string_encodings_test.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/htmlentities-4.3.4/test/string_encodings_test.rb
htmlentities-4.3.4 test/string_encodings_test.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/htmlentities-4.3.3/test/string_encodings_test.rb
htmlentities-4.3.3 test/string_encodings_test.rb
htmlentities-4.3.2 test/string_encodings_test.rb