summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorStan Lo <stan001212@gmail.com>2023-08-21 16:42:10 +0100
committergit <svn-admin@ruby-lang.org>2023-08-21 15:42:15 +0000
commit86ac17efde6cf98903513cac2538b15fc4ac80b2 (patch)
treeb683fd78c5380b3c61159001e4103f96d7bcd2a5 /test
parent2929c47243e30000ca4e273608b478cf8da42207 (diff)
[ruby/irb] Move input processing out of RubyLex
(https://github.com/ruby/irb/pull/683) * Add a test case for Ctrl-C handling * Test symbol aliases with integration tests There are a few places that also need to check symbol aliases before `Irb#eval_input`. But since the current command test skip them, we don't have test coverage on them. * Move each_top_level_statement and readmultiline to Irb This will save RubyLex from knowning information about commands and aliases. https://github.com/ruby/irb/commit/69cb5b5615
Diffstat (limited to 'test')
-rw-r--r--test/irb/test_cmd.rb17
-rw-r--r--test/irb/test_irb.rb61
-rw-r--r--test/irb/yamatanooroti/test_rendering.rb16
3 files changed, 77 insertions, 17 deletions
diff --git a/test/irb/test_cmd.rb b/test/irb/test_cmd.rb
index 272f6d3ace..670078679f 100644
--- a/test/irb/test_cmd.rb
+++ b/test/irb/test_cmd.rb
@@ -62,23 +62,6 @@ module TestIRB
end
end
- class CommnadAliasTest < CommandTestCase
- def test_vars_with_aliases
- @foo = "foo"
- $bar = "bar"
- out, err = execute_lines(
- "@foo\n",
- "$bar\n",
- )
- assert_empty err
- assert_match(/"foo"/, out)
- assert_match(/"bar"/, out)
- ensure
- remove_instance_variable(:@foo)
- $bar = nil
- end
- end
-
class InfoTest < CommandTestCase
def setup
super
diff --git a/test/irb/test_irb.rb b/test/irb/test_irb.rb
index b613cc8a9a..c685912093 100644
--- a/test/irb/test_irb.rb
+++ b/test/irb/test_irb.rb
@@ -4,6 +4,67 @@ require "irb"
require_relative "helper"
module TestIRB
+ class InputTest < IntegrationTestCase
+ def test_symbol_aliases_are_handled_correctly
+ write_ruby <<~'RUBY'
+ class Foo
+ end
+ binding.irb
+ RUBY
+
+ output = run_ruby_file do
+ type "$ Foo"
+ type "exit!"
+ end
+
+ assert_include output, "From: #{@ruby_file.path}:1"
+ end
+
+ def test_symbol_aliases_are_handled_correctly_with_singleline_mode
+ @irbrc = Tempfile.new('irbrc')
+ @irbrc.write <<~RUBY
+ IRB.conf[:USE_SINGLELINE] = true
+ RUBY
+ @irbrc.close
+ @envs['IRBRC'] = @irbrc.path
+
+ write_ruby <<~'RUBY'
+ class Foo
+ end
+ binding.irb
+ RUBY
+
+ output = run_ruby_file do
+ type "irb_info"
+ type "$ Foo"
+ type "exit!"
+ end
+
+ # Make sure it's tested in singleline mode
+ assert_include output, "InputMethod: ReadlineInputMethod"
+ assert_include output, "From: #{@ruby_file.path}:1"
+ ensure
+ @irbrc.unlink if @irbrc
+ end
+
+ def test_symbol_aliases_dont_affect_ruby_syntax
+ write_ruby <<~'RUBY'
+ $foo = "It's a foo"
+ @bar = "It's a bar"
+ binding.irb
+ RUBY
+
+ output = run_ruby_file do
+ type "$foo"
+ type "@bar"
+ type "exit!"
+ end
+
+ assert_include output, "=> \"It's a foo\""
+ assert_include output, "=> \"It's a bar\""
+ end
+ end
+
class IrbIOConfigurationTest < TestCase
Row = Struct.new(:content, :current_line_spaces, :new_line_spaces, :indent_level)
diff --git a/test/irb/yamatanooroti/test_rendering.rb b/test/irb/yamatanooroti/test_rendering.rb
index 6da7fded2b..3da3935c19 100644
--- a/test/irb/yamatanooroti/test_rendering.rb
+++ b/test/irb/yamatanooroti/test_rendering.rb
@@ -251,6 +251,22 @@ class IRB::RenderingTest < Yamatanooroti::TestCase
EOC
end
+ def test_ctrl_c_is_handled
+ write_irbrc <<~'LINES'
+ puts 'start IRB'
+ LINES
+ start_terminal(40, 80, %W{ruby -I#{@pwd}/lib #{@pwd}/exe/irb}, startup_message: 'start IRB')
+ # Assignment expression code that turns into non-assignment expression after evaluation
+ write("\C-c")
+ close
+ assert_screen(<<~EOC)
+ start IRB
+ irb(main):001>
+ ^C
+ irb(main):001>
+ EOC
+ end
+
def test_show_cmds_with_pager_can_quit_with_ctrl_c
write_irbrc <<~'LINES'
puts 'start IRB'