Skip to content

Commit

Permalink
* lib/scanf.rb (Scanf::FormatSpecifier#letter, #width): use matched
Browse files Browse the repository at this point in the history
  substring directly.

* ext/nkf/lib/kconv.rb (Kconv.conv): get rid of nil.to_a.

* test/ruby/test_assignment.rb, test/ruby/test_iterator.rb: followed
  change of sample/test.rb.

* test/net/http/test_http.rb: removed superfluous splatting stars.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9360 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nobu committed Oct 8, 2005
1 parent 8fb6f79 commit ec12edb
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 69 deletions.
12 changes: 12 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
Sat Oct 8 19:45:16 2005 Nobuyoshi Nakada <[email protected]>

* lib/scanf.rb (Scanf::FormatSpecifier#letter, #width): use matched
substring directly.

* ext/nkf/lib/kconv.rb (Kconv.conv): get rid of nil.to_a.

* test/ruby/test_assignment.rb, test/ruby/test_iterator.rb: followed
change of sample/test.rb.

* test/net/http/test_http.rb: removed superfluous splatting stars.

Sat Oct 8 19:32:56 2005 Nobuyoshi Nakada <[email protected]>

* io.c (rb_io_init_copy): clear PREP flag for copied IO.
Expand Down
2 changes: 1 addition & 1 deletion ext/nkf/lib/kconv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def conv(str, *args)

to = symbol_to_option(option[0])
from = symbol_to_option(option[1]).to_s.sub(/(-[jesw])/o){$1.upcase}
opt = option[2..-1].to_a.flatten.map{|x|symbol_to_option(x)}.compact.join(' ')
opt = option[2..-1] and opt = opt.flatten.map{|x|symbol_to_option(x)}.compact.join(' ')

nkf_opt = '-x -m0 %s %s %s' % [to, from, opt]
result = ::NKF::nkf( nkf_opt, str)
Expand Down
4 changes: 2 additions & 2 deletions lib/scanf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -467,11 +467,11 @@ def match(str)
end

def letter
/%\*?\d*([a-z\[])/.match(@spec_string).to_a[1]
@spec_string[/%\*?\d*([a-z\[])/, 1]
end

def width
w = /%\*?(\d+)/.match(@spec_string).to_a[1]
w = @spec_string[/%\*?(\d+)/, 1]
w && w.to_i
end

Expand Down
6 changes: 3 additions & 3 deletions test/net/http/test_http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_get
end

def _test_get__get(http)
res, body = *http.get('/')
res, body = http.get('/')
assert_kind_of Net::HTTPResponse, res
assert_kind_of String, res.body
assert_kind_of String, body
Expand Down Expand Up @@ -61,7 +61,7 @@ def _test_get__iter(http)

def _test_get__chunked(http)
buf = ''
res, body = *http.get('/') {|s| buf << s }
res, body = http.get('/') {|s| buf << s }
assert_kind_of Net::HTTPResponse, res
# assert_kind_of String, res.body
# assert_kind_of String, body
Expand All @@ -86,7 +86,7 @@ def test_get__break
end

def test_get__implicit_start
res, body = *new().get('/')
res, body = new().get('/')
assert_kind_of Net::HTTPResponse, res
assert_kind_of String, body
assert_kind_of String, res.body
Expand Down
61 changes: 0 additions & 61 deletions test/ruby/test_assignment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ def test_assign
a = [*[1]]; assert_equal([1], a)
a = [*[1,2]]; assert_equal([1,2], a)

a = *nil; assert_nil(a)
a = *1; assert_equal(1, a)
a = *[]; assert_nil(a)
a = *[1]; assert_equal(1, a)
a = *[nil]; assert_nil(a)
Expand All @@ -51,8 +49,6 @@ def test_assign
*a = [*[1]]; assert_equal([[1]], a)
*a = [*[1,2]]; assert_equal([[1,2]], a)

*a = *nil; assert_equal([nil], a)
*a = *1; assert_equal([1], a)
*a = *[]; assert_equal([], a)
*a = *[1]; assert_equal([1], a)
*a = *[nil]; assert_equal([nil], a)
Expand All @@ -73,8 +69,6 @@ def test_assign
a,b,*c = [*[1]]; assert_equal([1,nil,[]], [a,b,c])
a,b,*c = [*[1,2]]; assert_equal([1,2,[]], [a,b,c])

a,b,*c = *nil; assert_equal([nil,nil,[]], [a,b,c])
a,b,*c = *1; assert_equal([1,nil,[]], [a,b,c])
a,b,*c = *[]; assert_equal([nil,nil,[]], [a,b,c])
a,b,*c = *[1]; assert_equal([1,nil,[]], [a,b,c])
a,b,*c = *[nil]; assert_equal([nil,nil,[]], [a,b,c])
Expand All @@ -96,8 +90,6 @@ def f; yield([*[]]); end; f {|a| assert_equal([], a)}; undef f
def f; yield([*[1]]); end; f {|a| assert_equal([1], a)}; undef f
def f; yield([*[1,2]]); end; f {|a| assert_equal([1,2], a)}; undef f

def f; yield(*nil); end; f {|a| assert_nil(a)}; undef f
def f; yield(*1); end; f {|a| assert_equal(1, a)}; undef f
def f; yield(*[1]); end; f {|a| assert_equal(1, a)}; undef f
def f; yield(*[nil]); end; f {|a| assert_nil(a)}; undef f
def f; yield(*[[]]); end; f {|a| assert_equal([], a)}; undef f
Expand All @@ -115,8 +107,6 @@ def f; yield([*[]]); end; f {|*a| assert_equal([[]], a)}; undef f
def f; yield([*[1]]); end; f {|*a| assert_equal([[1]], a)}; undef f
def f; yield([*[1,2]]); end; f {|*a| assert_equal([[1,2]], a)}; undef f

def f; yield(*nil); end; f {|*a| assert_equal([nil], a)}; undef f
def f; yield(*1); end; f {|*a| assert_equal([1], a)}; undef f
def f; yield(*[]); end; f {|*a| assert_equal([], a)}; undef f
def f; yield(*[1]); end; f {|*a| assert_equal([1], a)}; undef f
def f; yield(*[nil]); end; f {|*a| assert_equal([nil], a)}; undef f
Expand All @@ -136,8 +126,6 @@ def f; yield([*[]]); end; f {|a,b,*c| assert_equal([nil,nil,[]], [a,b,c])}; unde
def f; yield([*[1]]); end; f {|a,b,*c| assert_equal([1,nil,[]], [a,b,c])}; undef f
def f; yield([*[1,2]]); end; f {|a,b,*c| assert_equal([1,2,[]], [a,b,c])}; undef f

def f; yield(*nil); end; f {|a,b,*c| assert_equal([nil,nil,[]], [a,b,c])}; undef f
def f; yield(*1); end; f {|a,b,*c| assert_equal([1,nil,[]], [a,b,c])}; undef f
def f; yield(*[]); end; f {|a,b,*c| assert_equal([nil,nil,[]], [a,b,c])}; undef f
def f; yield(*[1]); end; f {|a,b,*c| assert_equal([1,nil,[]], [a,b,c])}; undef f
def f; yield(*[nil]); end; f {|a,b,*c| assert_equal([nil,nil,[]], [a,b,c])}; undef f
Expand All @@ -159,8 +147,6 @@ def r; return [*[]]; end; a = r(); assert_equal([], a); undef r
def r; return [*[1]]; end; a = r(); assert_equal([1], a); undef r
def r; return [*[1,2]]; end; a = r(); assert_equal([1,2], a); undef r

def r; return *nil; end; a = r(); assert_nil(a); undef r
def r; return *1; end; a = r(); assert_equal(1, a); undef r
def r; return *[]; end; a = r(); assert_nil(a); undef r
def r; return *[1]; end; a = r(); assert_equal(1, a); undef r
def r; return *[nil]; end; a = r(); assert_nil(a); undef r
Expand All @@ -169,14 +155,7 @@ def r; return *[*[]]; end; a = r(); assert_nil(a); undef r
def r; return *[*[1]]; end; a = r(); assert_equal(1, a); undef r
def r; return *[*[1,2]]; end; a = r(); assert_equal([1,2], a); undef r

def r; return *nil; end; a = *r(); assert_nil(a); undef r
def r; return *1; end; a = *r(); assert_equal(1, a); undef r
def r; return *[]; end; a = *r(); assert_nil(a); undef r
def r; return *[1]; end; a = *r(); assert_equal(1, a); undef r
def r; return *[nil]; end; a = *r(); assert_nil(a); undef r
def r; return *[[]]; end; a = *r(); assert_nil(a); undef r
def r; return *[*[]]; end; a = *r(); assert_nil(a); undef r
def r; return *[*[1]]; end; a = *r(); assert_equal(1, a); undef r
def r; return *[*[1,2]]; end; a = *r(); assert_equal([1,2], a); undef r

def r; return; end; *a = r(); assert_equal([nil], a); undef r
Expand All @@ -191,8 +170,6 @@ def r; return [*[]]; end; *a = r(); assert_equal([[]], a); undef r
def r; return [*[1]]; end; *a = r(); assert_equal([[1]], a); undef r
def r; return [*[1,2]]; end; *a = r(); assert_equal([[1,2]], a); undef r

def r; return *nil; end; *a = r(); assert_equal([nil], a); undef r
def r; return *1; end; *a = r(); assert_equal([1], a); undef r
def r; return *[]; end; *a = r(); assert_equal([nil], a); undef r
def r; return *[1]; end; *a = r(); assert_equal([1], a); undef r
def r; return *[nil]; end; *a = r(); assert_equal([nil], a); undef r
Expand All @@ -202,15 +179,8 @@ def r; return *[*[]]; end; *a = r(); assert_equal([nil], a); undef r
def r; return *[*[1]]; end; *a = r(); assert_equal([1], a); undef r
def r; return *[*[1,2]]; end; *a = r(); assert_equal([[1,2]], a); undef r

def r; return *nil; end; *a = *r(); assert_equal([nil], a); undef r
def r; return *1; end; *a = *r(); assert_equal([1], a); undef r
def r; return *[]; end; *a = *r(); assert_equal([nil], a); undef r
def r; return *[1]; end; *a = *r(); assert_equal([1], a); undef r
def r; return *[nil]; end; *a = *r(); assert_equal([nil], a); undef r
def r; return *[[]]; end; *a = *r(); assert_equal([], a); undef r
def r; return *[1,2]; end; *a = *r(); assert_equal([1,2], a); undef r
def r; return *[*[]]; end; *a = *r(); assert_equal([nil], a); undef r
def r; return *[*[1]]; end; *a = *r(); assert_equal([1], a); undef r
def r; return *[*[1,2]]; end; *a = *r(); assert_equal([1,2], a); undef r

def r; return; end; a,b,*c = r(); assert_equal([nil,nil,[]], [a,b,c]); undef r
Expand All @@ -225,8 +195,6 @@ def r; return [*[]]; end; a,b,*c = r(); assert_equal([nil,nil,[]], [a,b,c]); und
def r; return [*[1]]; end; a,b,*c = r(); assert_equal([1,nil,[]], [a,b,c]); undef r
def r; return [*[1,2]]; end; a,b,*c = r(); assert_equal([1,2,[]], [a,b,c]); undef r

def r; return *nil; end; a,b,*c = r(); assert_equal([nil,nil,[]], [a,b,c]); undef r
def r; return *1; end; a,b,*c = r(); assert_equal([1,nil,[]], [a,b,c]); undef r
def r; return *[]; end; a,b,*c = r(); assert_equal([nil,nil,[]], [a,b,c]); undef r
def r; return *[1]; end; a,b,*c = r(); assert_equal([1,nil,[]], [a,b,c]); undef r
def r; return *[nil]; end; a,b,*c = r(); assert_equal([nil,nil,[]], [a,b,c]); undef r
Expand Down Expand Up @@ -292,8 +260,6 @@ def test_break
a = loop do break [*[1]]; end; assert_equal([1], a)
a = loop do break [*[1,2]]; end; assert_equal([1,2], a)

a = loop do break *nil; end; assert_nil(a)
a = loop do break *1; end; assert_equal(1, a)
a = loop do break *[]; end; assert_nil(a)
a = loop do break *[1]; end; assert_equal(1, a)
a = loop do break *[nil]; end; assert_nil(a)
Expand All @@ -314,8 +280,6 @@ def test_break
*a = loop do break [*[1]]; end; assert_equal([[1]], a)
*a = loop do break [*[1,2]]; end; assert_equal([[1,2]], a)

*a = loop do break *nil; end; assert_equal([nil], a)
*a = loop do break *1; end; assert_equal([1], a)
*a = loop do break *[]; end; assert_equal([nil], a)
*a = loop do break *[1]; end; assert_equal([1], a)
*a = loop do break *[nil]; end; assert_equal([nil], a)
Expand All @@ -325,15 +289,8 @@ def test_break
*a = loop do break *[*[1]]; end; assert_equal([1], a)
*a = loop do break *[*[1,2]]; end; assert_equal([[1,2]], a)

*a = *loop do break *nil; end; assert_equal([nil], a)
*a = *loop do break *1; end; assert_equal([1], a)
*a = *loop do break *[]; end; assert_equal([nil], a)
*a = *loop do break *[1]; end; assert_equal([1], a)
*a = *loop do break *[nil]; end; assert_equal([nil], a)
*a = *loop do break *[[]]; end; assert_equal([], a)
*a = *loop do break *[1,2]; end; assert_equal([1,2], a)
*a = *loop do break *[*[]]; end; assert_equal([nil], a)
*a = *loop do break *[*[1]]; end; assert_equal([1], a)
*a = *loop do break *[*[1,2]]; end; assert_equal([1,2], a)

a,b,*c = loop do break; end; assert_equal([nil,nil,[]], [a,b,c])
Expand All @@ -348,8 +305,6 @@ def test_break
a,b,*c = loop do break [*[1]]; end; assert_equal([1,nil,[]], [a,b,c])
a,b,*c = loop do break [*[1,2]]; end; assert_equal([1,2,[]], [a,b,c])

a,b,*c = loop do break *nil; end; assert_equal([nil,nil,[]], [a,b,c])
a,b,*c = loop do break *1; end; assert_equal([1,nil,[]], [a,b,c])
a,b,*c = loop do break *[]; end; assert_equal([nil,nil,[]], [a,b,c])
a,b,*c = loop do break *[1]; end; assert_equal([1,nil,[]], [a,b,c])
a,b,*c = loop do break *[nil]; end; assert_equal([nil,nil,[]], [a,b,c])
Expand All @@ -373,8 +328,6 @@ def r(val); a = yield(); assert_equal(val, a); end
r([1]){next [*[1]]}
r([1,2]){next [*[1,2]]}

r(nil){next *nil}
r(1){next *1}
r(nil){next *[]}
r(1){next *[1]}
r(nil){next *[nil]}
Expand All @@ -399,15 +352,8 @@ def r(val); *a = yield(); assert_equal(val, a); end
undef r

def r(val); *a = *yield(); assert_equal(val, a); end
r([nil]){next *nil}
r([1]){next *1}
r([nil]){next *[]}
r([1]){next *[1]}
r([nil]){next *[nil]}
r([]){next *[[]]}
r([1,2]){next *[1,2]}
r([nil]){next *[*[]]}
r([1]){next *[*[1]]}
r([1,2]){next *[*[1,2]]}
undef r

Expand All @@ -426,15 +372,8 @@ def r(val); a,b,*c = yield(); assert_equal(val, [a,b,c]); end
undef r

def r(val); a,b,*c = *yield(); assert_equal(val, [a,b,c]); end
r([nil,nil,[]]){next *nil}
r([1,nil,[]]){next *1}
r([nil,nil,[]]){next *[]}
r([1,nil,[]]){next *[1]}
r([nil,nil,[]]){next *[nil]}
r([nil,nil,[]]){next *[[]]}
r([1,2,[]]){next *[1,2]}
r([nil,nil,[]]){next *[*[]]}
r([1,nil,[]]){next *[*[1]]}
r([1,2,[]]){next *[*[1,2]]}
undef r
end
Expand Down
2 changes: 0 additions & 2 deletions test/ruby/test_iterator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,9 @@ def test_itertest
IterTest.new([0]).each0 {|x| assert_equal(0, x)}
IterTest.new([1]).each1 {|x| assert_equal(1, x)}
IterTest.new([2]).each2 {|x| assert_equal([2], x)}
IterTest.new([3]).each3 {|x| assert_equal(3, x)}
IterTest.new([4]).each4 {|x| assert_equal(4, x)}
IterTest.new([5]).each5 {|x| assert_equal(5, x)}
IterTest.new([6]).each6 {|x| assert_equal([6], x)}
IterTest.new([7]).each7 {|x| assert_equal(7, x)}
IterTest.new([8]).each8 {|x| assert_equal(8, x)}

IterTest.new([[0]]).each0 {|x| assert_equal([0], x)}
Expand Down

0 comments on commit ec12edb

Please sign in to comment.