Sha256: db19e6378abfc12443f4ce2565f4e3cf20224aebca98caf3505e9f5170ca73f9

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
require 'wurfl/user_agent_matcher'
require 'wurfl/loader'
require 'test/unit'

class UserAgentMatcherTest < Test::Unit::TestCase
  def setup
    loader = Wurfl::Loader.new
    handsets, fallbacks = loader.load_wurfl(File.join(File.dirname(__FILE__), "data", "wurfl.simple.xml"))
    @matcher = Wurfl::UserAgentMatcher.new(handsets)
  end

  def test_empty_user_agent
    a, shortest_distance = @matcher.match_handsets("")
    assert_equal 1, a.size
    assert_equal "generic_xhtml", a.first.wurfl_id
    assert_equal 4, shortest_distance
  end

  def test_matching_user_agent
    a, shortest_distance = @matcher.match_handsets("generic")
    assert_equal 1, a.size
    assert_equal "generic", a.first.wurfl_id
    assert_equal 0, shortest_distance
  end

  def test_iphone
    s = "Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en)"
    a, shortest_distance = @matcher.match_handsets(s)
    assert_equal 1, a.size
    assert_equal "apple_generic", a.first.wurfl_id
    assert_equal 26, shortest_distance
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
wurfl-1.2.0 test/user_agent_matcher_test.rb