2016-02-01 07:43:26 -05:00
|
|
|
# frozen_string_literal: true
|
2013-11-30 18:27:52 -05:00
|
|
|
require 'rubygems/test_case'
|
|
|
|
|
|
|
|
class TestGemSourceLock < Gem::TestCase
|
|
|
|
|
|
|
|
def test_fetch_spec
|
|
|
|
spec_fetcher do |fetcher|
|
|
|
|
fetcher.spec 'a', 1
|
|
|
|
end
|
|
|
|
|
|
|
|
name_tuple = Gem::NameTuple.new 'a', v(1), 'ruby'
|
|
|
|
|
|
|
|
remote = Gem::Source.new @gem_repo
|
|
|
|
lock = Gem::Source::Lock.new remote
|
|
|
|
|
|
|
|
spec = lock.fetch_spec name_tuple
|
|
|
|
|
|
|
|
assert_equal 'a-1', spec.full_name
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_equals2
|
|
|
|
git = Gem::Source::Git.new 'a', 'git/a', 'master', false
|
|
|
|
g_lock = Gem::Source::Lock.new git
|
|
|
|
|
|
|
|
installed = Gem::Source::Installed.new
|
|
|
|
i_lock = Gem::Source::Lock.new installed
|
|
|
|
|
|
|
|
assert_equal g_lock, g_lock
|
|
|
|
refute_equal g_lock, i_lock
|
|
|
|
refute_equal g_lock, Object.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_spaceship
|
|
|
|
git = Gem::Source::Git.new 'a', 'git/a', 'master', false
|
|
|
|
g_lock = Gem::Source::Lock.new git
|
|
|
|
|
|
|
|
installed = Gem::Source::Installed.new
|
|
|
|
i_lock = Gem::Source::Lock.new installed
|
|
|
|
|
|
|
|
vendor = Gem::Source::Vendor.new 'vendor/a'
|
|
|
|
v_lock = Gem::Source::Lock.new vendor
|
|
|
|
|
2019-02-14 07:59:03 -05:00
|
|
|
assert_equal(0, g_lock.<=>(g_lock), 'g_lock <=> g_lock')
|
|
|
|
assert_equal(0, i_lock.<=>(i_lock), 'i_lock <=> i_lock')
|
|
|
|
assert_equal(0, v_lock.<=>(v_lock), 'v_lock <=> v_lock')
|
2013-11-30 18:27:52 -05:00
|
|
|
|
2019-02-14 07:59:03 -05:00
|
|
|
assert_equal(1, g_lock.<=>(i_lock), 'g_lock <=> i_lock')
|
2014-09-13 23:30:02 -04:00
|
|
|
assert_equal(-1, i_lock.<=>(g_lock), 'i_lock <=> g_lock')
|
2013-11-30 18:27:52 -05:00
|
|
|
|
|
|
|
assert_equal(-1, g_lock.<=>(v_lock), 'g_lock <=> v_lock')
|
2019-02-14 07:59:03 -05:00
|
|
|
assert_equal(1, v_lock.<=>(g_lock), 'v_lock <=> g_lock')
|
2013-11-30 18:27:52 -05:00
|
|
|
|
|
|
|
assert_equal(-1, i_lock.<=>(v_lock), 'i_lock <=> v_lock')
|
2019-02-14 07:59:03 -05:00
|
|
|
assert_equal(1, v_lock.<=>(i_lock), 'i_lock <=> v_lock')
|
2013-11-30 18:27:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_spaceship_git
|
|
|
|
git = Gem::Source::Git.new 'a', 'git/a', 'master', false
|
|
|
|
lock = Gem::Source::Lock.new git
|
|
|
|
|
2019-02-14 07:59:03 -05:00
|
|
|
assert_equal(1, lock.<=>(git), 'lock <=> git')
|
2020-03-27 08:49:55 -04:00
|
|
|
assert_equal(-1, git.<=>(lock), 'git <=> lock')
|
2013-11-30 18:27:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_spaceship_installed
|
|
|
|
installed = Gem::Source::Installed.new
|
|
|
|
lock = Gem::Source::Lock.new installed
|
|
|
|
|
2019-05-03 13:56:58 -04:00
|
|
|
assert_equal(1, lock.<=>(installed), 'lock <=> installed')
|
|
|
|
assert_equal(-1, installed.<=>(lock), 'installed <=> lock')
|
2013-11-30 18:27:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_spaceship_local
|
|
|
|
local = Gem::Source::Local.new
|
|
|
|
lock = Gem::Source::Lock.new local # nonsense
|
|
|
|
|
2020-03-27 08:49:55 -04:00
|
|
|
assert_equal(1, lock.<=>(local), 'lock <=> local')
|
2019-05-03 13:56:58 -04:00
|
|
|
assert_equal(-1, local.<=>(lock), 'local <=> lock')
|
2013-11-30 18:27:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_spaceship_remote
|
|
|
|
remote = Gem::Source.new @gem_repo
|
|
|
|
lock = Gem::Source::Lock.new remote
|
|
|
|
|
2020-03-27 08:49:55 -04:00
|
|
|
assert_equal(1, lock.<=>(remote), 'lock <=> remote')
|
2019-05-03 13:56:58 -04:00
|
|
|
assert_equal(-1, remote.<=>(lock), 'remote <=> lock')
|
2013-11-30 18:27:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_spaceship_specific_file
|
|
|
|
_, gem = util_gem 'a', 1
|
|
|
|
|
|
|
|
specific = Gem::Source::SpecificFile.new gem
|
|
|
|
lock = Gem::Source::Lock.new specific # nonsense
|
|
|
|
|
2019-05-03 13:56:58 -04:00
|
|
|
assert_equal(1, lock.<=>(specific), 'lock <=> specific')
|
2013-11-30 18:27:52 -05:00
|
|
|
assert_equal(-1, specific.<=>(lock), 'specific <=> lock')
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_spaceship_vendor
|
|
|
|
vendor = Gem::Source::Vendor.new 'vendor/a'
|
|
|
|
lock = Gem::Source::Lock.new vendor
|
|
|
|
|
2020-03-27 08:49:55 -04:00
|
|
|
assert_equal(1, lock.<=>(vendor), 'lock <=> vendor')
|
2019-05-03 13:56:58 -04:00
|
|
|
assert_equal(-1, vendor.<=>(lock), 'vendor <=> lock')
|
2013-11-30 18:27:52 -05:00
|
|
|
end
|
|
|
|
|
2013-12-07 20:22:39 -05:00
|
|
|
def test_uri
|
|
|
|
remote = Gem::Source.new @gem_repo
|
|
|
|
lock = Gem::Source::Lock.new remote
|
|
|
|
|
|
|
|
assert_equal URI(@gem_repo), lock.uri
|
|
|
|
end
|
|
|
|
|
2013-11-30 18:27:52 -05:00
|
|
|
end
|