summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test/irb/test_ruby-lex.rb24
1 files changed, 22 insertions, 2 deletions
diff --git a/test/irb/test_ruby-lex.rb b/test/irb/test_ruby-lex.rb
index f7d331bc24..b5255e9b53 100644
--- a/test/irb/test_ruby-lex.rb
+++ b/test/irb/test_ruby-lex.rb
@@ -1,6 +1,7 @@
# frozen_string_literal: false
require 'test/unit'
require 'irb/ruby-lex'
+require 'stringio'
module TestIRB
class TestRubyLex < Test::Unit::TestCase
@@ -10,9 +11,28 @@ module TestIRB
def test_set_input_proc
called = false
- @scanner.set_input(self) {|x| called = true; nil}
- assert_nil(@scanner.lex)
+ @scanner.set_input(nil) {called = true; nil}
+ @scanner.each_top_level_statement {}
assert(called)
end
+
+ def test_comment
+ assert_equal([["#\n", 1]], top_level_statement("#\n"))
+ end
+
+ def top_level_statement(lines)
+ input = InputLines.new(lines, "r")
+ scanned = []
+ @scanner.set_input(input)
+ @scanner.each_top_level_statement {|*e|
+ scanned << e
+ yield(*e) if defined?(yield)
+ }
+ scanned
+ end
+
+ class InputLines < StringIO
+ alias encoding external_encoding
+ end
end
end