summaryrefslogtreecommitdiff
path: root/spec/ruby/core/string/strip_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/string/strip_spec.rb')
-rw-r--r--spec/ruby/core/string/strip_spec.rb58
1 files changed, 58 insertions, 0 deletions
diff --git a/spec/ruby/core/string/strip_spec.rb b/spec/ruby/core/string/strip_spec.rb
new file mode 100644
index 0000000000..81994a7f2e
--- /dev/null
+++ b/spec/ruby/core/string/strip_spec.rb
@@ -0,0 +1,58 @@
+# frozen_string_literal: false
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+require_relative 'shared/strip'
+
+describe "String#strip" do
+ it_behaves_like :string_strip, :strip
+
+ it "returns a new string with leading and trailing whitespace removed" do
+ " hello ".strip.should == "hello"
+ " hello world ".strip.should == "hello world"
+ "\tgoodbye\r\v\n".strip.should == "goodbye"
+ end
+
+ it "returns a copy of self without leading and trailing NULL bytes and whitespace" do
+ " \x00 goodbye \x00 ".strip.should == "goodbye"
+ end
+end
+
+describe "String#strip!" do
+ it "modifies self in place and returns self" do
+ a = " hello "
+ a.strip!.should.equal?(a)
+ a.should == "hello"
+
+ a = "\tgoodbye\r\v\n"
+ a.strip!
+ a.should == "goodbye"
+ end
+
+ it "returns nil if no modifications where made" do
+ a = "hello"
+ a.strip!.should == nil
+ a.should == "hello"
+ end
+
+ it "makes a string empty if it is only whitespace" do
+ "".strip!.should == nil
+ " ".strip.should == ""
+ " ".strip.should == ""
+ end
+
+ it "removes leading and trailing NULL bytes and whitespace" do
+ a = "\000 goodbye \000"
+ a.strip!
+ a.should == "goodbye"
+ end
+
+ it "raises a FrozenError on a frozen instance that is modified" do
+ -> { " hello ".freeze.strip! }.should.raise(FrozenError)
+ end
+
+ # see #1552
+ it "raises a FrozenError on a frozen instance that would not be modified" do
+ -> {"hello".freeze.strip! }.should.raise(FrozenError)
+ -> {"".freeze.strip! }.should.raise(FrozenError)
+ end
+end
spec/spec?id=31bb66a19df26409c9d47afcf37919c9a065516a'>Update to ruby/mspec@8106083Benoit Daloze 2019-04-28Update to ruby/mspec@c25d63dBenoit Daloze 2019-02-07Update to ruby/mspec@231e2ceeregon 2019-01-20Update to ruby/mspec@e9a482deregon 2018-10-27Update to ruby/mspec@4729971eregon 2018-09-25Update to ruby/mspec@2bca8cberegon 2018-09-25Update to ruby/mspec@3fb5112eregon 2018-08-03Update to ruby/mspec@072849eeregon 2018-06-27Update to ruby/mspec@7074b56eregon 2018-03-26Update to ruby/mspec@8b54bf3eregon 2018-01-29Update to ruby/mspec@5d49a6ceregon 2017-12-01Update to ruby/mspec@b501adeeregon 2017-10-28Update to ruby/mspec@90925d6eregon 2017-09-14Update to ruby/mspec@5bd9409eregon 2017-07-27Update to ruby/mspec@353605feregon 2017-06-29Update to ruby/mspec@021a119eregon 2017-06-15Update to ruby/mspec@d900a49eregon 2017-05-29Simplify, avoid extra exceptions and add test for concurrent mspec mkdir_peregon 2017-05-27Update to ruby/mspec@6c95759eregon 2017-05-14Update to ruby/mspec@4b980493eregon 2017-05-07* remove trailing spaces, append newline at EOF.svn 2017-05-07Add in-tree mspec and ruby/speceregon