blob: ba6774544ed5f58b71b297060e52de4605fae9fa (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# 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 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
|