Sha256: 5c545bcb0b8a5128eb2434c5bacfe12759210f645b163c0b3b91a0f426be4927

Contents?: true

Size: 1.38 KB

Versions: 17

Compression:

Stored size: 1.38 KB

Contents

require "test_helper"
require "public_suffix"

# This test runs against the current PSL file and ensures
# the definitions satisfies the test suite.
class PslTest < Minitest::Test

  ROOT = File.expand_path("..", __dir__)

  # rubocop:disable Security/Eval
  def self.tests
    File.readlines(File.join(ROOT, "test/tests.txt")).map do |line|
      line = line.strip
      next if line.empty?
      next if line.start_with?("//")
      input, output = line.split(", ")

      # handle the case of eval("null"), it must be eval("nil")
      input  = "nil" if input  == "null"
      output = "nil" if output == "null"

      input  = eval(input)
      output = eval(output)
      [input, output]
    end
  end
  # rubocop:enable Security/Eval


  def test_valid
    # Parse the PSL and run the tests
    data = File.read(PublicSuffix::List::DEFAULT_LIST_PATH)
    PublicSuffix::List.default = PublicSuffix::List.parse(data)

    failures = []
    self.class.tests.each do |input, output|
      # Punycode domains are not supported ATM
      next if input =~ /xn\-\-/

      domain = PublicSuffix.domain(input) rescue nil
      failures << [input, output, domain] if output != domain
    end

    message = "The following #{failures.size} tests fail:\n"
    failures.each { |i, o, d| message += "Expected %s to be %s, got %s\n" % [i.inspect, o.inspect, d.inspect] }
    assert_equal 0, failures.size, message
  end

end

Version data entries

17 entries across 15 versions & 6 rubygems

Version Path
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/public_suffix-3.0.3/test/psl_test.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.5.0/gems/public_suffix-3.0.3/test/psl_test.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.6.0/gems/public_suffix-3.0.3/test/psl_test.rb
dadapush_client-1.0.1 vendor/bundle/ruby/2.3.0/gems/public_suffix-3.0.3/test/psl_test.rb
cocoapods-dependency-html-0.0.2 vendor/bundle/gems/public_suffix-3.0.3/test/psl_test.rb
cocoapods-dependency-html-0.0.1 vendor/bundle/gems/public_suffix-3.0.3/test/psl_test.rb
tdiary-5.0.13 vendor/bundle/gems/public_suffix-3.0.3/test/psl_test.rb
tdiary-5.0.12.1 vendor/bundle/gems/public_suffix-3.0.3/test/psl_test.rb
vagrant-unbundled-2.2.4.0 vendor/bundle/ruby/2.5.0/gems/public_suffix-3.0.3/test/psl_test.rb
vagrant-unbundled-2.2.4.0 vendor/bundle/ruby/2.6.0/gems/public_suffix-3.0.3/test/psl_test.rb
vagrant-unbundled-2.2.3.0 vendor/bundle/ruby/2.5.0/gems/public_suffix-3.0.3/test/psl_test.rb
tdiary-5.0.11 vendor/bundle/gems/public_suffix-3.0.3/test/psl_test.rb
vagrant-unbundled-2.2.2.0 vendor/bundle/ruby/2.5.0/gems/public_suffix-3.0.3/test/psl_test.rb
vagrant-unbundled-2.2.0.0 vendor/bundle/ruby/2.5.0/gems/public_suffix-3.0.3/test/psl_test.rb
vagrant-unbundled-2.1.4.0 vendor/bundle/ruby/2.5.0/gems/public_suffix-3.0.3/test/psl_test.rb
vagrant-unbundled-2.1.2.0 vendor/bundle/ruby/2.3.0/gems/public_suffix-3.0.3/test/psl_test.rb
public_suffix-3.0.3 test/psl_test.rb