summaryrefslogtreecommitdiff
path: root/spec/syntax_suggest/unit
diff options
context:
space:
mode:
Diffstat (limited to 'spec/syntax_suggest/unit')
-rw-r--r--spec/syntax_suggest/unit/around_block_scan_spec.rb41
-rw-r--r--spec/syntax_suggest/unit/capture_code_context_spec.rb26
2 files changed, 65 insertions, 2 deletions
diff --git a/spec/syntax_suggest/unit/around_block_scan_spec.rb b/spec/syntax_suggest/unit/around_block_scan_spec.rb
index 88d973e151..c9241bc8ee 100644
--- a/spec/syntax_suggest/unit/around_block_scan_spec.rb
+++ b/spec/syntax_suggest/unit/around_block_scan_spec.rb
@@ -4,6 +4,43 @@ require_relative "../spec_helper"
module SyntaxSuggest
RSpec.describe AroundBlockScan do
+ it "on_falling_indent" do
+ source = <<~'EOM'
+ class OH
+ def lol
+ print 'lol
+ end
+
+ def hello
+ it "foo" do
+ end
+
+ def yolo
+ print 'haha'
+ end
+ end
+ EOM
+
+ code_lines = CleanDocument.new(source: source).call.lines
+ block = CodeBlock.new(lines: code_lines[6])
+
+ lines = []
+ AroundBlockScan.new(
+ block: block,
+ code_lines: code_lines
+ ).on_falling_indent do |line|
+ lines << line
+ end
+ lines.sort!
+
+ expect(lines.join).to eq(<<~'EOM')
+ class OH
+ def hello
+ end
+ end
+ EOM
+ end
+
it "continues scan from last location even if scan is false" do
source = <<~'EOM'
print 'omg'
@@ -104,8 +141,8 @@ module SyntaxSuggest
expand = AroundBlockScan.new(code_lines: code_lines, block: block)
expand.scan_while { true }
- expect(expand.before_index).to eq(0)
- expect(expand.after_index).to eq(6)
+ expect(expand.lines.first.index).to eq(0)
+ expect(expand.lines.last.index).to eq(6)
expect(expand.code_block.to_s).to eq(source_string)
end
diff --git a/spec/syntax_suggest/unit/capture_code_context_spec.rb b/spec/syntax_suggest/unit/capture_code_context_spec.rb
index 1563149b3c..46f13e8961 100644
--- a/spec/syntax_suggest/unit/capture_code_context_spec.rb
+++ b/spec/syntax_suggest/unit/capture_code_context_spec.rb
@@ -4,6 +4,32 @@ require_relative "../spec_helper"
module SyntaxSuggest
RSpec.describe CaptureCodeContext do
+ it "capture_before_after_kws two" do
+ source = <<~'EOM'
+ class OH
+
+ def hello
+
+ def hai
+ end
+ end
+ EOM
+
+ code_lines = CleanDocument.new(source: source).call.lines
+ block = CodeBlock.new(lines: code_lines[2])
+
+ display = CaptureCodeContext.new(
+ blocks: [block],
+ code_lines: code_lines
+ )
+ display.capture_before_after_kws(block)
+ expect(display.sorted_lines.join).to eq(<<~'EOM'.indent(2))
+ def hello
+ def hai
+ end
+ EOM
+ end
+
it "capture_before_after_kws" do
source = <<~'EOM'
def sit