Sha256: 60d202505711b1d4ec2ca81f95a952f417f6858573c084882e738eaf3b5aa1d1

Contents?: true

Size: 1.06 KB

Versions: 4

Compression:

Stored size: 1.06 KB

Contents

require 'test_helper'

class AcceptanceTest < Test::Unit::TestCase

  ValidCases = {
    "google.com" => [nil, "google", "com"],
    "foo.google.com" => ["foo", "google", "com"],

    "verybritish.co.uk" => [nil, "verybritish", "co.uk"],
    "foo.verybritish.co.uk" => ["foo", "verybritish", "co.uk"],

    "parliament.uk" => [nil, "parliament", "uk"],
    "foo.parliament.uk" => ["foo", "parliament", "uk"],
  }

  def test_valid
    ValidCases.each do |name, results|
      domain = PublicSuffix.parse(name)
      trd, sld, tld = results
      assert_equal tld, domain.tld, "Invalid tld for '#{name}'"
      assert_equal sld, domain.sld, "Invalid sld for '#{name}'"
      assert_equal trd, domain.trd, "Invalid trd for '#{name}'"
      assert PublicSuffix.valid?(name)
    end
  end

  InvalidCases = {
    "nic.ke" => PublicSuffix::DomainNotAllowed,
    "http://www.google.com" => PublicSuffix::DomainInvalid,
  }

  def test_invalid
    InvalidCases.each do |name, error|
      assert_raise(error) { PublicSuffix.parse(name) }
      assert !PublicSuffix.valid?(name)
    end
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
public_suffix-1.1.3 test/acceptance_test.rb
public_suffix-1.1.2 test/acceptance_test.rb
public_suffix-1.1.1 test/acceptance_test.rb
public_suffix-1.1.0 test/acceptance_test.rb