Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify the test builder so that the line numbers are displayed correctly in the generated file #225

Merged
merged 4 commits into from
Aug 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions test/debug/config_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ class SetTest < TestCase
def program
<<~RUBY
1| def foo
1| bar
2| end
3| def bar
4| p :bar
5| end
6| foo
2| bar
3| end
4| def bar
5| p :bar
6| end
7| foo
RUBY
end

Expand Down
36 changes: 18 additions & 18 deletions test/debug/record_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ class RecordOnOffTest < TestCase
def program
<<~RUBY
1|
1| p a = 1
2| p a += 1
3| binding.b do: 'record on'
4| p a += 1
2| p a = 1
3| p a += 1
4| binding.b do: 'record on'
5| p a += 1
6| binding.b
7| p a += 1
6| p a += 1
7| binding.b
8| p a += 1
9| p a += 1
RUBY
end

Expand Down Expand Up @@ -65,18 +65,18 @@ class RecordTest < TestCase
def program
<<~RUBY
1|
1| def foo n
2| n += 10
3| bar n + 1
4| end
5|
6| def bar n
7| n += 100
8| p n
9| end
10|
11| foo 10
12|
2| def foo n
3| n += 10
4| bar n + 1
5| end
6|
7| def bar n
8| n += 100
9| p n
10| end
11|
12| foo 10
13|
RUBY
end

Expand Down
15 changes: 7 additions & 8 deletions test/tool/test_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,25 +149,24 @@ def #{@method}

def format_program
lines = File.read(@debuggee).split("\n")
indent_num = 8
if lines.length > 9
first_l = " 1| #{lines[0]}\n"
indent_num = 9
first_l + lines[1..].map.with_index{|l, i|
if i < 9
single_digit_line_num_temp(indent_num, i, l)
if i < 8
line_num_temp(indent_num + 1, i, l)
else
"#{' ' * (indent_num - 1)}#{i + 1}| #{l}"
line_num_temp(indent_num, i, l)
end
}.join("\n")
else
first_l = "1| #{lines[0]}\n"
indent_num = 8
first_l + lines[1..].map.with_index{ |l, i| single_digit_line_num_temp(indent_num, i, l) }.join("\n")
first_l + lines[1..].map.with_index{ |l, i| line_num_temp(indent_num, i, l) }.join("\n")
end
end

def single_digit_line_num_temp(indent_num, index, line)
"#{' ' * indent_num}#{index + 1}| #{line}"
def line_num_temp(indent_num, index, line)
"#{' ' * indent_num}#{index + 2}| #{line}"
end

def content_with_module
Expand Down