summaryrefslogtreecommitdiff
path: root/spec/syntax_suggest/unit
diff options
context:
space:
mode:
authorschneems <[email protected]>2023-04-14 17:32:45 -0500
committerHiroshi SHIBATA <[email protected]>2023-04-25 14:43:06 +0900
commit3d5febf65b46f1a76759aa68d10f0888748831ab (patch)
tree9c4828657ec31154f7529476c7bde8f77181e529 /spec/syntax_suggest/unit
parentf77dc6fb1630f01c2b5dd1a407931c829ad6e77c (diff)
[ruby/syntax_suggest] Clean up output
I previously left a comment stating I didn't know why a certain method existed. In investigating the code in `CaptureCodeContext#capture_before_after_kws` I found that it was added as to give a slightly less noisy output. The docs for AroundBlockScan#capture_neighbor_context only describe keywords as being a primary concern. I modified that code to only include lines that are keywords or ends. This reduces the output noise even more. This allows me to remove that `start_at_next_line` method. One weird side effect of the prior logic is it would cause this code to produce this output: ``` class OH def hello def hai end end ``` ``` 1 class OH > 2 def hello 4 def hai 5 end 6 end ``` But this code to produce this output: ``` class OH def hello def hai end end ``` ``` 1 class OH > 2 def hello 4 end 5 end ``` Note the missing `def hai`. The only difference between them is that space. With this change, they're now both consistent. https://github.com/ruby/syntax_suggest/commit/4a54767a3e
Diffstat (limited to 'spec/syntax_suggest/unit')
-rw-r--r--spec/syntax_suggest/unit/capture_code_context_spec.rb5
-rw-r--r--spec/syntax_suggest/unit/display_invalid_blocks_spec.rb2
2 files changed, 5 insertions, 2 deletions
diff --git a/spec/syntax_suggest/unit/capture_code_context_spec.rb b/spec/syntax_suggest/unit/capture_code_context_spec.rb
index e1bc281c13..1563149b3c 100644
--- a/spec/syntax_suggest/unit/capture_code_context_spec.rb
+++ b/spec/syntax_suggest/unit/capture_code_context_spec.rb
@@ -16,13 +16,14 @@ module SyntaxSuggest
EOM
code_lines = CleanDocument.new(source: source).call.lines
- block = CodeBlock.new(lines: code_lines[0])
+ block = CodeBlock.new(lines: code_lines[3])
display = CaptureCodeContext.new(
blocks: [block],
code_lines: code_lines
)
- lines = display.call
+
+ lines = display.capture_before_after_kws(block).sort
expect(lines.join).to eq(<<~'EOM')
def sit
end
diff --git a/spec/syntax_suggest/unit/display_invalid_blocks_spec.rb b/spec/syntax_suggest/unit/display_invalid_blocks_spec.rb
index 2c59d9dc78..b11d7d242e 100644
--- a/spec/syntax_suggest/unit/display_invalid_blocks_spec.rb
+++ b/spec/syntax_suggest/unit/display_invalid_blocks_spec.rb
@@ -144,6 +144,7 @@ module SyntaxSuggest
expect(io.string).to include([
" 1 class OH",
"> 2 def hello",
+ " 3 def hai",
" 4 end",
" 5 end",
""
@@ -162,6 +163,7 @@ module SyntaxSuggest
[
" 1 class OH",
["> 2 ", DisplayCodeWithLineNumbers::TERMINAL_HIGHLIGHT, " def hello"].join,
+ " 3 def hai",
" 4 end",
" 5 end",
""