* test/ruby/test_argf.rb (assert_src_expected): refactored.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24719 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
44320bc32c
commit
7fed54570f
@ -54,8 +54,21 @@ class TestArgf < Test::Unit::TestCase
|
|||||||
/cygwin|mswin|mingw|bccwin/ =~ RUBY_PLATFORM
|
/cygwin|mswin|mingw|bccwin/ =~ RUBY_PLATFORM
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def assert_src_expected(line, src, args = nil)
|
||||||
|
args ||= [@t1.path, @t2.path, @t3.path]
|
||||||
|
expected = src.split(/^/)
|
||||||
|
ruby('-e', src, *args) do |f|
|
||||||
|
expected.each_with_index do |e, i|
|
||||||
|
/#=> *(.*)/ =~ e or next
|
||||||
|
a = f.gets
|
||||||
|
assert_not_nil(a, "[ruby-dev:34445]: remained")
|
||||||
|
assert_equal($1, a.chomp, "[ruby-dev:34445]: line #{line+i}")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_argf
|
def test_argf
|
||||||
src = <<-SRC
|
assert_src_expected(__LINE__+1, <<-'SRC')
|
||||||
a = ARGF
|
a = ARGF
|
||||||
b = a.dup
|
b = a.dup
|
||||||
p [a.gets.chomp, a.lineno, b.gets.chomp, b.lineno] #=> ["1", 1, "1", 1]
|
p [a.gets.chomp, a.lineno, b.gets.chomp, b.lineno] #=> ["1", 1, "1", 1]
|
||||||
@ -72,20 +85,10 @@ class TestArgf < Test::Unit::TestCase
|
|||||||
p [a.gets.chomp, a.lineno, b.gets.chomp, b.lineno] #=> ["5", 5, "5", 8]
|
p [a.gets.chomp, a.lineno, b.gets.chomp, b.lineno] #=> ["5", 5, "5", 8]
|
||||||
p [a.gets.chomp, a.lineno, b.gets.chomp, b.lineno] #=> ["6", 6, "6", 9]
|
p [a.gets.chomp, a.lineno, b.gets.chomp, b.lineno] #=> ["6", 6, "6", 9]
|
||||||
SRC
|
SRC
|
||||||
expected = src.scan(/\#=> *(.+)/).flatten
|
|
||||||
ruby('-e', src, @t1.path, @t2.path, @t3.path) do |f|
|
|
||||||
f.each_with_index do |a, i|
|
|
||||||
assert_equal(expected.shift, a.chomp, "[ruby-dev:34445]: line #{i}")
|
|
||||||
end
|
|
||||||
|
|
||||||
assert_empty(expected, "[ruby-dev:34445]: remained")
|
|
||||||
|
|
||||||
# is this test OK? [ruby-dev:34445]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_lineno
|
def test_lineno
|
||||||
src = <<-SRC
|
assert_src_expected(__LINE__+1, <<-'SRC')
|
||||||
a = ARGF
|
a = ARGF
|
||||||
a.gets; p $. #=> 1
|
a.gets; p $. #=> 1
|
||||||
a.gets; p $. #=> 2
|
a.gets; p $. #=> 2
|
||||||
@ -102,14 +105,10 @@ class TestArgf < Test::Unit::TestCase
|
|||||||
a.gets; p $. #=> 2001
|
a.gets; p $. #=> 2001
|
||||||
a.gets; p $. #=> 2001
|
a.gets; p $. #=> 2001
|
||||||
SRC
|
SRC
|
||||||
expected = src.scan(/\#=> *(.+)/).join(",")
|
|
||||||
ruby('-e', src, @t1.path, @t2.path, @t3.path) do |f|
|
|
||||||
assert_equal(expected, f.read.chomp.gsub("\n", ","))
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_lineno2
|
def test_lineno2
|
||||||
src = <<-SRC
|
assert_src_expected(__LINE__+1, <<-'SRC')
|
||||||
a = ARGF.dup
|
a = ARGF.dup
|
||||||
a.gets; p $. #=> 1
|
a.gets; p $. #=> 1
|
||||||
a.gets; p $. #=> 2
|
a.gets; p $. #=> 2
|
||||||
@ -125,10 +124,6 @@ class TestArgf < Test::Unit::TestCase
|
|||||||
a.gets; p $. #=> 2000
|
a.gets; p $. #=> 2000
|
||||||
a.gets; p $. #=> 2000
|
a.gets; p $. #=> 2000
|
||||||
SRC
|
SRC
|
||||||
expected = src.scan(/\#=> *(.+)/).join(",")
|
|
||||||
ruby('-e', src, @t1.path, @t2.path, @t3.path) do |f|
|
|
||||||
assert_equal(expected, f.read.chomp.gsub("\n", ","))
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_inplace
|
def test_inplace
|
||||||
@ -304,73 +299,54 @@ class TestArgf < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_seek
|
def test_seek
|
||||||
ruby('-e', <<-SRC, @t1.path, @t2.path, @t3.path) do |f|
|
assert_src_expected(__LINE__+1, <<-'SRC')
|
||||||
ARGF.seek(4)
|
ARGF.seek(4)
|
||||||
p ARGF.gets #=> "3"
|
p ARGF.gets #=> "3\n"
|
||||||
ARGF.seek(0, IO::SEEK_END)
|
ARGF.seek(0, IO::SEEK_END)
|
||||||
p ARGF.gets #=> "5"
|
p ARGF.gets #=> "5\n"
|
||||||
ARGF.seek(4)
|
ARGF.seek(4)
|
||||||
p ARGF.gets #=> nil
|
p ARGF.gets #=> nil
|
||||||
begin
|
begin
|
||||||
ARGF.seek(0)
|
ARGF.seek(0)
|
||||||
rescue
|
rescue
|
||||||
puts "end"
|
puts "end" #=> end
|
||||||
end
|
end
|
||||||
SRC
|
SRC
|
||||||
a = f.read.split("\n")
|
|
||||||
assert_equal('"3\n"', a.shift)
|
|
||||||
assert_equal('"5\n"', a.shift)
|
|
||||||
assert_equal('nil', a.shift)
|
|
||||||
assert_equal('end', a.shift)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_set_pos
|
def test_set_pos
|
||||||
ruby('-e', <<-SRC, @t1.path, @t2.path, @t3.path) do |f|
|
assert_src_expected(__LINE__+1, <<-'SRC')
|
||||||
ARGF.pos = 4
|
ARGF.pos = 4
|
||||||
p ARGF.gets #=> "3"
|
p ARGF.gets #=> "3\n"
|
||||||
ARGF.pos = 4
|
ARGF.pos = 4
|
||||||
p ARGF.gets #=> "5"
|
p ARGF.gets #=> "5\n"
|
||||||
ARGF.pos = 4
|
ARGF.pos = 4
|
||||||
p ARGF.gets #=> nil
|
p ARGF.gets #=> nil
|
||||||
begin
|
begin
|
||||||
ARGF.pos = 4
|
ARGF.pos = 4
|
||||||
rescue
|
rescue
|
||||||
puts "end"
|
puts "end" #=> end
|
||||||
end
|
end
|
||||||
SRC
|
SRC
|
||||||
a = f.read.split("\n")
|
|
||||||
assert_equal('"3\n"', a.shift)
|
|
||||||
assert_equal('"5\n"', a.shift)
|
|
||||||
assert_equal('nil', a.shift)
|
|
||||||
assert_equal('end', a.shift)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_rewind
|
def test_rewind
|
||||||
ruby('-e', <<-SRC, @t1.path, @t2.path, @t3.path) do |f|
|
assert_src_expected(__LINE__+1, <<-'SRC')
|
||||||
ARGF.pos = 4
|
ARGF.pos = 4
|
||||||
ARGF.rewind
|
ARGF.rewind
|
||||||
p ARGF.gets #=> "1"
|
p ARGF.gets #=> "1\n"
|
||||||
ARGF.pos = 4
|
ARGF.pos = 4
|
||||||
p ARGF.gets #=> "3"
|
p ARGF.gets #=> "3\n"
|
||||||
ARGF.pos = 4
|
ARGF.pos = 4
|
||||||
p ARGF.gets #=> "5"
|
p ARGF.gets #=> "5\n"
|
||||||
ARGF.pos = 4
|
ARGF.pos = 4
|
||||||
p ARGF.gets #=> nil
|
p ARGF.gets #=> nil
|
||||||
begin
|
begin
|
||||||
ARGF.rewind
|
ARGF.rewind
|
||||||
rescue
|
rescue
|
||||||
puts "end"
|
puts "end" #=> end
|
||||||
end
|
end
|
||||||
SRC
|
SRC
|
||||||
a = f.read.split("\n")
|
|
||||||
assert_equal('"1\n"', a.shift)
|
|
||||||
assert_equal('"3\n"', a.shift)
|
|
||||||
assert_equal('"5\n"', a.shift)
|
|
||||||
assert_equal('nil', a.shift)
|
|
||||||
assert_equal('end', a.shift)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_fileno
|
def test_fileno
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#define RUBY_VERSION "1.9.2"
|
#define RUBY_VERSION "1.9.2"
|
||||||
#define RUBY_RELEASE_DATE "2009-08-30"
|
#define RUBY_RELEASE_DATE "2009-08-31"
|
||||||
#define RUBY_PATCHLEVEL -1
|
#define RUBY_PATCHLEVEL -1
|
||||||
#define RUBY_BRANCH_NAME "trunk"
|
#define RUBY_BRANCH_NAME "trunk"
|
||||||
|
|
||||||
@ -8,7 +8,7 @@
|
|||||||
#define RUBY_VERSION_TEENY 1
|
#define RUBY_VERSION_TEENY 1
|
||||||
#define RUBY_RELEASE_YEAR 2009
|
#define RUBY_RELEASE_YEAR 2009
|
||||||
#define RUBY_RELEASE_MONTH 8
|
#define RUBY_RELEASE_MONTH 8
|
||||||
#define RUBY_RELEASE_DAY 30
|
#define RUBY_RELEASE_DAY 31
|
||||||
|
|
||||||
#include "ruby/version.h"
|
#include "ruby/version.h"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user