[ruby/syntax_suggest] Bump minimum Ruby version & update standardrb

https://github.com/ruby/syntax_suggest/commit/73753518e9
This commit is contained in:
Schneems 2023-12-04 16:19:20 -06:00 коммит произвёл git
Родитель 13482ab1e6
Коммит 5a2d70ef73
15 изменённых файлов: 89 добавлений и 89 удалений

Просмотреть файл

@ -117,7 +117,7 @@ module SyntaxSuggest
if ENV["SYNTAX_SUGGEST_DEBUG"] if ENV["SYNTAX_SUGGEST_DEBUG"]
puts "```" puts "```"
puts @queue.peek.to_s puts @queue.peek
puts "```" puts "```"
puts " @frontier indent: #{frontier_indent}" puts " @frontier indent: #{frontier_indent}"
puts " @unvisited indent: #{unvisited_indent}" puts " @unvisited indent: #{unvisited_indent}"

Просмотреть файл

@ -43,7 +43,7 @@ module SyntaxSuggest
def initialize(source, record_dir: DEFAULT_VALUE) def initialize(source, record_dir: DEFAULT_VALUE)
record_dir = if record_dir == DEFAULT_VALUE record_dir = if record_dir == DEFAULT_VALUE
ENV["SYNTAX_SUGGEST_RECORD_DIR"] || ENV["SYNTAX_SUGGEST_DEBUG"] ? "tmp" : nil (ENV["SYNTAX_SUGGEST_RECORD_DIR"] || ENV["SYNTAX_SUGGEST_DEBUG"]) ? "tmp" : nil
else else
record_dir record_dir
end end
@ -73,7 +73,7 @@ module SyntaxSuggest
if ENV["SYNTAX_SUGGEST_DEBUG"] if ENV["SYNTAX_SUGGEST_DEBUG"]
puts "\n\n==== #{filename} ====" puts "\n\n==== #{filename} ===="
puts "\n```#{block.starts_at}..#{block.ends_at}" puts "\n```#{block.starts_at}..#{block.ends_at}"
puts block.to_s puts block
puts "```" puts "```"
puts " block indent: #{block.current_indent}" puts " block indent: #{block.current_indent}"
end end

Просмотреть файл

@ -14,7 +14,7 @@ module SyntaxSuggest
@filename = filename @filename = filename
@code_lines = code_lines @code_lines = code_lines
@terminal = terminal == DEFAULT_VALUE ? io.isatty : terminal @terminal = (terminal == DEFAULT_VALUE) ? io.isatty : terminal
end end
def document_ok? def document_ok?

Просмотреть файл

@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
spec.description = 'When you get an "unexpected end" in your syntax this gem helps you find it' spec.description = 'When you get an "unexpected end" in your syntax this gem helps you find it'
spec.homepage = "https://github.com/ruby/syntax_suggest.git" spec.homepage = "https://github.com/ruby/syntax_suggest.git"
spec.license = "MIT" spec.license = "MIT"
spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0") spec.required_ruby_version = Gem::Requirement.new(">= 3.0.0")
spec.metadata["homepage_uri"] = spec.homepage spec.metadata["homepage_uri"] = spec.homepage
spec.metadata["source_code_uri"] = "https://github.com/ruby/syntax_suggest.git" spec.metadata["source_code_uri"] = "https://github.com/ruby/syntax_suggest.git"

Просмотреть файл

@ -9,7 +9,7 @@ module SyntaxSuggest
Dir.mktmpdir do |dir| Dir.mktmpdir do |dir|
tmpdir = Pathname(dir) tmpdir = Pathname(dir)
script = tmpdir.join("script.rb") script = tmpdir.join("script.rb")
script.write <<~'EOM' script.write <<~EOM
puts Kernel.private_methods puts Kernel.private_methods
EOM EOM
@ -159,7 +159,7 @@ module SyntaxSuggest
Dir.mktmpdir do |dir| Dir.mktmpdir do |dir|
tmpdir = Pathname(dir) tmpdir = Pathname(dir)
script = tmpdir.join("script.rb") script = tmpdir.join("script.rb")
script.write <<~'EOM' script.write <<~EOM
$stderr = STDOUT $stderr = STDOUT
eval("def lol") eval("def lol")
EOM EOM
@ -178,7 +178,7 @@ module SyntaxSuggest
Dir.mktmpdir do |dir| Dir.mktmpdir do |dir|
tmpdir = Pathname(dir) tmpdir = Pathname(dir)
script = tmpdir.join("script.rb") script = tmpdir.join("script.rb")
script.write <<~'EOM' script.write <<~EOM
break break
EOM EOM

Просмотреть файл

@ -26,7 +26,7 @@ module SyntaxSuggest
debug_display(io.string) debug_display(io.string)
debug_display(benchmark) debug_display(benchmark)
expect(io.string).to include(<<~'EOM') expect(io.string).to include(<<~EOM)
6 class SyntaxTree < Ripper 6 class SyntaxTree < Ripper
170 def self.parse(source) 170 def self.parse(source)
174 end 174 end
@ -54,7 +54,7 @@ module SyntaxSuggest
end end
expect(io.string).to_not include("def ruby_install_binstub_path") expect(io.string).to_not include("def ruby_install_binstub_path")
expect(io.string).to include(<<~'EOM') expect(io.string).to include(<<~EOM)
> 1067 def add_yarn_binary > 1067 def add_yarn_binary
> 1068 return [] if yarn_preinstalled? > 1068 return [] if yarn_preinstalled?
> 1069 | > 1069 |
@ -72,7 +72,7 @@ module SyntaxSuggest
) )
debug_display(io.string) debug_display(io.string)
expect(io.string).to include(<<~'EOM') expect(io.string).to include(<<~EOM)
1 Rails.application.routes.draw do 1 Rails.application.routes.draw do
> 113 namespace :admin do > 113 namespace :admin do
> 116 match "/foobar(*path)", via: :all, to: redirect { |_params, req| > 116 match "/foobar(*path)", via: :all, to: redirect { |_params, req|
@ -91,7 +91,7 @@ module SyntaxSuggest
) )
debug_display(io.string) debug_display(io.string)
expect(io.string).to include(<<~'EOM') expect(io.string).to include(<<~EOM)
1 describe "webmock tests" do 1 describe "webmock tests" do
22 it "body" do 22 it "body" do
27 query = Cutlass::FunctionQuery.new( 27 query = Cutlass::FunctionQuery.new(
@ -113,7 +113,7 @@ module SyntaxSuggest
) )
debug_display(io.string) debug_display(io.string)
expect(io.string).to include(<<~'EOM') expect(io.string).to include(<<~EOM)
5 module DerailedBenchmarks 5 module DerailedBenchmarks
6 class RequireTree 6 class RequireTree
> 13 def initialize(name) > 13 def initialize(name)
@ -166,7 +166,7 @@ module SyntaxSuggest
end end
it "ambiguous end" do it "ambiguous end" do
source = <<~'EOM' source = <<~EOM
def call # 0 def call # 0
print "lol" # 1 print "lol" # 1
end # one # 2 end # one # 2
@ -186,7 +186,7 @@ module SyntaxSuggest
end end
it "simple regression" do it "simple regression" do
source = <<~'EOM' source = <<~EOM
class Dog class Dog
def bark def bark
puts "woof" puts "woof"
@ -206,7 +206,7 @@ module SyntaxSuggest
end end
it "empty else" do it "empty else" do
source = <<~'EOM' source = <<~EOM
class Foo class Foo
def foo def foo
if cond? if cond?

Просмотреть файл

@ -5,7 +5,7 @@ require_relative "../spec_helper"
module SyntaxSuggest module SyntaxSuggest
RSpec.describe AroundBlockScan do RSpec.describe AroundBlockScan do
it "continues scan from last location even if scan is false" do it "continues scan from last location even if scan is false" do
source = <<~'EOM' source = <<~EOM
print 'omg' print 'omg'
print 'lol' print 'lol'
print 'haha' print 'haha'

Просмотреть файл

@ -5,7 +5,7 @@ require_relative "../../spec_helper"
module SyntaxSuggest module SyntaxSuggest
RSpec.describe Capture::BeforeAfterKeywordEnds do RSpec.describe Capture::BeforeAfterKeywordEnds do
it "before after keyword ends" do it "before after keyword ends" do
source = <<~'EOM' source = <<~EOM
def nope def nope
print 'not me' print 'not me'
end end
@ -36,7 +36,7 @@ module SyntaxSuggest
).call ).call
lines.sort! lines.sort!
expect(lines.join).to include(<<~'EOM') expect(lines.join).to include(<<~EOM)
def lol def lol
end end
def yolo def yolo

Просмотреть файл

@ -5,7 +5,7 @@ require_relative "../../spec_helper"
module SyntaxSuggest module SyntaxSuggest
RSpec.describe Capture::FallingIndentLines do RSpec.describe Capture::FallingIndentLines do
it "on_falling_indent" do it "on_falling_indent" do
source = <<~'EOM' source = <<~EOM
class OH class OH
def lol def lol
print 'lol print 'lol
@ -33,7 +33,7 @@ module SyntaxSuggest
end end
lines.sort! lines.sort!
expect(lines.join).to eq(<<~'EOM') expect(lines.join).to eq(<<~EOM)
class OH class OH
def hello def hello
end end

Просмотреть файл

@ -5,7 +5,7 @@ require_relative "../spec_helper"
module SyntaxSuggest module SyntaxSuggest
RSpec.describe CaptureCodeContext do RSpec.describe CaptureCodeContext do
it "capture_before_after_kws two" do it "capture_before_after_kws two" do
source = <<~'EOM' source = <<~EOM
class OH class OH
def hello def hello
@ -23,7 +23,7 @@ module SyntaxSuggest
code_lines: code_lines code_lines: code_lines
) )
display.capture_before_after_kws(block) display.capture_before_after_kws(block)
expect(display.sorted_lines.join).to eq(<<~'EOM'.indent(2)) expect(display.sorted_lines.join).to eq(<<~EOM.indent(2))
def hello def hello
def hai def hai
end end
@ -31,7 +31,7 @@ module SyntaxSuggest
end end
it "capture_before_after_kws" do it "capture_before_after_kws" do
source = <<~'EOM' source = <<~EOM
def sit def sit
end end
@ -50,7 +50,7 @@ module SyntaxSuggest
) )
lines = display.capture_before_after_kws(block).sort lines = display.capture_before_after_kws(block).sort
expect(lines.join).to eq(<<~'EOM') expect(lines.join).to eq(<<~EOM)
def sit def sit
end end
def bark def bark
@ -60,7 +60,7 @@ module SyntaxSuggest
end end
it "handles ambiguous end" do it "handles ambiguous end" do
source = <<~'EOM' source = <<~EOM
def call # 0 def call # 0
print "lol" # 1 print "lol" # 1
end # one # 2 end # one # 2
@ -79,7 +79,7 @@ module SyntaxSuggest
lines = lines.sort.map(&:original) lines = lines.sort.map(&:original)
expect(lines.join).to eq(<<~'EOM') expect(lines.join).to eq(<<~EOM)
def call # 0 def call # 0
end # one # 2 end # one # 2
end # two # 3 end # two # 3
@ -106,7 +106,7 @@ module SyntaxSuggest
lines = display.call lines = display.call
lines = lines.sort.map(&:original) lines = lines.sort.map(&:original)
expect(lines.join).to include(<<~'EOM'.indent(2)) expect(lines.join).to include(<<~EOM.indent(2))
class Lookups class Lookups
def format_requires def format_requires
end end
@ -114,7 +114,7 @@ module SyntaxSuggest
end end
it "shows ends of captured block" do it "shows ends of captured block" do
source = <<~'EOM' source = <<~EOM
class Dog class Dog
def bark def bark
puts "woof" puts "woof"
@ -132,7 +132,7 @@ module SyntaxSuggest
code_lines: code_lines code_lines: code_lines
) )
lines = display.call.sort.map(&:original) lines = display.call.sort.map(&:original)
expect(lines.join).to eq(<<~'EOM') expect(lines.join).to eq(<<~EOM)
class Dog class Dog
def bark def bark
end end
@ -140,7 +140,7 @@ module SyntaxSuggest
end end
it "captures surrounding context on falling indent" do it "captures surrounding context on falling indent" do
source = <<~'EOM' source = <<~EOM
class Blerg class Blerg
end end
@ -164,7 +164,7 @@ module SyntaxSuggest
code_lines: code_lines code_lines: code_lines
) )
lines = display.call.sort.map(&:original) lines = display.call.sort.map(&:original)
expect(lines.join).to eq(<<~'EOM') expect(lines.join).to eq(<<~EOM)
class OH class OH
def hello def hello
it "foo" do it "foo" do
@ -174,7 +174,7 @@ module SyntaxSuggest
end end
it "captures surrounding context on same indent" do it "captures surrounding context on same indent" do
source = <<~'EOM' source = <<~EOM
class Blerg class Blerg
end end
class OH class OH
@ -200,7 +200,7 @@ module SyntaxSuggest
code_lines = CleanDocument.new(source: source).call.lines code_lines = CleanDocument.new(source: source).call.lines
block = CodeBlock.new(lines: code_lines[7..10]) block = CodeBlock.new(lines: code_lines[7..10])
expect(block.to_s).to eq(<<~'EOM'.indent(2)) expect(block.to_s).to eq(<<~EOM.indent(2))
def lol def lol
end end
@ -217,7 +217,7 @@ module SyntaxSuggest
lines: lines lines: lines
).call ).call
expect(out).to eq(<<~'EOM'.indent(2)) expect(out).to eq(<<~EOM.indent(2))
3 class OH 3 class OH
8 def lol 8 def lol
9 end 9 end

Просмотреть файл

@ -8,7 +8,7 @@ module SyntaxSuggest
source = fixtures_dir.join("this_project_extra_def.rb.txt").read source = fixtures_dir.join("this_project_extra_def.rb.txt").read
code_lines = CleanDocument.new(source: source).call.lines code_lines = CleanDocument.new(source: source).call.lines
expect(code_lines[18 - 1].to_s).to eq(<<-'EOL') expect(code_lines[18 - 1].to_s).to eq(<<-EOL)
@io.puts <<~EOM @io.puts <<~EOM
SyntaxSuggest: A syntax error was detected SyntaxSuggest: A syntax error was detected
@ -54,7 +54,7 @@ module SyntaxSuggest
DisplayCodeWithLineNumbers.new( DisplayCodeWithLineNumbers.new(
lines: lines lines: lines
).call ).call
).to eq(<<~'EOM'.indent(2)) ).to eq(<<~EOM.indent(2))
1 User 1 User
2 .where(name: 'schneems') 2 .where(name: 'schneems')
3 .first 3 .first
@ -65,7 +65,7 @@ module SyntaxSuggest
lines: lines, lines: lines,
highlight_lines: lines[0] highlight_lines: lines[0]
).call ).call
).to eq(<<~'EOM') ).to eq(<<~EOM)
> 1 User > 1 User
> 2 .where(name: 'schneems') > 2 .where(name: 'schneems')
> 3 .first > 3 .first

Просмотреть файл

@ -5,7 +5,7 @@ require_relative "../spec_helper"
module SyntaxSuggest module SyntaxSuggest
RSpec.describe CodeLine do RSpec.describe CodeLine do
it "bug in keyword detection" do it "bug in keyword detection" do
lines = CodeLine.from_source(<<~'EOM') lines = CodeLine.from_source(<<~EOM)
def to_json(*opts) def to_json(*opts)
{ {
type: :module, type: :module,
@ -19,7 +19,7 @@ module SyntaxSuggest
it "supports endless method definitions" do it "supports endless method definitions" do
skip("Unsupported ruby version") unless Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3") skip("Unsupported ruby version") unless Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3")
line = CodeLine.from_source(<<~'EOM').first line = CodeLine.from_source(<<~EOM).first
def square(x) = x * x def square(x) = x * x
EOM EOM
@ -28,7 +28,7 @@ module SyntaxSuggest
end end
it "retains original line value, after being marked invisible" do it "retains original line value, after being marked invisible" do
line = CodeLine.from_source(<<~'EOM').first line = CodeLine.from_source(<<~EOM).first
puts "lol" puts "lol"
EOM EOM
expect(line.line).to match('puts "lol"') expect(line.line).to match('puts "lol"')
@ -38,7 +38,7 @@ module SyntaxSuggest
end end
it "knows which lines can be joined" do it "knows which lines can be joined" do
code_lines = CodeLine.from_source(<<~'EOM') code_lines = CodeLine.from_source(<<~EOM)
user = User. user = User.
where(name: 'schneems'). where(name: 'schneems').
first first
@ -50,7 +50,7 @@ module SyntaxSuggest
end end
it "trailing if" do it "trailing if" do
code_lines = CodeLine.from_source(<<~'EOM') code_lines = CodeLine.from_source(<<~EOM)
puts "lol" if foo puts "lol" if foo
if foo if foo
end end
@ -60,7 +60,7 @@ module SyntaxSuggest
end end
it "trailing unless" do it "trailing unless" do
code_lines = CodeLine.from_source(<<~'EOM') code_lines = CodeLine.from_source(<<~EOM)
puts "lol" unless foo puts "lol" unless foo
unless foo unless foo
end end

Просмотреть файл

@ -12,13 +12,13 @@ module SyntaxSuggest
search = CodeSearch.new(source) search = CodeSearch.new(source)
search.call search.call
expect(search.invalid_blocks.join.strip).to eq(<<~'EOM'.strip) expect(search.invalid_blocks.join.strip).to eq(<<~EOM.strip)
class Lookups class Lookups
EOM EOM
end end
it "squished do regression" do it "squished do regression" do
source = <<~'EOM' source = <<~EOM
def call def call
trydo trydo
@ -47,14 +47,14 @@ module SyntaxSuggest
search = CodeSearch.new(source) search = CodeSearch.new(source)
search.call search.call
expect(search.invalid_blocks.join).to eq(<<~'EOM'.indent(2)) expect(search.invalid_blocks.join).to eq(<<~EOM.indent(2))
trydo trydo
end # one end # one
EOM EOM
end end
it "regression test ambiguous end" do it "regression test ambiguous end" do
source = <<~'EOM' source = <<~EOM
def call # 0 def call # 0
print "lol" # 1 print "lol" # 1
end # one # 2 end # one # 2
@ -64,13 +64,13 @@ module SyntaxSuggest
search = CodeSearch.new(source) search = CodeSearch.new(source)
search.call search.call
expect(search.invalid_blocks.join).to eq(<<~'EOM') expect(search.invalid_blocks.join).to eq(<<~EOM)
end # two # 3 end # two # 3
EOM EOM
end end
it "regression dog test" do it "regression dog test" do
source = <<~'EOM' source = <<~EOM
class Dog class Dog
def bark def bark
puts "woof" puts "woof"
@ -79,7 +79,7 @@ module SyntaxSuggest
search = CodeSearch.new(source) search = CodeSearch.new(source)
search.call search.call
expect(search.invalid_blocks.join).to eq(<<~'EOM') expect(search.invalid_blocks.join).to eq(<<~EOM)
class Dog class Dog
EOM EOM
expect(search.invalid_blocks.first.lines.length).to eq(4) expect(search.invalid_blocks.first.lines.length).to eq(4)
@ -99,7 +99,7 @@ module SyntaxSuggest
search = CodeSearch.new(source) search = CodeSearch.new(source)
search.call search.call
expect(search.invalid_blocks.join).to eq(<<~'EOM'.indent(2)) expect(search.invalid_blocks.join).to eq(<<~EOM.indent(2))
Foo.call do |a Foo.call do |a
end # one end # one
EOM EOM
@ -118,7 +118,7 @@ module SyntaxSuggest
search = CodeSearch.new(source) search = CodeSearch.new(source)
search.call search.call
expect(search.invalid_blocks.join).to eq(<<~'EOM'.indent(2)) expect(search.invalid_blocks.join).to eq(<<~EOM.indent(2))
Foo.call do { Foo.call do {
EOM EOM
end end
@ -152,7 +152,7 @@ module SyntaxSuggest
end end
it "handles no spaces between blocks" do it "handles no spaces between blocks" do
source = <<~'EOM' source = <<~EOM
context "foo bar" do context "foo bar" do
it "bars the foo" do it "bars the foo" do
travel_to DateTime.new(2020, 10, 1, 10, 0, 0) do travel_to DateTime.new(2020, 10, 1, 10, 0, 0) do
@ -172,7 +172,7 @@ module SyntaxSuggest
it "records debugging steps to a directory" do it "records debugging steps to a directory" do
Dir.mktmpdir do |dir| Dir.mktmpdir do |dir|
dir = Pathname(dir) dir = Pathname(dir)
search = CodeSearch.new(<<~'EOM', record_dir: dir) search = CodeSearch.new(<<~EOM, record_dir: dir)
class OH class OH
def hello def hello
def hai def hai
@ -193,7 +193,7 @@ module SyntaxSuggest
end end
it "def with missing end" do it "def with missing end" do
search = CodeSearch.new(<<~'EOM') search = CodeSearch.new(<<~EOM)
class OH class OH
def hello def hello
@ -206,7 +206,7 @@ module SyntaxSuggest
expect(search.invalid_blocks.join.strip).to eq("def hello") expect(search.invalid_blocks.join.strip).to eq("def hello")
search = CodeSearch.new(<<~'EOM') search = CodeSearch.new(<<~EOM)
class OH class OH
def hello def hello
@ -218,7 +218,7 @@ module SyntaxSuggest
expect(search.invalid_blocks.join.strip).to eq("def hello") expect(search.invalid_blocks.join.strip).to eq("def hello")
search = CodeSearch.new(<<~'EOM') search = CodeSearch.new(<<~EOM)
class OH class OH
def hello def hello
def hai def hai
@ -227,7 +227,7 @@ module SyntaxSuggest
EOM EOM
search.call search.call
expect(search.invalid_blocks.join).to eq(<<~'EOM'.indent(2)) expect(search.invalid_blocks.join).to eq(<<~EOM.indent(2))
def hello def hello
EOM EOM
end end
@ -244,13 +244,13 @@ module SyntaxSuggest
highlight_lines: search.invalid_blocks.flat_map(&:lines) highlight_lines: search.invalid_blocks.flat_map(&:lines)
).call ).call
expect(document).to include(<<~'EOM') expect(document).to include(<<~EOM)
> 36 def filename > 36 def filename
EOM EOM
end end
it "Format Code blocks real world example" do it "Format Code blocks real world example" do
search = CodeSearch.new(<<~'EOM') search = CodeSearch.new(<<~EOM)
require 'rails_helper' require 'rails_helper'
RSpec.describe AclassNameHere, type: :worker do RSpec.describe AclassNameHere, type: :worker do
@ -291,7 +291,7 @@ module SyntaxSuggest
highlight_lines: search.invalid_blocks.flat_map(&:lines) highlight_lines: search.invalid_blocks.flat_map(&:lines)
).call ).call
expect(document).to include(<<~'EOM') expect(document).to include(<<~EOM)
1 require 'rails_helper' 1 require 'rails_helper'
2 2
3 RSpec.describe AclassNameHere, type: :worker do 3 RSpec.describe AclassNameHere, type: :worker do
@ -308,7 +308,7 @@ module SyntaxSuggest
describe "needs improvement" do describe "needs improvement" do
describe "mis-matched-indentation" do describe "mis-matched-indentation" do
it "extra space before end" do it "extra space before end" do
search = CodeSearch.new(<<~'EOM') search = CodeSearch.new(<<~EOM)
Foo.call Foo.call
def foo def foo
puts "lol" puts "lol"
@ -318,14 +318,14 @@ module SyntaxSuggest
EOM EOM
search.call search.call
expect(search.invalid_blocks.join).to eq(<<~'EOM') expect(search.invalid_blocks.join).to eq(<<~EOM)
Foo.call Foo.call
end # two end # two
EOM EOM
end end
it "stacked ends 2" do it "stacked ends 2" do
search = CodeSearch.new(<<~'EOM') search = CodeSearch.new(<<~EOM)
def cat def cat
blerg blerg
end end
@ -339,7 +339,7 @@ module SyntaxSuggest
EOM EOM
search.call search.call
expect(search.invalid_blocks.join).to eq(<<~'EOM') expect(search.invalid_blocks.join).to eq(<<~EOM)
Foo.call do Foo.call do
end # one end # one
end # two end # two
@ -348,7 +348,7 @@ module SyntaxSuggest
end end
it "stacked ends " do it "stacked ends " do
search = CodeSearch.new(<<~'EOM') search = CodeSearch.new(<<~EOM)
Foo.call Foo.call
def foo def foo
puts "lol" puts "lol"
@ -358,14 +358,14 @@ module SyntaxSuggest
EOM EOM
search.call search.call
expect(search.invalid_blocks.join).to eq(<<~'EOM') expect(search.invalid_blocks.join).to eq(<<~EOM)
Foo.call Foo.call
end end
EOM EOM
end end
it "missing space before end" do it "missing space before end" do
search = CodeSearch.new(<<~'EOM') search = CodeSearch.new(<<~EOM)
Foo.call Foo.call
def foo def foo
@ -377,7 +377,7 @@ module SyntaxSuggest
search.call search.call
# expand-1 and expand-2 seem to be broken? # expand-1 and expand-2 seem to be broken?
expect(search.invalid_blocks.join).to eq(<<~'EOM') expect(search.invalid_blocks.join).to eq(<<~EOM)
Foo.call Foo.call
end end
EOM EOM
@ -386,7 +386,7 @@ module SyntaxSuggest
end end
it "returns syntax error in outer block without inner block" do it "returns syntax error in outer block without inner block" do
search = CodeSearch.new(<<~'EOM') search = CodeSearch.new(<<~EOM)
Foo.call Foo.call
def foo def foo
puts "lol" puts "lol"
@ -396,27 +396,27 @@ module SyntaxSuggest
EOM EOM
search.call search.call
expect(search.invalid_blocks.join).to eq(<<~'EOM') expect(search.invalid_blocks.join).to eq(<<~EOM)
Foo.call Foo.call
end # two end # two
EOM EOM
end end
it "doesn't just return an empty `end`" do it "doesn't just return an empty `end`" do
search = CodeSearch.new(<<~'EOM') search = CodeSearch.new(<<~EOM)
Foo.call Foo.call
end end
EOM EOM
search.call search.call
expect(search.invalid_blocks.join).to eq(<<~'EOM') expect(search.invalid_blocks.join).to eq(<<~EOM)
Foo.call Foo.call
end end
EOM EOM
end end
it "finds multiple syntax errors" do it "finds multiple syntax errors" do
search = CodeSearch.new(<<~'EOM') search = CodeSearch.new(<<~EOM)
describe "hi" do describe "hi" do
Foo.call Foo.call
end end
@ -429,7 +429,7 @@ module SyntaxSuggest
EOM EOM
search.call search.call
expect(search.invalid_blocks.join).to eq(<<~'EOM'.indent(2)) expect(search.invalid_blocks.join).to eq(<<~EOM.indent(2))
Foo.call Foo.call
end end
Bar.call Bar.call
@ -438,47 +438,47 @@ module SyntaxSuggest
end end
it "finds a typo def" do it "finds a typo def" do
search = CodeSearch.new(<<~'EOM') search = CodeSearch.new(<<~EOM)
defzfoo defzfoo
puts "lol" puts "lol"
end end
EOM EOM
search.call search.call
expect(search.invalid_blocks.join).to eq(<<~'EOM') expect(search.invalid_blocks.join).to eq(<<~EOM)
defzfoo defzfoo
end end
EOM EOM
end end
it "finds a mis-matched def" do it "finds a mis-matched def" do
search = CodeSearch.new(<<~'EOM') search = CodeSearch.new(<<~EOM)
def foo def foo
def blerg def blerg
end end
EOM EOM
search.call search.call
expect(search.invalid_blocks.join).to eq(<<~'EOM'.indent(2)) expect(search.invalid_blocks.join).to eq(<<~EOM.indent(2))
def blerg def blerg
EOM EOM
end end
it "finds a naked end" do it "finds a naked end" do
search = CodeSearch.new(<<~'EOM') search = CodeSearch.new(<<~EOM)
def foo def foo
end # one end # one
end # two end # two
EOM EOM
search.call search.call
expect(search.invalid_blocks.join).to eq(<<~'EOM'.indent(2)) expect(search.invalid_blocks.join).to eq(<<~EOM.indent(2))
end # one end # one
EOM EOM
end end
it "returns when no invalid blocks are found" do it "returns when no invalid blocks are found" do
search = CodeSearch.new(<<~'EOM') search = CodeSearch.new(<<~EOM)
def foo def foo
puts 'lol' puts 'lol'
end end
@ -489,14 +489,14 @@ module SyntaxSuggest
end end
it "expands frontier by eliminating valid lines" do it "expands frontier by eliminating valid lines" do
search = CodeSearch.new(<<~'EOM') search = CodeSearch.new(<<~EOM)
def foo def foo
puts 'lol' puts 'lol'
end end
EOM EOM
search.create_blocks_from_untracked_lines search.create_blocks_from_untracked_lines
expect(search.code_lines.join).to eq(<<~'EOM') expect(search.code_lines.join).to eq(<<~EOM)
def foo def foo
end end
EOM EOM

Просмотреть файл

@ -8,7 +8,7 @@ module SyntaxSuggest
Dir.mktmpdir do |dir| Dir.mktmpdir do |dir|
tmpdir = Pathname(dir) tmpdir = Pathname(dir)
file = tmpdir.join("file.rb") file = tmpdir.join("file.rb")
file.write(<<~'EOM'.strip) file.write(<<~EOM.strip)
print 'no newline print 'no newline
EOM EOM

Просмотреть файл

@ -5,7 +5,7 @@ require_relative "../spec_helper"
module SyntaxSuggest module SyntaxSuggest
RSpec.describe ScanHistory do RSpec.describe ScanHistory do
it "retains commits" do it "retains commits" do
source = <<~'EOM' source = <<~EOM
class OH # 0 class OH # 0
def lol # 1 def lol # 1
print 'lol # 2 print 'lol # 2
@ -42,7 +42,7 @@ module SyntaxSuggest
end end
it "is stashable" do it "is stashable" do
source = <<~'EOM' source = <<~EOM
class OH # 0 class OH # 0
def lol # 1 def lol # 1
print 'lol # 2 print 'lol # 2
@ -79,7 +79,7 @@ module SyntaxSuggest
end end
it "doesnt change if you dont't change it" do it "doesnt change if you dont't change it" do
source = <<~'EOM' source = <<~EOM
class OH # 0 class OH # 0
def lol # 1 def lol # 1
print 'lol # 2 print 'lol # 2