diff options
author | Benoit Daloze <eregontp@gmail.com> | 2020-11-27 14:55:31 +0100 |
---|---|---|
committer | Benoit Daloze <eregontp@gmail.com> | 2020-11-27 14:55:31 +0100 |
commit | f02d2f82bf10351f480ea312f40cb840e2437f93 (patch) | |
tree | 0b53098bffe6dacadb09880183ebcaea06e95153 /spec/ruby/core | |
parent | f0bfa266d70651dc295a63b026938b246693499b (diff) |
Update to ruby/spec@ac878ad
Diffstat (limited to 'spec/ruby/core')
-rw-r--r-- | spec/ruby/core/dir/fixtures/common.rb | 3 | ||||
-rw-r--r-- | spec/ruby/core/dir/glob_spec.rb | 16 | ||||
-rw-r--r-- | spec/ruby/core/dir/shared/glob.rb | 3 | ||||
-rw-r--r-- | spec/ruby/core/hash/ruby2_keywords_hash_spec.rb | 47 | ||||
-rw-r--r-- | spec/ruby/core/kernel/backtick_spec.rb | 4 | ||||
-rw-r--r-- | spec/ruby/core/proc/shared/to_s.rb | 9 | ||||
-rw-r--r-- | spec/ruby/core/string/fixtures/classes.rb | 11 | ||||
-rw-r--r-- | spec/ruby/core/string/gsub_spec.rb | 5 | ||||
-rw-r--r-- | spec/ruby/core/string/unpack/w_spec.rb | 10 |
9 files changed, 106 insertions, 2 deletions
diff --git a/spec/ruby/core/dir/fixtures/common.rb b/spec/ruby/core/dir/fixtures/common.rb index 96dba56c93..71b1438b72 100644 --- a/spec/ruby/core/dir/fixtures/common.rb +++ b/spec/ruby/core/dir/fixtures/common.rb @@ -36,6 +36,8 @@ module DirSpecs .dotfile .dotsubdir/.dotfile .dotsubdir/nondotfile + nested/.dotsubir/.dotfile + nested/.dotsubir/nondotfile deeply/.dotfile deeply/nested/.dotfile.ext @@ -160,6 +162,7 @@ module DirSpecs dir_filename_ordering file_one.ext file_two.ext + nested nondotfile special subdir_one diff --git a/spec/ruby/core/dir/glob_spec.rb b/spec/ruby/core/dir/glob_spec.rb index d4888ee147..9b6e2b2d3d 100644 --- a/spec/ruby/core/dir/glob_spec.rb +++ b/spec/ruby/core/dir/glob_spec.rb @@ -59,6 +59,8 @@ describe "Dir.glob" do deeply/nested/directory/ deeply/nested/directory/structure/ dir/ + nested/ + nested/.dotsubir/ special/ special/test{1}/ subdir_one/ @@ -68,6 +70,18 @@ describe "Dir.glob" do Dir.glob('**/', File::FNM_DOTMATCH).sort.should == expected end + it "recursively matches files and directories in nested dot subdirectory with 'nested/**/*' from the current directory and option File::FNM_DOTMATCH" do + expected = %w[ + nested/. + nested/.dotsubir + nested/.dotsubir/. + nested/.dotsubir/.dotfile + nested/.dotsubir/nondotfile + ] + + Dir.glob('nested/**/*', File::FNM_DOTMATCH).sort.should == expected.sort + end + # This is a separate case to check **/ coming after a constant # directory as well. it "recursively matches any subdirectories except './' or '../' with '**/' and option File::FNM_DOTMATCH" do @@ -80,6 +94,8 @@ describe "Dir.glob" do ./deeply/nested/directory/ ./deeply/nested/directory/structure/ ./dir/ + ./nested/ + ./nested/.dotsubir/ ./special/ ./special/test{1}/ ./subdir_one/ diff --git a/spec/ruby/core/dir/shared/glob.rb b/spec/ruby/core/dir/shared/glob.rb index fcaa0d8a43..f6d41ba209 100644 --- a/spec/ruby/core/dir/shared/glob.rb +++ b/spec/ruby/core/dir/shared/glob.rb @@ -53,6 +53,7 @@ describe :dir_glob, shared: true do dir_filename_ordering file_one.ext file_two.ext + nested nondotfile special subdir_one @@ -156,6 +157,7 @@ describe :dir_glob, shared: true do dir_filename_ordering file_one.ext file_two.ext + nested nondotfile special subdir_one @@ -177,6 +179,7 @@ describe :dir_glob, shared: true do deeply/nested/directory/ deeply/nested/directory/structure/ dir/ + nested/ special/ special/test{1}/ subdir_one/ diff --git a/spec/ruby/core/hash/ruby2_keywords_hash_spec.rb b/spec/ruby/core/hash/ruby2_keywords_hash_spec.rb new file mode 100644 index 0000000000..005886a482 --- /dev/null +++ b/spec/ruby/core/hash/ruby2_keywords_hash_spec.rb @@ -0,0 +1,47 @@ +require_relative '../../spec_helper' +require_relative 'fixtures/classes' + +ruby_version_is "2.7" do + describe "Hash.ruby2_keywords_hash?" do + it "returns false if the Hash is not a keywords Hash" do + Hash.ruby2_keywords_hash?({}).should == false + end + + it "returns true if the Hash is a keywords Hash marked by Module#ruby2_keywords" do + obj = Class.new { + ruby2_keywords def m(*args) + args.last + end + }.new + Hash.ruby2_keywords_hash?(obj.m(a: 1)).should == true + end + + it "raises TypeError for non-Hash" do + -> { Hash.ruby2_keywords_hash?(nil) }.should raise_error(TypeError) + end + end + + describe "Hash.ruby2_keywords_hash" do + it "returns a copy of a Hash and marks the copy as a keywords Hash" do + h = {a: 1}.freeze + kw = Hash.ruby2_keywords_hash(h) + Hash.ruby2_keywords_hash?(h).should == false + Hash.ruby2_keywords_hash?(kw).should == true + kw.should == h + end + + it "returns an instance of the subclass if called on an instance of a subclass of Hash" do + h = HashSpecs::MyHash.new + h[:a] = 1 + kw = Hash.ruby2_keywords_hash(h) + kw.class.should == HashSpecs::MyHash + Hash.ruby2_keywords_hash?(h).should == false + Hash.ruby2_keywords_hash?(kw).should == true + kw.should == h + end + + it "raises TypeError for non-Hash" do + -> { Hash.ruby2_keywords_hash(nil) }.should raise_error(TypeError) + end + end +end diff --git a/spec/ruby/core/kernel/backtick_spec.rb b/spec/ruby/core/kernel/backtick_spec.rb index 391583b539..045bb598cd 100644 --- a/spec/ruby/core/kernel/backtick_spec.rb +++ b/spec/ruby/core/kernel/backtick_spec.rb @@ -36,6 +36,10 @@ describe "Kernel#`" do end platform_is_not :windows do + it "handles invalid UTF-8 bytes in command" do + `echo "testing\xC2 a non UTF-8 string"`.should == "testing\xC2 a non UTF-8 string\n" + end + it "sets $? to the exit status of the executed sub-process" do ip = 'world' `echo disc #{ip}` diff --git a/spec/ruby/core/proc/shared/to_s.rb b/spec/ruby/core/proc/shared/to_s.rb index 7edd11b1e1..7f167a3d9d 100644 --- a/spec/ruby/core/proc/shared/to_s.rb +++ b/spec/ruby/core/proc/shared/to_s.rb @@ -33,8 +33,13 @@ describe :proc_to_s, shared: true do describe "for a proc created with UnboundMethod#to_proc" do it "returns a description including '(lambda)' and optionally including file and line number" do - def hello; end - method("hello").to_proc.send(@method).should =~ /^#<Proc:([^ ]*?)(#{sep}#{Regexp.escape __FILE__}:#{__LINE__ })? \(lambda\)>$/ + def hello; end + s = method("hello").to_proc.send(@method) + if s.include? __FILE__ + s.should =~ /^#<Proc:([^ ]*?)#{sep}#{Regexp.escape __FILE__}:#{__LINE__ - 3} \(lambda\)>$/ + else + s.should =~ /^#<Proc:([^ ]*?) \(lambda\)>$/ + end end it "has a binary encoding" do diff --git a/spec/ruby/core/string/fixtures/classes.rb b/spec/ruby/core/string/fixtures/classes.rb index 1cc7600abb..26fcd51b5d 100644 --- a/spec/ruby/core/string/fixtures/classes.rb +++ b/spec/ruby/core/string/fixtures/classes.rb @@ -46,4 +46,15 @@ module StringSpecs self.replace(str) end end + + class SpecialVarProcessor + def process(match) + if $~ != nil + str = $~[0] + else + str = "unset" + end + "<#{str}>" + end + end end diff --git a/spec/ruby/core/string/gsub_spec.rb b/spec/ruby/core/string/gsub_spec.rb index 54a2be0fed..6789199ff3 100644 --- a/spec/ruby/core/string/gsub_spec.rb +++ b/spec/ruby/core/string/gsub_spec.rb @@ -475,6 +475,11 @@ describe "String#gsub with pattern and block" do offsets.should == [[1, 2], [4, 5]] end + it "does not set $~ for procs created from methods" do + str = "hello" + str.gsub("l", &StringSpecs::SpecialVarProcessor.new.method(:process)).should == "he<unset><unset>o" + end + it "restores $~ after leaving the block" do [/./, "l"].each do |pattern| old_md = nil diff --git a/spec/ruby/core/string/unpack/w_spec.rb b/spec/ruby/core/string/unpack/w_spec.rb index 166ae58869..011c75f5c4 100644 --- a/spec/ruby/core/string/unpack/w_spec.rb +++ b/spec/ruby/core/string/unpack/w_spec.rb @@ -23,3 +23,13 @@ describe "String#unpack with directive 'w'" do "\x01\x02\x03".unpack("w w").should == [1, 2] end end + +describe "String#unpack with directive 'w*'" do + + it "decodes BER-compressed integers" do + "\x01\x02\x03\x04".unpack("w*").should == [1, 2, 3, 4] + "\x00\xCE\x0F\x84\x80\x80\x80\x80\x80\x80\x80\x80\x00\x01\x00".unpack("w*").should == [0, 9999, 2**65, 1, 0] + "\x81\x80\x80\x80\x80\x80\x80\x80\x80\x00\x90\x80\x80\x80\x80\x80\x80\x80\x03\x01\x02".unpack("w*").should == [2**63, (2**60 + 3), 1, 2] + end + +end |