Sha256: e11261b3dfb1859065a8f0e9bbe0f539acc738443d2e9149ebf331f106bb178b

Contents?: true

Size: 1.41 KB

Versions: 77

Compression:

Stored size: 1.41 KB

Contents

# frozen_string_literal: true

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

77 entries across 68 versions & 11 rubygems

Version Path
whitelabelmachinename-ruby-sdk-3.2.1 vendor/bundle/ruby/2.4.0/gems/public_suffix-4.0.7/test/psl_test.rb
wallee-ruby-sdk-3.2.0 vendor/bundle/ruby/2.4.0/gems/public_suffix-4.0.7/test/psl_test.rb
postfinancecheckout-ruby-sdk-3.2.0 vendor/bundle/ruby/2.4.0/gems/public_suffix-4.0.7/test/psl_test.rb
wallee-ruby-sdk-3.1.5 vendor/bundle/ruby/2.4.0/gems/public_suffix-4.0.7/test/psl_test.rb
postfinancecheckout-ruby-sdk-3.1.5 vendor/bundle/ruby/2.4.0/gems/public_suffix-4.0.7/test/psl_test.rb
whitelabelmachinename-ruby-sdk-3.2.0 vendor/bundle/ruby/2.4.0/gems/public_suffix-4.0.7/test/psl_test.rb
whitelabelmachinename-ruby-sdk-3.1.9 vendor/bundle/ruby/2.4.0/gems/public_suffix-4.0.7/test/psl_test.rb
whitelabelmachinename-ruby-sdk-3.1.8 vendor/bundle/ruby/2.4.0/gems/public_suffix-4.0.7/test/psl_test.rb
cloudsmith-api-1.120.3 vendor/bundle/ruby/2.6.0/gems/public_suffix-4.0.7/test/psl_test.rb
whitelabelmachinename-ruby-sdk-3.1.7 vendor/bundle/ruby/2.4.0/gems/public_suffix-4.0.7/test/psl_test.rb
whitelabelmachinename-ruby-sdk-3.1.6 vendor/bundle/ruby/2.4.0/gems/public_suffix-4.0.7/test/psl_test.rb
whitelabelmachinename-ruby-sdk-3.1.5 vendor/bundle/ruby/2.4.0/gems/public_suffix-4.0.7/test/psl_test.rb
postfinancecheckout-ruby-sdk-3.1.4 vendor/bundle/ruby/2.4.0/gems/public_suffix-4.0.7/test/psl_test.rb
whitelabelmachinename-ruby-sdk-3.1.4 vendor/bundle/ruby/2.4.0/gems/public_suffix-4.0.7/test/psl_test.rb
wallee-ruby-sdk-3.1.4 vendor/bundle/ruby/2.4.0/gems/public_suffix-4.0.7/test/psl_test.rb
wallee-ruby-sdk-3.1.3 vendor/bundle/ruby/2.4.0/gems/public_suffix-4.0.7/test/psl_test.rb
whitelabelmachinename-ruby-sdk-3.1.3 vendor/bundle/ruby/2.4.0/gems/public_suffix-4.0.7/test/psl_test.rb
whitelabelmachinename-ruby-sdk-3.1.2 vendor/bundle/ruby/2.4.0/gems/public_suffix-4.0.7/test/psl_test.rb
wallee-ruby-sdk-3.1.2 vendor/bundle/ruby/2.4.0/gems/public_suffix-4.0.7/test/psl_test.rb
wallee-ruby-sdk-3.1.1 vendor/bundle/ruby/2.4.0/gems/public_suffix-4.0.7/test/psl_test.rb