[前][次][番号順一覧][スレッド一覧]

ruby-changes:59301

From: Nobuyoshi <ko1@a...>
Date: Tue, 17 Dec 2019 19:52:24 +0900 (JST)
Subject: [ruby-changes:59301] ec89a0f803 (master): [ruby/io-console] Added the test for intr option

https://git.ruby-lang.org/ruby.git/commit/?id=ec89a0f803

From ec89a0f8033215817d9c6f9300d9513178e785b7 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Fri, 13 Dec 2019 12:14:10 +0900
Subject: [ruby/io-console] Added the test for intr option

https://github.com/ruby/io-console/commit/4f01db102d

diff --git a/test/io/console/test_io_console.rb b/test/io/console/test_io_console.rb
index 165012d..eab0fb6 100644
--- a/test/io/console/test_io_console.rb
+++ b/test/io/console/test_io_console.rb
@@ -319,6 +319,42 @@ defined?(PTY) and defined?(IO.console) and TestIO_Console.class_eval do https://github.com/ruby/ruby/blob/trunk/test/io/console/test_io_console.rb#L319
     end
   end
 
+  def assert_ctrl(expect, cc, r, w)
+    sleep 0.1
+    w.print cc
+    w.flush
+    result = EnvUtil.timeout(3) {r.gets}
+    assert_equal(expect, result.chomp)
+  end
+
+  def test_intr
+    run_pty("#{<<~"begin;"}\n#{<<~'end;'}") do |r, w, _|
+      begin;
+        STDOUT.puts `stty -a`.scan(/\b\w+ *= *\^.;/), ""
+        STDOUT.flush
+        while c = STDIN.getch
+          p c.ord
+          p STDIN.getch(intr: false).ord
+          begin
+            p STDIN.getch(intr: true).ord
+          rescue Interrupt => e
+            p e
+          end
+        end
+      end;
+      ctrl = {}
+      r.each do |l|
+        break unless /^(\w+) *= *\^(\\?.)/ =~ l
+        ctrl[$1] = eval("?\\C-#$2")
+      end
+      if cc = ctrl["intr"]
+        assert_ctrl("#{cc.ord}", cc, r, w)
+        assert_ctrl("#{cc.ord}", cc, r, w)
+        assert_ctrl("Interrupt", cc, r, w)
+      end
+    end
+  end
+
   unless IO.console
     def test_close
       assert_equal(["true"], run_pty("IO.console.close; p IO.console.fileno >= 0"))
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]