File: domain_test.rb

package info (click to toggle)
ruby-public-suffix 3.0.3%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 284 kB
  • sloc: ruby: 1,431; makefile: 22
file content (104 lines) | stat: -rw-r--r-- 3,305 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
require "test_helper"

class PublicSuffix::DomainTest < Minitest::Test

  def setup
    @klass = PublicSuffix::Domain
  end

  # Tokenizes given input into labels.
  def test_self_name_to_labels
    assert_equal  %w( someone spaces live com ),
                  PublicSuffix::Domain.name_to_labels("someone.spaces.live.com")
    assert_equal  %w( leontina23samiko wiki zoho com ),
                  PublicSuffix::Domain.name_to_labels("leontina23samiko.wiki.zoho.com")
  end

  # Converts input into String.
  def test_self_name_to_labels_converts_input_to_string
    assert_equal  %w( someone spaces live com ),
                  PublicSuffix::Domain.name_to_labels(:"someone.spaces.live.com")
  end


  def test_initialize_with_tld
    domain = @klass.new("com")
    assert_equal "com", domain.tld
    assert_nil domain.sld
    assert_nil domain.trd
  end

  def test_initialize_with_tld_and_sld
    domain = @klass.new("com", "google")
    assert_equal "com", domain.tld
    assert_equal "google", domain.sld
    assert_nil domain.trd
  end

  def test_initialize_with_tld_and_sld_and_trd
    domain = @klass.new("com", "google", "www")
    assert_equal "com", domain.tld
    assert_equal "google", domain.sld
    assert_equal "www", domain.trd
  end


  def test_to_s
    assert_equal "com",             @klass.new("com").to_s
    assert_equal "google.com",      @klass.new("com", "google").to_s
    assert_equal "www.google.com",  @klass.new("com", "google", "www").to_s
  end

  def test_to_a
    assert_equal [nil, nil, "com"],         @klass.new("com").to_a
    assert_equal [nil, "google", "com"],    @klass.new("com", "google").to_a
    assert_equal ["www", "google", "com"],  @klass.new("com", "google", "www").to_a
  end


  def test_tld
    assert_equal "com", @klass.new("com", "google", "www").tld
  end

  def test_sld
    assert_equal "google", @klass.new("com", "google", "www").sld
  end

  def test_trd
    assert_equal "www", @klass.new("com", "google", "www").trd
  end


  def test_name
    assert_equal "com",             @klass.new("com").name
    assert_equal "google.com",      @klass.new("com", "google").name
    assert_equal "www.google.com",  @klass.new("com", "google", "www").name
  end

  def test_domain
    assert_nil @klass.new("com").domain
    assert_nil @klass.new("tldnotlisted").domain
    assert_equal "google.com", @klass.new("com", "google").domain
    assert_equal "google.tldnotlisted", @klass.new("tldnotlisted", "google").domain
    assert_equal "google.com", @klass.new("com", "google", "www").domain
    assert_equal "google.tldnotlisted", @klass.new("tldnotlisted", "google", "www").domain
  end

  def test_subdomain
    assert_nil @klass.new("com").subdomain
    assert_nil @klass.new("tldnotlisted").subdomain
    assert_nil @klass.new("com", "google").subdomain
    assert_nil @klass.new("tldnotlisted", "google").subdomain
    assert_equal "www.google.com", @klass.new("com", "google", "www").subdomain
    assert_equal "www.google.tldnotlisted", @klass.new("tldnotlisted", "google", "www").subdomain
  end


  def test_domain_question
    assert !@klass.new("com").domain?
    assert  @klass.new("com", "example").domain?
    assert  @klass.new("com", "example", "www").domain?
    assert  @klass.new("tldnotlisted", "example").domain?
  end

end