зеркало из https://github.com/github/ruby.git
Expect bool as `sort:` option at glob [Feature #18287]
This commit is contained in:
Родитель
6896324465
Коммит
89b440bf72
|
@ -3858,6 +3858,7 @@ debug_counter.$(OBJEXT): {$(VPATH)}thread_native.h
|
|||
dir.$(OBJEXT): $(hdrdir)/ruby.h
|
||||
dir.$(OBJEXT): $(hdrdir)/ruby/ruby.h
|
||||
dir.$(OBJEXT): $(top_srcdir)/internal/array.h
|
||||
dir.$(OBJEXT): $(top_srcdir)/internal/class.h
|
||||
dir.$(OBJEXT): $(top_srcdir)/internal/compilers.h
|
||||
dir.$(OBJEXT): $(top_srcdir)/internal/dir.h
|
||||
dir.$(OBJEXT): $(top_srcdir)/internal/encoding.h
|
||||
|
@ -3865,6 +3866,7 @@ dir.$(OBJEXT): $(top_srcdir)/internal/error.h
|
|||
dir.$(OBJEXT): $(top_srcdir)/internal/file.h
|
||||
dir.$(OBJEXT): $(top_srcdir)/internal/gc.h
|
||||
dir.$(OBJEXT): $(top_srcdir)/internal/io.h
|
||||
dir.$(OBJEXT): $(top_srcdir)/internal/object.h
|
||||
dir.$(OBJEXT): $(top_srcdir)/internal/serial.h
|
||||
dir.$(OBJEXT): $(top_srcdir)/internal/static_assert.h
|
||||
dir.$(OBJEXT): $(top_srcdir)/internal/string.h
|
||||
|
@ -3888,6 +3890,7 @@ dir.$(OBJEXT): {$(VPATH)}dir.rbinc
|
|||
dir.$(OBJEXT): {$(VPATH)}encindex.h
|
||||
dir.$(OBJEXT): {$(VPATH)}encoding.h
|
||||
dir.$(OBJEXT): {$(VPATH)}id.h
|
||||
dir.$(OBJEXT): {$(VPATH)}id_table.h
|
||||
dir.$(OBJEXT): {$(VPATH)}intern.h
|
||||
dir.$(OBJEXT): {$(VPATH)}internal.h
|
||||
dir.$(OBJEXT): {$(VPATH)}internal/anyargs.h
|
||||
|
|
3
dir.c
3
dir.c
|
@ -112,6 +112,7 @@ char *strchr(char*,char);
|
|||
#include "internal/file.h"
|
||||
#include "internal/gc.h"
|
||||
#include "internal/io.h"
|
||||
#include "internal/object.h"
|
||||
#include "internal/vm.h"
|
||||
#include "ruby/encoding.h"
|
||||
#include "ruby/ruby.h"
|
||||
|
@ -2937,7 +2938,7 @@ dir_glob_option_base(VALUE base)
|
|||
static int
|
||||
dir_glob_option_sort(VALUE sort)
|
||||
{
|
||||
return (sort ? 0 : FNM_GLOB_NOSORT);
|
||||
return (rb_bool_expected(sort, "sort") ? 0 : FNM_GLOB_NOSORT);
|
||||
}
|
||||
|
||||
static VALUE
|
||||
|
|
|
@ -55,6 +55,15 @@ describe :dir_glob, shared: true do
|
|||
end
|
||||
end
|
||||
|
||||
ruby_version_is "3.1" do
|
||||
it "true or false is expected as sort:" do
|
||||
-> {Dir.send(@method, '*', sort: nil)}.should raise_error ArgumentError, /true or false/
|
||||
-> {Dir.send(@method, '*', sort: 0)}.should raise_error ArgumentError, /true or false/
|
||||
-> {Dir.send(@method, '*', sort: "")}.should raise_error ArgumentError, /true or false/
|
||||
-> {Dir.send(@method, '*', sort: Object.new)}.should raise_error ArgumentError, /true or false/
|
||||
end
|
||||
end
|
||||
|
||||
it "matches non-dotfiles with '*'" do
|
||||
expected = %w[
|
||||
brace
|
||||
|
|
|
@ -176,6 +176,12 @@ class TestDir < Test::Unit::TestCase
|
|||
assert_raise_with_message(ArgumentError, /nul-separated/) do
|
||||
Dir.glob(@root + "\0\0\0" + File.join(@root, "*"))
|
||||
end
|
||||
assert_raise_with_message(ArgumentError, /expected true or false/) do
|
||||
Dir.glob(@root, sort: 1)
|
||||
end
|
||||
assert_raise_with_message(ArgumentError, /expected true or false/) do
|
||||
Dir.glob(@root, sort: nil)
|
||||
end
|
||||
|
||||
assert_equal(("a".."z").step(2).map {|f| File.join(File.join(@root, f), "") },
|
||||
Dir.glob(File.join(@root, "*/")))
|
||||
|
|
Загрузка…
Ссылка в новой задаче