Sha256: 29c05eed2edba230caecf7c5e8aae452d5ba6f0110d0c054e56cc9a1a6d2af42

Contents?: true

Size: 1.3 KB

Versions: 6

Compression:

Stored size: 1.3 KB

Contents

require File.expand_path('../helper', __FILE__)

class CharsetTest < Test::Unit::TestCase
  C = Rack::Accept::Charset

  def test_qvalue
    c = C.new('')
    assert_equal(0, c.qvalue('unicode-1-1'))
    assert_equal(1, c.qvalue('iso-8859-1'))

    c = C.new('unicode-1-1')
    assert_equal(1, c.qvalue('unicode-1-1'))
    assert_equal(0, c.qvalue('iso-8859-5'))
    assert_equal(1, c.qvalue('iso-8859-1'))

    c = C.new('unicode-1-1, *;q=0.5')
    assert_equal(1, c.qvalue('unicode-1-1'))
    assert_equal(0.5, c.qvalue('iso-8859-5'))
    assert_equal(0.5, c.qvalue('iso-8859-1'))

    c = C.new('iso-8859-1;q=0, *;q=0.5')
    assert_equal(0.5, c.qvalue('iso-8859-5'))
    assert_equal(0, c.qvalue('iso-8859-1'))

    c = C.new('*;q=0')
    assert_equal(0, c.qvalue('iso-8859-1'))
  end

  def test_matches
    c = C.new('iso-8859-1, iso-8859-5, *')
    assert_equal(%w{*}, c.matches(''))
    assert_equal(%w{iso-8859-1 *}, c.matches('iso-8859-1'))
    assert_equal(%w{*}, c.matches('unicode-1-1'))
  end

  def test_best_of
    c = C.new('iso-8859-5, unicode-1-1;q=0.8')
    assert_equal('iso-8859-5', c.best_of(%w< iso-8859-5 unicode-1-1 >))
    assert_equal('iso-8859-5', c.best_of(%w< iso-8859-5 utf-8 >))
    assert_equal('iso-8859-1', c.best_of(%w< iso-8859-1 utf-8 >))
    assert_equal(nil, c.best_of(%w< utf-8 >))
  end
end

Version data entries

6 entries across 6 versions & 3 rubygems

Version Path
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/rack-accept-0.4.5/test/charset_test.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/rack-accept-0.4.5/test/charset_test.rb
fragrant-0.0.5 vendor/bundle/ruby/1.9.1/gems/rack-accept-0.4.5/test/charset_test.rb
rack-accept-0.4.5 test/charset_test.rb
rack-accept-0.4.4 test/charset_test.rb
rack-accept-0.4.3 test/charset_test.rb