aboutsummaryrefslogtreecommitdiffstats
path: root/test/irb/test_ruby_lex.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/irb/test_ruby_lex.rb')
-rw-r--r--test/irb/test_ruby_lex.rb29
1 files changed, 22 insertions, 7 deletions
diff --git a/test/irb/test_ruby_lex.rb b/test/irb/test_ruby_lex.rb
index 1388d08962..5d66dc5bb0 100644
--- a/test/irb/test_ruby_lex.rb
+++ b/test/irb/test_ruby_lex.rb
@@ -24,13 +24,14 @@ module TestIRB
last_line_index = lines.length - 1
byte_pointer = lines.last.length
+ context = build_context
+ context.auto_indent_mode = true
ruby_lex = RubyLex.new()
io = MockIO_AutoIndent.new([lines, last_line_index, byte_pointer, add_new_line]) do |auto_indent|
error_message = "Calculated the wrong number of spaces for:\n #{lines.join("\n")}"
assert_equal(correct_space_count, auto_indent, error_message)
end
- ruby_lex.set_input(io)
- context = OpenStruct.new(auto_indent_mode: true)
+ ruby_lex.set_input(io, context: context)
ruby_lex.set_auto_indent(context)
end
@@ -48,11 +49,10 @@ module TestIRB
def ruby_lex_for_lines(lines, local_variables: [])
ruby_lex = RubyLex.new()
+
+ context = build_context(local_variables)
io = proc{ lines.join("\n") }
- ruby_lex.set_input(io, io)
- unless local_variables.empty?
- context = OpenStruct.new(local_variables: local_variables)
- end
+ ruby_lex.set_input(io, io, context: context)
ruby_lex.lex(context)
ruby_lex
end
@@ -620,7 +620,8 @@ module TestIRB
ruby_lex.set_prompt do |ltype, indent, continue, line_no|
'%03d:%01d:%1s:%s ' % [line_no, indent, ltype, continue ? '*' : '>']
end
- ruby_lex.set_input(io)
+ context = build_context
+ ruby_lex.set_input(io, context: context)
end
def test_dyanmic_prompt
@@ -697,5 +698,19 @@ module TestIRB
assert_equal('<<A', string_literal&.tok)
end
end
+
+ private
+
+ def build_context(local_variables = nil)
+ workspace = IRB::WorkSpace.new
+
+ if local_variables
+ local_variables.each do |n|
+ workspace.binding.local_variable_set(n, nil)
+ end
+ end
+
+ IRB::Context.new(nil, workspace)
+ end
end
end