2016-02-01 07:43:26 -05:00
|
|
|
# frozen_string_literal: true
|
2020-07-14 22:21:33 -04:00
|
|
|
require 'rubygems'
|
2012-11-29 01:52:18 -05:00
|
|
|
require 'rubygems/source_list'
|
2021-06-01 23:32:47 -04:00
|
|
|
require_relative 'helper'
|
2012-11-29 01:52:18 -05:00
|
|
|
|
|
|
|
class TestGemSourceList < Gem::TestCase
|
|
|
|
def setup
|
|
|
|
super
|
|
|
|
|
2013-02-27 18:20:57 -05:00
|
|
|
@uri = "http://example"
|
2012-11-29 01:52:18 -05:00
|
|
|
@source = Gem::Source.new(@uri)
|
|
|
|
|
|
|
|
@sl = Gem::SourceList.new
|
|
|
|
@sl << @source
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_self_from
|
|
|
|
sl = Gem::SourceList.from [@uri]
|
|
|
|
|
|
|
|
assert_equal [Gem::Source.new(@uri)], sl.sources
|
|
|
|
end
|
|
|
|
|
2013-11-10 12:51:40 -05:00
|
|
|
def test_Enumerable
|
|
|
|
assert_includes Gem::SourceList.ancestors, Enumerable
|
|
|
|
end
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
def test_append
|
|
|
|
sl = Gem::SourceList.new
|
2016-03-03 19:29:40 -05:00
|
|
|
sl << @uri
|
|
|
|
sl << @uri
|
|
|
|
|
|
|
|
assert_equal sl.to_a.size, 1
|
|
|
|
|
|
|
|
sl.clear
|
2012-11-29 01:52:18 -05:00
|
|
|
source = (sl << @uri)
|
|
|
|
|
|
|
|
assert_kind_of Gem::Source, source
|
|
|
|
|
|
|
|
assert_kind_of URI, source.uri
|
|
|
|
assert_equal source.uri.to_s, @uri
|
|
|
|
|
|
|
|
assert_equal [source], sl.sources
|
|
|
|
end
|
|
|
|
|
2013-11-10 12:51:40 -05:00
|
|
|
def test_clear
|
|
|
|
sl = Gem::SourceList.new
|
|
|
|
|
|
|
|
sl << 'http://source.example'
|
|
|
|
|
|
|
|
sl.clear
|
|
|
|
|
|
|
|
assert_empty sl
|
|
|
|
end
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
def test_replace
|
|
|
|
sl = Gem::SourceList.new
|
|
|
|
sl.replace [@uri]
|
|
|
|
|
|
|
|
assert_equal [@source], sl.sources
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_each
|
|
|
|
@sl.each do |x|
|
|
|
|
assert_equal @uri, x
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_each_source
|
|
|
|
@sl.each_source do |x|
|
|
|
|
assert_equal @source, x
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-11-10 12:51:40 -05:00
|
|
|
def test_empty?
|
|
|
|
sl = Gem::SourceList.new
|
|
|
|
|
|
|
|
assert_empty sl
|
|
|
|
|
|
|
|
sl << 'http://source.example'
|
|
|
|
|
|
|
|
refute_empty sl
|
|
|
|
end
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
def test_equal_to_another_list
|
|
|
|
sl2 = Gem::SourceList.new
|
|
|
|
sl2 << Gem::Source.new(@uri)
|
|
|
|
|
|
|
|
assert @sl == sl2, "lists not equal"
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_equal_to_array
|
|
|
|
assert @sl == [@uri], "lists not equal"
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_to_a
|
|
|
|
assert_equal @sl.to_a, [@uri]
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_include_eh
|
|
|
|
assert @sl.include?(@uri), "string comparison not working"
|
|
|
|
assert @sl.include?(URI.parse(@uri)), "uri comparison not working"
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_include_matches_a_source
|
|
|
|
assert @sl.include?(@source), "source comparison not working"
|
|
|
|
assert @sl.include?(Gem::Source.new(@uri)), "source comparison not working"
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_delete
|
|
|
|
@sl.delete @uri
|
|
|
|
assert_equal @sl.sources, []
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_delete_a_source
|
|
|
|
@sl.delete Gem::Source.new(@uri)
|
|
|
|
assert_equal @sl.sources, []
|
|
|
|
end
|
|
|
|
end
|