summaryrefslogtreecommitdiff
path: root/spec/ruby/core/set/shared/inspect.rb
blob: a90af66c980dbf5099519beec33c3111a81cced2 (plain)
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
describe :set_inspect, shared: true do
  it "returns a String representation of self" do
    Set[].send(@method).should be_kind_of(String)
    Set[nil, false, true].send(@method).should be_kind_of(String)
    Set[1, 2, 3].send(@method).should be_kind_of(String)
    Set["1", "2", "3"].send(@method).should be_kind_of(String)
    Set[:a, "b", Set[?c]].send(@method).should be_kind_of(String)
  end

  ruby_version_is "4.0" do
    it "does include the elements of the set" do
      Set["1"].send(@method).should == 'Set["1"]'
    end
  end

  ruby_version_is ""..."4.0" do
    it "does include the elements of the set" do
      Set["1"].send(@method).should == '#<Set: {"1"}>'
    end
  end

  it "puts spaces between the elements" do
    Set["1", "2"].send(@method).should include('", "')
  end

  ruby_version_is "4.0" do
    it "correctly handles cyclic-references" do
      set1 = Set[]
      set2 = Set[set1]
      set1 << set2
      set1.send(@method).should be_kind_of(String)
      set1.send(@method).should include("Set[...]")
    end
  end

  ruby_version_is ""..."4.0" do
    it "correctly handles cyclic-references" do
      set1 = Set[]
      set2 = Set[set1]
      set1 << set2
      set1.send(@method).should be_kind_of(String)
      set1.send(@method).should include("#<Set: {...}>")
    end
  end
end