mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
test for comment
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57454 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
25ad4a7907
commit
3abb4948b2
1 changed files with 22 additions and 2 deletions
|
@ -1,6 +1,7 @@
|
||||||
# frozen_string_literal: false
|
# frozen_string_literal: false
|
||||||
require 'test/unit'
|
require 'test/unit'
|
||||||
require 'irb/ruby-lex'
|
require 'irb/ruby-lex'
|
||||||
|
require 'stringio'
|
||||||
|
|
||||||
module TestIRB
|
module TestIRB
|
||||||
class TestRubyLex < Test::Unit::TestCase
|
class TestRubyLex < Test::Unit::TestCase
|
||||||
|
@ -10,9 +11,28 @@ module TestIRB
|
||||||
|
|
||||||
def test_set_input_proc
|
def test_set_input_proc
|
||||||
called = false
|
called = false
|
||||||
@scanner.set_input(self) {|x| called = true; nil}
|
@scanner.set_input(nil) {called = true; nil}
|
||||||
assert_nil(@scanner.lex)
|
@scanner.each_top_level_statement {}
|
||||||
assert(called)
|
assert(called)
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue