diff options
author | Stan Lo <stan001212@gmail.com> | 2024-03-01 23:51:14 +0800 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2024-03-01 15:51:29 +0000 |
commit | 57ca5960ad207beb0c4f2788df0e74f8cc6b7cac (patch) | |
tree | 32e39f039b6b53a967f37ed52bd10b2b84abd36e /test | |
parent | 162e13c884a1764e6cf6e62407e607d18f29eecc (diff) |
[ruby/irb] Restructure workspace management
(https://github.com/ruby/irb/pull/888)
* Remove dead irb_level method
* Restructure workspace management
Currently, workspace is an attribute of IRB::Context in most use cases.
But when some workspace commands are used, like `pushws` or `popws`, a
workspace will be created and used along side with the original workspace
attribute.
This complexity is not necessary and will prevent us from expanding
multi-workspace support in the future.
So this commit introduces a @workspace_stack ivar to IRB::Context so IRB
can have a more natural way to manage workspaces.
* Fix pushws without args
* Always display workspace stack after related commands are used
https://github.com/ruby/irb/commit/61560b99b3
Diffstat (limited to 'test')
-rw-r--r-- | test/irb/test_command.rb | 48 |
1 files changed, 27 insertions, 21 deletions
diff --git a/test/irb/test_command.rb b/test/irb/test_command.rb index e27fac67b7..d6c8c534f9 100644 --- a/test/irb/test_command.rb +++ b/test/irb/test_command.rb @@ -482,7 +482,8 @@ module TestIRB class CwwsTest < WorkspaceCommandTestCase def test_cwws_returns_the_current_workspace_object out, err = execute_lines( - "cwws.class", + "cwws", + "self.class" ) assert_empty err @@ -493,51 +494,56 @@ module TestIRB class PushwsTest < WorkspaceCommandTestCase def test_pushws_switches_to_new_workspace_and_pushes_the_current_one_to_the_stack out, err = execute_lines( - "pushws #{self.class}::Foo.new\n", - "cwws.class", + "pushws #{self.class}::Foo.new", + "self.class", + "popws", + "self.class" ) assert_empty err - assert_include(out, "#{self.class}::Foo") + + assert_match(/=> #{self.class}::Foo\n/, out) + assert_match(/=> #{self.class}\n$/, out) end def test_pushws_extends_the_new_workspace_with_command_bundle out, err = execute_lines( - "pushws Object.new\n", + "pushws Object.new", "self.singleton_class.ancestors" ) assert_empty err assert_include(out, "IRB::ExtendCommandBundle") end - def test_pushws_prints_help_message_when_no_arg_is_given + def test_pushws_prints_workspace_stack_when_no_arg_is_given out, err = execute_lines( - "pushws\n", + "pushws", ) assert_empty err - assert_match(/No other workspace/, out) + assert_include(out, "[#<TestIRB::PushwsTe...>]") end - end - class WorkspacesTest < WorkspaceCommandTestCase - def test_workspaces_returns_the_array_of_non_main_workspaces + def test_pushws_without_argument_swaps_the_top_two_workspaces out, err = execute_lines( - "pushws #{self.class}::Foo.new\n", - "workspaces.map { |w| w.class.name }", + "pushws #{self.class}::Foo.new", + "self.class", + "pushws", + "self.class" ) - assert_empty err - # self.class::Foo would be the current workspace - # self.class would be the old workspace that's pushed to the stack - assert_include(out, "=> [\"#{self.class}\"]") + assert_match(/=> #{self.class}::Foo\n/, out) + assert_match(/=> #{self.class}\n$/, out) end + end - def test_workspaces_returns_empty_array_when_no_workspaces_were_added + class WorkspacesTest < WorkspaceCommandTestCase + def test_workspaces_returns_the_stack_of_workspaces out, err = execute_lines( - "workspaces.map(&:to_s)", + "pushws #{self.class}::Foo.new\n", + "workspaces", ) assert_empty err - assert_include(out, "=> []") + assert_match(/\[#<TestIRB::Workspac...>, #<TestIRB::Workspac...>]\n/, out) end end @@ -557,7 +563,7 @@ module TestIRB "popws\n", ) assert_empty err - assert_match(/workspace stack empty/, out) + assert_match(/\[#<TestIRB::PopwsTes...>\]\n/, out) end end |