aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-02-03 07:54:18 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-02-03 07:54:18 +0000
commitf050b2232711c162ee380ba61ddb8554cb4f7719 (patch)
treeb9c878f7d576b5435781bcb996815dc647f87df1
parent47dc049f6190c2bdc68b734bab67bcf19d1df02c (diff)
downloadruby-f050b2232711c162ee380ba61ddb8554cb4f7719.tar.gz
console.c: fix unit of min
* ext/io/console/console.c (rawmode_opt): min is minimum characters, not tenths. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39029 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--ext/io/console/console.c3
-rw-r--r--test/io/console/test_io_console.rb32
3 files changed, 38 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index b1914f41b0..764ec81fbd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Sun Feb 3 16:54:15 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * ext/io/console/console.c (rawmode_opt): min is minimum characters,
+ not tenths.
+
Sun Feb 3 16:13:00 2013 Charlie Somerville <charlie@charliesomerville.com>
* doc/security.rdoc: add first cut at a Ruby security document
diff --git a/ext/io/console/console.c b/ext/io/console/console.c
index cedc057bb3..61b31258e6 100644
--- a/ext/io/console/console.c
+++ b/ext/io/console/console.c
@@ -105,13 +105,12 @@ rawmode_opt(int argc, VALUE *argv, rawmode_arg_t *opts)
if (!NIL_P(vopts)) {
VALUE vmin = rb_hash_aref(vopts, ID2SYM(rb_intern("min")));
VALUE vtime = rb_hash_aref(vopts, ID2SYM(rb_intern("time")));
- VALUE v10 = INT2FIX(10);
if (!NIL_P(vmin)) {
- vmin = rb_funcall3(vmin, '*', 1, &v10);
opts->vmin = NUM2INT(vmin);
optp = opts;
}
if (!NIL_P(vtime)) {
+ VALUE v10 = INT2FIX(10);
vtime = rb_funcall3(vtime, '*', 1, &v10);
opts->vtime = NUM2INT(vtime);
optp = opts;
diff --git a/test/io/console/test_io_console.rb b/test/io/console/test_io_console.rb
index 3acc4de5d5..2de15f1f24 100644
--- a/test/io/console/test_io_console.rb
+++ b/test/io/console/test_io_console.rb
@@ -25,6 +25,38 @@ class TestIO_Console < Test::Unit::TestCase
}
end
+ def test_raw_minchar
+ len = 0
+ th = nil
+ helper {|m, s|
+ th = Thread.start {
+ m.print("a")
+ len += 1
+ sleep 2
+ m.print("1234567890")
+ len += 10
+ }
+ assert_equal(["a", 1], [s.getch(min: 1), len])
+ }
+ ensure
+ th.kill if th and th.alive?
+ end
+
+ def test_raw_timeout
+ len = 0
+ th = nil
+ helper {|m, s|
+ th = Thread.start {
+ sleep 2
+ m.print("a")
+ len += 1
+ }
+ assert_equal([nil, 0], [s.getch(time: 0.1), len])
+ }
+ ensure
+ th.kill if th and th.alive?
+ end
+
def test_cooked
helper {|m, s|
assert_send([s, :echo?])