1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/test/irb/test_ruby-lex.rb
nobu 62acbb9805 test for immature statement
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57456 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-01-29 12:53:24 +00:00

58 lines
1.3 KiB
Ruby

# frozen_string_literal: false
require 'test/unit'
require 'irb/ruby-lex'
require 'stringio'
module TestIRB
class TestRubyLex < Test::Unit::TestCase
def setup
@scanner = RubyLex.new
end
def test_set_input_proc
called = false
@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 test_top_level_statement
result = top_level_statement("#{<<-"begin;"}#{<<~"end;"}")
begin;
begin
end
begin
end
end;
assert_equal([
["begin\n""end\n", 1],
["begin\n""end\n", 3],
],
result)
end
def test_immature_statement
src = "if false\n"
assert_equal([[src, 1]], top_level_statement(src))
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