summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-01-30 03:21:15 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-01-30 03:21:15 +0000
commit5a48f20c33ad9a70cfc0353689a63d044e2412d2 (patch)
tree3e9610afe1a45946f367def35c7d5cfab1f0d740
parent62acbb9805be958a784d9e7cea97be90239aefc4 (diff)
test for prompt
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57457 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--test/irb/test_ruby-lex.rb47
1 files changed, 47 insertions, 0 deletions
diff --git a/test/irb/test_ruby-lex.rb b/test/irb/test_ruby-lex.rb
index 79528676e49..d1355549b7a 100644
--- a/test/irb/test_ruby-lex.rb
+++ b/test/irb/test_ruby-lex.rb
@@ -9,6 +9,10 @@ module TestIRB
@scanner = RubyLex.new
end
+ def teardown
+ RubyLex.debug_level = 0
+ end
+
def test_set_input_proc
called = false
@scanner.set_input(nil) {called = true; nil}
@@ -40,6 +44,49 @@ module TestIRB
assert_equal([[src, 1]], top_level_statement(src))
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)
input = InputLines.new(lines, "r")
scanned = []