Skip to content

Commit

Permalink
Add dedicated tests for input recognition logic
Browse files Browse the repository at this point in the history
  • Loading branch information
st0012 committed Dec 7, 2023
1 parent a955ee2 commit 8016358
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions test/irb/test_irb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -738,4 +738,56 @@ def build_irb
IRB::Irb.new(workspace, TestInputMethod.new)
end
end

class InputCategorisationTest < TestCase
def test_irb_distinguihes_commands_and_non_commands_correctly
irb = build_irb

[
"show_source Foo#bar",
"show_source Foo#bar -s",
"show_source Foo.bar",
"show_source Foo.bar -s",
"show_source == -s",
"show_source =~ -s",
"ls foo.bar -g baz",
"ls -g foo",
"bt 4",
"bt"
].each do |input|
statement = irb.build_statement(input)
assert_equal(IRB::Statement::Command, statement.class, "Expected #{input} to be a command")
end

[
"info + 1",
"info - 1",
"info = 1",
"info = -1",
"info = /regex/",
"info = a",
"info += a",
"info -= a",
"info &&= a",
"info ||= a",
].each do |input|
statement = irb.build_statement(input)
assert_equal(IRB::Statement::Expression, statement.class, "Expected #{input} to not be a command")
end
end

private

def build_binding
Object.new.instance_eval { binding }
end

def build_irb
IRB.init_config(nil)
workspace = IRB::WorkSpace.new(build_binding)

IRB.conf[:VERBOSE] = false
IRB::Irb.new(workspace, TestInputMethod.new)
end
end
end

0 comments on commit 8016358

Please sign in to comment.