Sha256: 3c8e4588aa70e3ea8600dec33929967b2cb2f0b488aa206bf66a82b4e91707a3

Contents?: true

Size: 1.27 KB

Versions: 4

Compression:

Stored size: 1.27 KB

Contents

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

class LanguageTest < Test::Unit::TestCase
  L = Rack::Accept::Language

  def test_qvalue
    l = L.new('')
    assert_equal(1, l.qvalue('en'))

    l = L.new('en;q=0.5, en-gb')
    assert_equal(0.5, l.qvalue('en'))
    assert_equal(1, l.qvalue('en-gb'))
    assert_equal(0, l.qvalue('da'))
  end

  def test_matches
    l = L.new('da, *, en')
    assert_equal(%w{*}, l.matches(''))
    assert_equal(%w{da *}, l.matches('da'))
    assert_equal(%w{en *}, l.matches('en'))
    assert_equal(%w{en *}, l.matches('en-gb'))
    assert_equal(%w{*}, l.matches('eng'))

    l = L.new('en, en-gb')
    assert_equal(%w{en-gb en}, l.matches('en-gb'))
  end

  def test_best_of
    l = L.new('en;q=0.5, en-gb')
    assert_equal('en-gb', l.best_of(%w< en en-gb >))
    assert_equal('en', l.best_of(%w< en da >))
    assert_equal('en-us', l.best_of(%w< en-us en-au >))
    assert_equal(nil, l.best_of(%w< da >))

    l = L.new('en;q=0.5, en-GB, fr-CA')
    assert_equal('en-gb', l.best_of(%w< en en-gb >))

    l = L.new('en-gb;q=0.5, EN, fr-CA')
    assert_equal('en', l.best_of(%w< en en-gb >))

    l = L.new('en;q=0.5, fr-ca')
    assert_equal('en', l.best_of(%w< en fr >))

    l.first_level_match = true
    assert_equal('fr', l.best_of(%w< en fr >))
  end
end

Version data entries

4 entries across 4 versions & 3 rubygems

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