ruby-changes:22268
From: nobu <ko1@a...>
Date: Mon, 16 Jan 2012 16:42:24 +0900 (JST)
Subject: [ruby-changes:22268] nobu:r34316 (ruby_1_9_3, trunk, ruby_1_9_2): * lib/optparse.rb (Regexp): fix incorrect options when casting to
nobu 2012-01-16 16:42:01 +0900 (Mon, 16 Jan 2012) New Revision: 34316 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=34316 Log: * lib/optparse.rb (Regexp): fix incorrect options when casting to a Regexp, and suppress encoding option warnings. https://github.com/ruby/ruby/pull/82 Modified files: branches/ruby_1_9_2/ChangeLog branches/ruby_1_9_2/lib/optparse.rb branches/ruby_1_9_2/test/optparse/test_optarg.rb branches/ruby_1_9_2/test/optparse/test_optparse.rb branches/ruby_1_9_2/test/optparse/test_placearg.rb branches/ruby_1_9_2/test/optparse/test_reqarg.rb branches/ruby_1_9_3/ChangeLog branches/ruby_1_9_3/lib/optparse.rb branches/ruby_1_9_3/test/optparse/test_optarg.rb branches/ruby_1_9_3/test/optparse/test_optparse.rb branches/ruby_1_9_3/test/optparse/test_placearg.rb branches/ruby_1_9_3/test/optparse/test_reqarg.rb trunk/ChangeLog trunk/lib/optparse.rb trunk/test/optparse/test_optarg.rb trunk/test/optparse/test_optparse.rb trunk/test/optparse/test_placearg.rb trunk/test/optparse/test_reqarg.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 34315) +++ ChangeLog (revision 34316) @@ -1,3 +1,9 @@ +Mon Jan 16 16:41:53 2012 Nobuyoshi Nakada <nobu@r...> + + * lib/optparse.rb (Regexp): fix incorrect options when casting to + a Regexp, and suppress encoding option warnings. + https://github.com/ruby/ruby/pull/82 + Mon Jan 16 11:22:38 2012 Nobuyoshi Nakada <nobu@r...> * win32/win32.c (rb_chsize): no need to get the current file size. Index: lib/optparse.rb =================================================================== --- lib/optparse.rb (revision 34315) +++ lib/optparse.rb (revision 34316) @@ -1709,7 +1709,8 @@ f |= Regexp::IGNORECASE if /i/ =~ o f |= Regexp::MULTILINE if /m/ =~ o f |= Regexp::EXTENDED if /x/ =~ o - k = o.delete("^imx") + k = o.delete("imx") + k = nil if k.empty? end Regexp.new(s || all, f, k) end Index: test/optparse/test_placearg.rb =================================================================== --- test/optparse/test_placearg.rb (revision 34315) +++ test/optparse/test_placearg.rb (revision 34316) @@ -6,7 +6,10 @@ @opt.def_option("-x [VAL]") {|x| @flag = x} @opt.def_option("--option [VAL]") {|x| @flag = x} @opt.def_option("-T [level]", /^[0-4]$/, Integer) {|x| @topt = x} + @topt = nil @opt.def_option("-n") {} + @opt.def_option("--regexp [REGEXP]", Regexp) {|x| @reopt = x} + @reopt = nil end def test_short Index: test/optparse/test_reqarg.rb =================================================================== --- test/optparse/test_reqarg.rb (revision 34315) +++ test/optparse/test_reqarg.rb (revision 34316) @@ -7,6 +7,8 @@ super @opt.def_option("-xVAL") {|x| @flag = x} @opt.def_option("--option=VAL") {|x| @flag = x} + @opt.def_option("--regexp=REGEXP", Regexp) {|x| @reopt = x} + @reopt = nil end end class Def2 < TestOptionParser Index: test/optparse/test_optarg.rb =================================================================== --- test/optparse/test_optarg.rb (revision 34315) +++ test/optparse/test_optarg.rb (revision 34316) @@ -5,6 +5,8 @@ super @opt.def_option("-x[VAL]") {|x| @flag = x} @opt.def_option("--option[=VAL]") {|x| @flag = x} + @opt.def_option("--regexp[=REGEXP]", Regexp) {|x| @reopt = x} + @reopt = nil end def test_short Index: test/optparse/test_optparse.rb =================================================================== --- test/optparse/test_optparse.rb (revision 34315) +++ test/optparse/test_optparse.rb (revision 34316) @@ -6,10 +6,17 @@ @opt = OptionParser.new @flag = self.class # cannot set by option end + + class DummyOutput < String + alias write << + end def no_error(*args) + $stderr, stderr = DummyOutput.new, $stderr assert_nothing_raised(*args) {return yield} ensure + stderr, $stderr = $stderr, stderr $!.backtrace.delete_if {|e| /\A#{Regexp.quote(__FILE__)}:#{__LINE__-2}/o =~ e} if $! + assert_empty(stderr) end def test_permute @@ -45,4 +52,14 @@ assert_equal(%w"foo -- --help bar", no_error {@opt.order!(%w"foo -- --help bar")}) assert_equal(self.class, @flag) end + + def test_regexp + return unless defined?(@reopt) + assert_equal(%w"", no_error {@opt.parse!(%w"--regexp=/foo/")}) + assert_equal(/foo/, @reopt) + assert_equal(%w"", no_error {@opt.parse!(%w"--regexp=/foo/i")}) + assert_equal(/foo/i, @reopt) + assert_equal(%w"", no_error {@opt.parse!(%w"--regexp=/foo/n")}) + assert_equal(/foo/n, @reopt) + end end Index: ruby_1_9_2/ChangeLog =================================================================== --- ruby_1_9_2/ChangeLog (revision 34315) +++ ruby_1_9_2/ChangeLog (revision 34316) @@ -1,3 +1,9 @@ +Mon Jan 16 16:41:53 2012 Nobuyoshi Nakada <nobu@r...> + + * lib/optparse.rb (Regexp): fix incorrect options when casting to + a Regexp, and suppress encoding option warnings. + https://github.com/ruby/ruby/pull/82 + Wed Dec 28 11:22:45 2011 Nobuyoshi Nakada <nobu@r...> * lib/fileutils.rb (FileUtils::Entry_#entries): use utility method Index: ruby_1_9_2/lib/optparse.rb =================================================================== --- ruby_1_9_2/lib/optparse.rb (revision 34315) +++ ruby_1_9_2/lib/optparse.rb (revision 34316) @@ -1596,7 +1596,8 @@ f |= Regexp::IGNORECASE if /i/ =~ o f |= Regexp::MULTILINE if /m/ =~ o f |= Regexp::EXTENDED if /x/ =~ o - k = o.delete("^imx") + k = o.delete("imx") + k = nil if k.empty? end Regexp.new(s || all, f, k) end Index: ruby_1_9_2/test/optparse/test_placearg.rb =================================================================== --- ruby_1_9_2/test/optparse/test_placearg.rb (revision 34315) +++ ruby_1_9_2/test/optparse/test_placearg.rb (revision 34316) @@ -6,7 +6,10 @@ @opt.def_option("-x [VAL]") {|x| @flag = x} @opt.def_option("--option [VAL]") {|x| @flag = x} @opt.def_option("-T [level]", /^[0-4]$/, Integer) {|x| @topt = x} + @topt = nil @opt.def_option("-n") {} + @opt.def_option("--regexp [REGEXP]", Regexp) {|x| @reopt = x} + @reopt = nil end def test_short Index: ruby_1_9_2/test/optparse/test_reqarg.rb =================================================================== --- ruby_1_9_2/test/optparse/test_reqarg.rb (revision 34315) +++ ruby_1_9_2/test/optparse/test_reqarg.rb (revision 34316) @@ -7,6 +7,8 @@ super @opt.def_option("-xVAL") {|x| @flag = x} @opt.def_option("--option=VAL") {|x| @flag = x} + @opt.def_option("--regexp=REGEXP", Regexp) {|x| @reopt = x} + @reopt = nil end end class Def2 < TestOptionParser Index: ruby_1_9_2/test/optparse/test_optarg.rb =================================================================== --- ruby_1_9_2/test/optparse/test_optarg.rb (revision 34315) +++ ruby_1_9_2/test/optparse/test_optarg.rb (revision 34316) @@ -5,6 +5,8 @@ super @opt.def_option("-x[VAL]") {|x| @flag = x} @opt.def_option("--option[=VAL]") {|x| @flag = x} + @opt.def_option("--regexp[=REGEXP]", Regexp) {|x| @reopt = x} + @reopt = nil end def test_short Index: ruby_1_9_2/test/optparse/test_optparse.rb =================================================================== --- ruby_1_9_2/test/optparse/test_optparse.rb (revision 34315) +++ ruby_1_9_2/test/optparse/test_optparse.rb (revision 34316) @@ -6,10 +6,17 @@ @opt = OptionParser.new @flag = self.class # cannot set by option end + + class DummyOutput < String + alias write << + end def no_error(*args) + $stderr, stderr = DummyOutput.new, $stderr assert_nothing_raised(*args) {return yield} ensure + stderr, $stderr = $stderr, stderr $!.backtrace.delete_if {|e| /\A#{Regexp.quote(__FILE__)}:#{__LINE__-2}/o =~ e} if $! + assert_empty(stderr) end def test_permute @@ -45,4 +52,14 @@ assert_equal(%w"foo -- --help bar", no_error {@opt.order!(%w"foo -- --help bar")}) assert_equal(self.class, @flag) end + + def test_regexp + return unless defined?(@reopt) + assert_equal(%w"", no_error {@opt.parse!(%w"--regexp=/foo/")}) + assert_equal(/foo/, @reopt) + assert_equal(%w"", no_error {@opt.parse!(%w"--regexp=/foo/i")}) + assert_equal(/foo/i, @reopt) + assert_equal(%w"", no_error {@opt.parse!(%w"--regexp=/foo/n")}) + assert_equal(/foo/n, @reopt) + end end Index: ruby_1_9_3/ChangeLog =================================================================== --- ruby_1_9_3/ChangeLog (revision 34315) +++ ruby_1_9_3/ChangeLog (revision 34316) @@ -1,3 +1,9 @@ +Mon Jan 16 16:41:53 2012 Nobuyoshi Nakada <nobu@r...> + + * lib/optparse.rb (Regexp): fix incorrect options when casting to + a Regexp, and suppress encoding option warnings. + https://github.com/ruby/ruby/pull/82 + Fri Jan 13 15:22:43 2012 Tanaka Akira <akr@f...> * time.c (TIME_COPY_GMT): copy vtm.utc_offset and vtm.zone too. Index: ruby_1_9_3/lib/optparse.rb =================================================================== --- ruby_1_9_3/lib/optparse.rb (revision 34315) +++ ruby_1_9_3/lib/optparse.rb (revision 34316) @@ -1709,7 +1709,8 @@ f |= Regexp::IGNORECASE if /i/ =~ o f |= Regexp::MULTILINE if /m/ =~ o f |= Regexp::EXTENDED if /x/ =~ o - k = o.delete("^imx") + k = o.delete("imx") + k = nil if k.empty? end Regexp.new(s || all, f, k) end Index: ruby_1_9_3/test/optparse/test_placearg.rb =================================================================== --- ruby_1_9_3/test/optparse/test_placearg.rb (revision 34315) +++ ruby_1_9_3/test/optparse/test_placearg.rb (revision 34316) @@ -6,7 +6,10 @@ @opt.def_option("-x [VAL]") {|x| @flag = x} @opt.def_option("--option [VAL]") {|x| @flag = x} @opt.def_option("-T [level]", /^[0-4]$/, Integer) {|x| @topt = x} + @topt = nil @opt.def_option("-n") {} + @opt.def_option("--regexp [REGEXP]", Regexp) {|x| @reopt = x} + @reopt = nil end def test_short Index: ruby_1_9_3/test/optparse/test_reqarg.rb =================================================================== --- ruby_1_9_3/test/optparse/test_reqarg.rb (revision 34315) +++ ruby_1_9_3/test/optparse/test_reqarg.rb (revision 34316) @@ -7,6 +7,8 @@ super @opt.def_option("-xVAL") {|x| @flag = x} @opt.def_option("--option=VAL") {|x| @flag = x} + @opt.def_option("--regexp=REGEXP", Regexp) {|x| @reopt = x} + @reopt = nil end end class Def2 < TestOptionParser Index: ruby_1_9_3/test/optparse/test_optarg.rb =================================================================== --- ruby_1_9_3/test/optparse/test_optarg.rb (revision 34315) +++ ruby_1_9_3/test/optparse/test_optarg.rb (revision 34316) @@ -5,6 +5,8 @@ super @opt.def_option("-x[VAL]") {|x| @flag = x} @opt.def_option("--option[=VAL]") {|x| @flag = x} + @opt.def_option("--regexp[=REGEXP]", Regexp) {|x| @reopt = x} + @reopt = nil end def test_short Index: ruby_1_9_3/test/optparse/test_optparse.rb =================================================================== --- ruby_1_9_3/test/optparse/test_optparse.rb (revision 34315) +++ ruby_1_9_3/test/optparse/test_optparse.rb (revision 34316) @@ -6,10 +6,17 @@ @opt = OptionParser.new @flag = self.class # cannot set by option end + + class DummyOutput < String + alias write << + end def no_error(*args) + $stderr, stderr = DummyOutput.new, $stderr assert_nothing_raised(*args) {return yield} ensure + stderr, $stderr = $stderr, stderr $!.backtrace.delete_if {|e| /\A#{Regexp.quote(__FILE__)}:#{__LINE__-2}/o =~ e} if $! + assert_empty(stderr) end def test_permute @@ -45,4 +52,14 @@ assert_equal(%w"foo -- --help bar", no_error {@opt.order!(%w"foo -- --help bar")}) assert_equal(self.class, @flag) end + + def test_regexp + return unless defined?(@reopt) + assert_equal(%w"", no_error {@opt.parse!(%w"--regexp=/foo/")}) + assert_equal(/foo/, @reopt) + assert_equal(%w"", no_error {@opt.parse!(%w"--regexp=/foo/i")}) + assert_equal(/foo/i, @reopt) + assert_equal(%w"", no_error {@opt.parse!(%w"--regexp=/foo/n")}) + assert_equal(/foo/n, @reopt) + end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/