[前][次][番号順一覧][スレッド一覧]

ruby-changes:72712

From: Benoit <ko1@a...>
Date: Thu, 28 Jul 2022 00:24:13 +0900 (JST)
Subject: [ruby-changes:72712] 6582df26dc (master): Update to ruby/spec@cbfaf51

https://git.ruby-lang.org/ruby.git/commit/?id=6582df26dc

From 6582df26dcdef5dab01242b4d97d9b242e959860 Mon Sep 17 00:00:00 2001
From: Benoit Daloze <eregontp@g...>
Date: Wed, 27 Jul 2022 17:18:25 +0200
Subject: Update to ruby/spec@cbfaf51

---
 spec/ruby/core/enumerable/compact_spec.rb          | 11 +++
 spec/ruby/core/enumerator/lazy/lazy_spec.rb        | 14 ++++
 spec/ruby/core/file/shared/fnmatch.rb              |  8 +--
 spec/ruby/core/range/clone_spec.rb                 | 26 +++++++
 spec/ruby/core/range/dup_spec.rb                   |  4 +-
 spec/ruby/core/range/new_spec.rb                   | 10 +++
 spec/ruby/core/regexp/shared/quote.rb              |  5 ++
 spec/ruby/core/regexp/source_spec.rb               | 22 +++++-
 spec/ruby/core/string/capitalize_spec.rb           |  3 +-
 spec/ruby/core/string/delete_prefix_spec.rb        |  4 ++
 spec/ruby/core/string/delete_suffix_spec.rb        |  4 ++
 spec/ruby/core/string/downcase_spec.rb             |  4 ++
 spec/ruby/core/string/encoding_spec.rb             |  1 +
 .../core/string/fixtures/iso-8859-9-encoding.rb    |  2 +-
 spec/ruby/core/string/include_spec.rb              | 14 ++++
 spec/ruby/core/string/inspect_spec.rb              | 20 ++++++
 spec/ruby/core/string/lstrip_spec.rb               | 34 ++++++---
 spec/ruby/core/string/ord_spec.rb                  |  5 ++
 spec/ruby/core/string/reverse_spec.rb              | 17 +++++
 spec/ruby/core/string/rstrip_spec.rb               | 28 +++++++-
 spec/ruby/core/string/setbyte_spec.rb              |  6 ++
 spec/ruby/core/string/shared/dedup.rb              | 10 +++
 spec/ruby/core/string/split_spec.rb                | 16 +++++
 spec/ruby/core/string/start_with_spec.rb           | 10 +++
 spec/ruby/core/string/strip_spec.rb                |  6 ++
 spec/ruby/core/string/swapcase_spec.rb             |  4 ++
 spec/ruby/core/string/upcase_spec.rb               |  4 ++
 spec/ruby/language/range_spec.rb                   |  8 +++
 spec/ruby/language/regexp/escapes_spec.rb          | 84 ++++++++++++++++++++--
 spec/ruby/language/regexp_spec.rb                  | 21 ------
 spec/ruby/library/stringio/shared/read.rb          |  6 ++
 spec/ruby/optional/capi/encoding_spec.rb           | 15 ++--
 spec/ruby/optional/capi/ext/encoding_spec.c        |  7 +-
 spec/ruby/shared/file/executable.rb                | 35 +++++++++
 spec/ruby/shared/file/executable_real.rb           | 35 +++++++++
 spec/ruby/shared/file/readable.rb                  | 16 +++++
 spec/ruby/shared/file/readable_real.rb             | 16 +++++
 spec/ruby/shared/file/writable.rb                  | 16 +++++
 spec/ruby/shared/file/writable_real.rb             | 16 +++++
 spec/ruby/shared/string/end_with.rb                |  9 ++-
 spec/ruby/shared/string/start_with.rb              |  4 ++
 41 files changed, 526 insertions(+), 54 deletions(-)
 create mode 100644 spec/ruby/core/enumerable/compact_spec.rb
 create mode 100644 spec/ruby/core/range/clone_spec.rb

diff --git a/spec/ruby/core/enumerable/compact_spec.rb b/spec/ruby/core/enumerable/compact_spec.rb
new file mode 100644
index 0000000000..86e95dce08
--- /dev/null
+++ b/spec/ruby/core/enumerable/compact_spec.rb
@@ -0,0 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/enumerable/compact_spec.rb#L1
+require_relative '../../spec_helper'
+require_relative 'fixtures/classes'
+
+ruby_version_is '3.1' do
+  describe "Enumerable#compact" do
+    it 'returns array without nil elements' do
+      arr = EnumerableSpecs::Numerous.new(nil, 1, 2, nil, true)
+      arr.compact.should == [1, 2, true]
+    end
+  end
+end
diff --git a/spec/ruby/core/enumerator/lazy/lazy_spec.rb b/spec/ruby/core/enumerator/lazy/lazy_spec.rb
index cde9b31066..683dfb81d7 100644
--- a/spec/ruby/core/enumerator/lazy/lazy_spec.rb
+++ b/spec/ruby/core/enumerator/lazy/lazy_spec.rb
@@ -16,6 +16,10 @@ describe "Enumerator::Lazy" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/enumerator/lazy/lazy_spec.rb#L16
     ]
     lazy_methods += [:chunk_while, :uniq]
 
+    ruby_version_is '3.1' do
+      lazy_methods += [:compact]
+    end
+
     Enumerator::Lazy.instance_methods(false).should include(*lazy_methods)
   end
 end
@@ -26,3 +30,13 @@ describe "Enumerator::Lazy#lazy" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/enumerator/lazy/lazy_spec.rb#L30
     lazy.lazy.should equal(lazy)
   end
 end
+
+ruby_version_is '3.1' do
+  describe "Enumerator::Lazy#compact" do
+    it 'returns array without nil elements' do
+      arr = [1, nil, 3, false, 5].to_enum.lazy.compact
+      arr.should be_an_instance_of(Enumerator::Lazy)
+      arr.force.should == [1, 3, false, 5]
+    end
+  end
+end
diff --git a/spec/ruby/core/file/shared/fnmatch.rb b/spec/ruby/core/file/shared/fnmatch.rb
index 00682bb64c..94f22144b0 100644
--- a/spec/ruby/core/file/shared/fnmatch.rb
+++ b/spec/ruby/core/file/shared/fnmatch.rb
@@ -159,10 +159,10 @@ describe :file_fnmatch, shared: true do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/file/shared/fnmatch.rb#L159
   end
 
   it "does not match leading periods in filenames with wildcards by default" do
-    File.send(@method, '*', '.profile').should == false
-    File.send(@method, '*', 'home/.profile').should == true
-    File.send(@method, '*/*', 'home/.profile').should == true
-    File.send(@method, '*/*', 'dave/.profile', File::FNM_PATHNAME).should == false
+    File.should_not.send(@method, '*', '.profile')
+    File.should.send(@method, '*', 'home/.profile')
+    File.should.send(@method, '*/*', 'home/.profile')
+    File.should_not.send(@method, '*/*', 'dave/.profile', File::FNM_PATHNAME)
   end
 
   it "matches patterns with leading periods to dotfiles by default" do
diff --git a/spec/ruby/core/range/clone_spec.rb b/spec/ruby/core/range/clone_spec.rb
new file mode 100644
index 0000000000..cf6ce74da0
--- /dev/null
+++ b/spec/ruby/core/range/clone_spec.rb
@@ -0,0 +1,26 @@ https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/range/clone_spec.rb#L1
+require_relative '../../spec_helper'
+
+describe "Range#clone" do
+  it "duplicates the range" do
+    original = (1..3)
+    copy = original.clone
+    copy.begin.should == 1
+    copy.end.should == 3
+    copy.should_not.exclude_end?
+    copy.should_not.equal? original
+
+    original = ("a"..."z")
+    copy = original.clone
+    copy.begin.should == "a"
+    copy.end.should == "z"
+    copy.should.exclude_end?
+    copy.should_not.equal? original
+  end
+
+  it "maintains the frozen state" do
+    (1..2).clone.frozen?.should == (1..2).frozen?
+    (1..).clone.frozen?.should == (1..).frozen?
+    Range.new(1, 2).clone.frozen?.should == Range.new(1, 2).frozen?
+    Class.new(Range).new(1, 2).clone.frozen?.should == Class.new(Range).new(1, 2).frozen?
+  end
+end
diff --git a/spec/ruby/core/range/dup_spec.rb b/spec/ruby/core/range/dup_spec.rb
index 976d4fd1d0..fab3c3f1b2 100644
--- a/spec/ruby/core/range/dup_spec.rb
+++ b/spec/ruby/core/range/dup_spec.rb
@@ -2,10 +2,12 @@ require_relative '../../spec_helper' https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/range/dup_spec.rb#L2
 
 describe "Range#dup" do
   it "duplicates the range" do
-    copy = (1..3).dup
+    original = (1..3)
+    copy = original.dup
     copy.begin.should == 1
     copy.end.should == 3
     copy.should_not.exclude_end?
+    copy.should_not.equal?(original)
 
     copy = ("a"..."z").dup
     copy.begin.should == "a"
diff --git a/spec/ruby/core/range/new_spec.rb b/spec/ruby/core/range/new_spec.rb
index 85e99babff..40df914b83 100644
--- a/spec/ruby/core/range/new_spec.rb
+++ b/spec/ruby/core/range/new_spec.rb
@@ -65,5 +65,15 @@ describe "Range.new" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/range/new_spec.rb#L65
 
       range_exclude.should_not == range_include
     end
+
+    ruby_version_is "3.0" do
+      it "creates a frozen range if the class is Range.class" do
+        Range.new(1, 2).should.frozen?
+      end
+
+      it "does not create a frozen range if the class is not Range.class" do
+        Class.new(Range).new(1, 2).should_not.frozen?
+      end
+    end
   end
 end
diff --git a/spec/ruby/core/regexp/shared/quote.rb b/spec/ruby/core/regexp/shared/quote.rb
index 33bdfd9979..9533102766 100644
--- a/spec/ruby/core/regexp/shared/quote.rb
+++ b/spec/ruby/core/regexp/shared/quote.rb
@@ -17,6 +17,11 @@ describe :regexp_quote, shared: true do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/regexp/shared/quote.rb#L17
     Regexp.send(@method, str).should == '\+\[\]\('
   end
 
+  it "works for broken strings" do
+    Regexp.send(@method, "a.\x85b.".force_encoding("US-ASCII")).should =="a\\.\x85b\\.".force_encoding("US-ASCII")
+    Regexp.send(@method, "a.\x80".force_encoding("UTF-8")).should == "a\\.\x80".force_encoding("UTF-8")
+  end
+
   it "sets the encoding of the result to US-ASCII if there are only US-ASCII characters present in the input String" do
     str = "abc".force_encoding("euc-jp")
     Regexp.send(@method, str).encoding.should == Encoding::US_ASCII
diff --git a/spec/ruby/core/regexp/source_spec.rb b/spec/ruby/core/regexp/source_spec.rb
index 709fee49b3..5f253da9ea 100644
--- a/spec/ruby/core/regexp/source_spec.rb
+++ b/spec/ruby/core/regexp/source_spec.rb
@@ -9,8 +9,26 @@ describe "Regexp#source" do https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/regexp/source_spec.rb#L9
     /x(.)xz/.source.should == "x(.)xz"
   end
 
-  it "will remove escape characters" do
-    /foo\/bar/.source.should == "foo/bar"
+  it "keeps escape sequences as is" do
+    /\x20\+/.source.should == '\x20\+'
+  end
+
+  describe "escaping" do
+    it "keeps escaping of metacharacter" do
+      /\$/.source.should == "\\$"
+    end
+
+    it "keeps escaping of metacharacter used as a terminator" do
+      %r+\++.source.should == "\\+"
+    end
+
+    it "removes escaping of non-metacharacter used as a terminator" do
+      %r@\@@.source.should == "@"
+    end
+
+    it "keeps escaping of non-metacharacter not used as a terminator" do
+      /\@/.source.should == "\\@"
+    end
   end
 
    (... truncated)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]