mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
test for prompt
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57457 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
62acbb9805
commit
5a48f20c33
1 changed files with 47 additions and 0 deletions
|
@ -9,6 +9,10 @@ module TestIRB
|
||||||
@scanner = RubyLex.new
|
@scanner = RubyLex.new
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def teardown
|
||||||
|
RubyLex.debug_level = 0
|
||||||
|
end
|
||||||
|
|
||||||
def test_set_input_proc
|
def test_set_input_proc
|
||||||
called = false
|
called = false
|
||||||
@scanner.set_input(nil) {called = true; nil}
|
@scanner.set_input(nil) {called = true; nil}
|
||||||
|
@ -40,6 +44,49 @@ module TestIRB
|
||||||
assert_equal([[src, 1]], top_level_statement(src))
|
assert_equal([[src, 1]], top_level_statement(src))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_prompt
|
||||||
|
prompts = []
|
||||||
|
@scanner.set_prompt {|*a|
|
||||||
|
a << @scanner.instance_variable_get(:@lex_state)
|
||||||
|
unless prompts.last == a
|
||||||
|
prompts << a
|
||||||
|
end
|
||||||
|
}
|
||||||
|
src = "#{<<-"begin;"}#{<<~"end;"}"
|
||||||
|
begin;
|
||||||
|
if false or
|
||||||
|
true
|
||||||
|
"
|
||||||
|
"
|
||||||
|
'
|
||||||
|
'
|
||||||
|
else
|
||||||
|
nil
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
end;
|
||||||
|
assert_equal([[src, 1]], top_level_statement(src))
|
||||||
|
expected = [
|
||||||
|
[nil, 0, false],
|
||||||
|
[nil, 1, true],
|
||||||
|
[nil, 1, false],
|
||||||
|
['"', 1, false],
|
||||||
|
[nil, 1, false],
|
||||||
|
["'", 1, false],
|
||||||
|
[nil, 1, false],
|
||||||
|
[nil, 1, true], # FIXME: just after `else' should be `false'
|
||||||
|
[nil, 1, false],
|
||||||
|
[nil, 1, false],
|
||||||
|
[nil, 0, false],
|
||||||
|
]
|
||||||
|
srcs = src.lines
|
||||||
|
assert_equal(expected.size, prompts.size)
|
||||||
|
expected.each_with_index {|e, i|
|
||||||
|
assert_equal(i + 1, prompts[i][3])
|
||||||
|
assert_equal(e, prompts[i][0..2], "#{i+1}: #{srcs[i]} # #{prompts[i]}")
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
def top_level_statement(lines)
|
def top_level_statement(lines)
|
||||||
input = InputLines.new(lines, "r")
|
input = InputLines.new(lines, "r")
|
||||||
scanned = []
|
scanned = []
|
||||||
|
|
Loading…
Reference in a new issue