summaryrefslogtreecommitdiff
path: root/spec/syntax_suggest/unit/capture/falling_indent_lines_spec.rb
blob: ed2265539aeb2eca3fa41eada42aaea30881e2c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# frozen_string_literal: true

require_relative "../../spec_helper"

module SyntaxSuggest
  RSpec.describe Capture::FallingIndentLines 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 = []
      Capture::FallingIndentLines.new(
        block: block,
        code_lines: code_lines
      ).call do |line|
        lines << line
      end
      lines.sort!

      expect(lines.join).to eq(<<~EOM)
        class OH
          def hello
          end
        end
      EOM
    end
  end
end