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 10, 2023
1 parent 548e170 commit 715526b
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions test/irb/test_irb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -738,4 +738,62 @@ 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",
"info ||= a",
"info # comment",
"info if foo",
"info ? foo : bar",
"info ; foo",
"info ,other = expr"
].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 715526b

Please sign in to comment.