From 3abb4948b248da896e0bf03de6caf147543a5432 Mon Sep 17 00:00:00 2001 From: nobu Date: Sun, 29 Jan 2017 12:20:26 +0000 Subject: test for comment git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57454 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/irb/test_ruby-lex.rb | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'test/irb') 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 -- cgit v1.2.3