|
5 | 5 |
|
6 | 6 | module TestIRB |
7 | 7 | class TestRubyLex < Test::Unit::TestCase |
8 | | - Row = Struct.new(:content, :current_line_spaces, :new_line_spaces) |
| 8 | + Row = Struct.new(:content, :current_line_spaces, :new_line_spaces, :nesting_level) |
9 | 9 |
|
10 | 10 | class MockIO |
11 | 11 | def initialize(params, &assertion) |
@@ -34,6 +34,15 @@ def assert_indenting(lines, correct_space_count, add_new_line) |
34 | 34 | ruby_lex.set_auto_indent(context) |
35 | 35 | end |
36 | 36 |
|
| 37 | + def assert_nesting_level(lines, expected) |
| 38 | + ruby_lex = RubyLex.new() |
| 39 | + io = proc{ lines.join("\n") } |
| 40 | + ruby_lex.set_input(io, io) |
| 41 | + ruby_lex.lex |
| 42 | + error_message = "Calculated the wrong number of nesting level for:\n #{lines.join("\n")}" |
| 43 | + assert_equal(expected, ruby_lex.instance_variable_get(:@indent), error_message) |
| 44 | + end |
| 45 | + |
37 | 46 | def test_auto_indent |
38 | 47 | input_with_correct_indents = [ |
39 | 48 | Row.new(%q(def each_top_level_statement), nil, 2), |
@@ -237,17 +246,18 @@ def test_oneliner_method_definition |
237 | 246 |
|
238 | 247 | def test_tlambda |
239 | 248 | input_with_correct_indents = [ |
240 | | - Row.new(%q(if true), nil, 2), |
241 | | - Row.new(%q( -> {), nil, 4), |
242 | | - Row.new(%q( }), 2, 2), |
243 | | - Row.new(%q(end), 0, 0), |
| 249 | + Row.new(%q(if true), nil, 2, 1), |
| 250 | + Row.new(%q( -> {), nil, 4, 2), |
| 251 | + Row.new(%q( }), 2, 2, 1), |
| 252 | + Row.new(%q(end), 0, 0, 0), |
244 | 253 | ] |
245 | 254 |
|
246 | 255 | lines = [] |
247 | 256 | input_with_correct_indents.each do |row| |
248 | 257 | lines << row.content |
249 | 258 | assert_indenting(lines, row.current_line_spaces, false) |
250 | 259 | assert_indenting(lines, row.new_line_spaces, true) |
| 260 | + assert_nesting_level(lines, row.nesting_level) |
251 | 261 | end |
252 | 262 | end |
253 | 263 | end |
|
0 commit comments