File: test_gem_name_tuple.rb

package info (click to toggle)
ruby3.3 3.3.8-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 153,620 kB
  • sloc: ruby: 1,244,308; ansic: 836,474; yacc: 28,074; pascal: 6,748; sh: 3,913; python: 1,719; cpp: 1,158; makefile: 742; asm: 712; javascript: 394; lisp: 97; perl: 62; awk: 36; sed: 23; xml: 4
file content (60 lines) | stat: -rw-r--r-- 2,040 bytes parent folder | download | duplicates (5)
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
# frozen_string_literal: true

require_relative "helper"
require "rubygems/name_tuple"

class TestGemNameTuple < Gem::TestCase
  def test_full_name
    n = Gem::NameTuple.new "a", Gem::Version.new(0), "ruby"
    assert_equal "a-0", n.full_name

    n = Gem::NameTuple.new "a", Gem::Version.new(0), nil
    assert_equal "a-0", n.full_name

    n = Gem::NameTuple.new "a", Gem::Version.new(0), ""
    assert_equal "a-0", n.full_name

    n = Gem::NameTuple.new "a", Gem::Version.new(0), "other"
    assert_equal "a-0-other", n.full_name
  end

  def test_platform_normalization
    a = Gem::NameTuple.new "a", Gem::Version.new(0), "ruby"
    b = Gem::NameTuple.new "a", Gem::Version.new(0), Gem::Platform::RUBY
    assert_equal a, b
    assert_equal a.hash, b.hash

    a = Gem::NameTuple.new "a", Gem::Version.new(0), nil
    b = Gem::NameTuple.new "a", Gem::Version.new(0), Gem::Platform.new("ruby")
    assert_equal a, b
    assert_equal a.hash, b.hash

    a = Gem::NameTuple.new "a", Gem::Version.new(0), ""
    b = Gem::NameTuple.new "a", Gem::Version.new(0), Gem::Platform.new("ruby")
    assert_equal a, b
    assert_equal a.hash, b.hash

    a = Gem::NameTuple.new "a", Gem::Version.new(0), "universal-darwin-23"
    b = Gem::NameTuple.new "a", Gem::Version.new(0), Gem::Platform.new("universal-darwin-23")
    assert_equal a, b
    assert_equal a.hash, b.hash

    # Gem::Platform does normalization so that these are equal (note the missing dash before 21)
    a = Gem::NameTuple.new "a", Gem::Version.new(0), "universal-darwin-21"
    b = Gem::NameTuple.new "a", Gem::Version.new(0), Gem::Platform.new("universal-darwin21")
    assert_equal a, b
    assert_equal a.hash, b.hash
  end

  def test_spec_name
    n = Gem::NameTuple.new "a", Gem::Version.new(0), "ruby"
    assert_equal "a-0.gemspec", n.spec_name
  end

  def test_spaceship
    a   = Gem::NameTuple.new "a", Gem::Version.new(0), Gem::Platform::RUBY
    a_p = Gem::NameTuple.new "a", Gem::Version.new(0), Gem::Platform.local

    assert_equal 1, a_p.<=>(a)
  end
end