2017-05-07 12:04:49 +00:00
|
|
|
# -*- encoding: utf-8 -*-
|
2018-03-04 15:09:32 +00:00
|
|
|
require_relative '../../spec_helper'
|
|
|
|
require_relative 'fixtures/classes'
|
2017-05-07 12:04:49 +00:00
|
|
|
|
|
|
|
describe "String#swapcase" do
|
|
|
|
it "returns a new string with all uppercase chars from self converted to lowercase and vice versa" do
|
|
|
|
"Hello".swapcase.should == "hELLO"
|
|
|
|
"cYbEr_PuNk11".swapcase.should == "CyBeR_pUnK11"
|
|
|
|
"+++---111222???".swapcase.should == "+++---111222???"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "taints resulting string when self is tainted" do
|
|
|
|
"".taint.swapcase.tainted?.should == true
|
|
|
|
"hello".taint.swapcase.tainted?.should == true
|
|
|
|
end
|
|
|
|
|
|
|
|
ruby_version_is ''...'2.4' do
|
|
|
|
it "is locale insensitive (only upcases a-z and only downcases A-Z)" do
|
|
|
|
"ÄÖÜ".swapcase.should == "ÄÖÜ"
|
|
|
|
"ärger".swapcase.should == "äRGER"
|
|
|
|
"BÄR".swapcase.should == "bÄr"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-19 08:19:02 +00:00
|
|
|
ruby_version_is '2.4' do
|
|
|
|
it "works for all of Unicode" do
|
|
|
|
"äÖü".swapcase.should == "ÄöÜ"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-07 12:04:49 +00:00
|
|
|
it "returns subclass instances when called on a subclass" do
|
|
|
|
StringSpecs::MyString.new("").swapcase.should be_an_instance_of(StringSpecs::MyString)
|
|
|
|
StringSpecs::MyString.new("hello").swapcase.should be_an_instance_of(StringSpecs::MyString)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "String#swapcase!" do
|
|
|
|
it "modifies self in place" do
|
|
|
|
a = "cYbEr_PuNk11"
|
|
|
|
a.swapcase!.should equal(a)
|
|
|
|
a.should == "CyBeR_pUnK11"
|
|
|
|
end
|
|
|
|
|
2017-10-28 15:15:48 +00:00
|
|
|
ruby_version_is '2.4' do
|
|
|
|
it "modifies self in place for all of Unicode" do
|
|
|
|
a = "äÖü"
|
|
|
|
a.swapcase!.should equal(a)
|
|
|
|
a.should == "ÄöÜ"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-07 12:04:49 +00:00
|
|
|
it "returns nil if no modifications were made" do
|
|
|
|
a = "+++---111222???"
|
|
|
|
a.swapcase!.should == nil
|
|
|
|
a.should == "+++---111222???"
|
|
|
|
|
|
|
|
"".swapcase!.should == nil
|
|
|
|
end
|
|
|
|
|
2017-12-27 16:12:47 +00:00
|
|
|
it "raises a #{frozen_error_class} when self is frozen" do
|
2017-05-07 12:04:49 +00:00
|
|
|
["", "hello"].each do |a|
|
|
|
|
a.freeze
|
2017-12-27 16:12:47 +00:00
|
|
|
lambda { a.swapcase! }.should raise_error(frozen_error_class)
|
2017-05-07 12:04:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|