2015-12-16 00:07:31 -05:00
|
|
|
# frozen_string_literal: false
|
2004-03-01 07:24:42 -05:00
|
|
|
# $Id$
|
|
|
|
#
|
|
|
|
# scanf for Ruby
|
|
|
|
#
|
|
|
|
# Ad hoc tests of IO#scanf (needs to be expanded)
|
|
|
|
|
2019-06-27 23:37:07 -04:00
|
|
|
require 'test/unit'
|
|
|
|
require 'scanf'
|
2004-03-02 06:21:32 -05:00
|
|
|
|
2009-10-20 23:44:56 -04:00
|
|
|
class TestScanfIO < Test::Unit::TestCase
|
2004-03-02 06:21:32 -05:00
|
|
|
def test_io
|
2019-06-27 23:37:36 -04:00
|
|
|
File.open(File.join(File.dirname(__FILE__), "data.txt"), "r") do |fh|
|
|
|
|
assert_equal(0, fh.pos)
|
|
|
|
assert_equal(["this", "is"], fh.scanf("%s%s"))
|
|
|
|
assert_equal([33, "little"], fh.scanf("%da fun%s"))
|
|
|
|
end
|
2004-03-02 06:21:32 -05:00
|
|
|
end
|
2019-06-14 20:50:31 -04:00
|
|
|
|
|
|
|
def test_pipe_scanf
|
2019-06-27 23:37:36 -04:00
|
|
|
IO.pipe do |r, w|
|
|
|
|
w.write('a')
|
|
|
|
w.close
|
|
|
|
assert_equal([], r.scanf('a'))
|
|
|
|
end
|
2019-06-14 20:50:31 -04:00
|
|
|
end
|
2004-03-02 06:21:32 -05:00
|
|
|
end
|
|
|
|
|