Skip to content

Commit f62bec1

Browse files
EarlopainXrXr
authored andcommitted
Fix sync for syntax_suggest
It is a bit special in that is uses `spec` for tests. Since ruby#15015 those did not get synced anymore. This fixes the mapping to what is was before and pulls in missing changes
1 parent d7da198 commit f62bec1

10 files changed

Lines changed: 54 additions & 34 deletions

spec/syntax_suggest/integration/ruby_command_line_spec.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,13 @@ module SyntaxSuggest
9494
end
9595

9696
it "gem can be tested when executing on Ruby with default gem included" do
97-
skip if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3.2")
98-
9997
out = `#{ruby} -I#{lib_dir} -rsyntax_suggest -e "puts SyntaxError.instance_method(:detailed_message).source_location" 2>&1`
10098

10199
expect($?.success?).to be_truthy
102100
expect(out).to include(lib_dir.join("syntax_suggest").join("core_ext.rb").to_s).once
103101
end
104102

105103
it "annotates a syntax error in Ruby 3.2+ when require is not used" do
106-
skip if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3.2")
107-
108104
Dir.mktmpdir do |dir|
109105
tmpdir = Pathname(dir)
110106
script = tmpdir.join("script.rb")

spec/syntax_suggest/integration/syntax_suggest_spec.rb

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44

55
module SyntaxSuggest
66
RSpec.describe "Integration tests that don't spawn a process (like using the cli)" do
7-
before(:each) do
8-
skip "Benchmark is not available" unless defined?(::Benchmark)
9-
end
10-
117
it "does not timeout on massive files" do
128
next unless ENV["SYNTAX_SUGGEST_TIMEOUT"]
139

@@ -17,7 +13,7 @@ module SyntaxSuggest
1713

1814
io = StringIO.new
1915

20-
benchmark = Benchmark.measure do
16+
benchmark_measure do
2117
debug_perf do
2218
SyntaxSuggest.call(
2319
io: io,
@@ -28,7 +24,6 @@ module SyntaxSuggest
2824
end
2925

3026
debug_display(io.string)
31-
debug_display(benchmark)
3227

3328
expect(io.string).to include(<<~EOM)
3429
6 class SyntaxTree < Ripper
@@ -46,15 +41,14 @@ module SyntaxSuggest
4641
io = StringIO.new
4742

4843
debug_perf do
49-
benchmark = Benchmark.measure do
44+
benchmark_measure do
5045
SyntaxSuggest.call(
5146
io: io,
5247
source: file.read,
5348
filename: file
5449
)
5550
end
5651
debug_display(io.string)
57-
debug_display(benchmark)
5852
end
5953

6054
expect(io.string).to_not include("def ruby_install_binstub_path")

spec/syntax_suggest/spec_helper.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,16 @@ def debug_perf
8585
end
8686
end
8787

88+
def benchmark_measure
89+
raise "No block given" unless block_given?
90+
91+
if defined?(::Benchmark)
92+
debug_display(Benchmark.measure { yield })
93+
else
94+
yield
95+
end
96+
end
97+
8898
def run!(cmd, raise_on_nonzero_exit: true)
8999
out = `#{cmd} 2>&1`
90100
raise "Command: #{cmd} failed: #{out}" if !$?.success? && raise_on_nonzero_exit

spec/syntax_suggest/unit/api_spec.rb

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,6 @@
88

99
module SyntaxSuggest
1010
RSpec.describe "Top level SyntaxSuggest api" do
11-
it "doesn't load prism if env var is set" do
12-
skip("SYNTAX_SUGGEST_DISABLE_PRISM not set") unless ENV["SYNTAX_SUGGEST_DISABLE_PRISM"]
13-
14-
expect(SyntaxSuggest.use_prism_parser?).to be_falsey
15-
end
16-
1711
it "has a `handle_error` interface" do
1812
fake_error = Object.new
1913
def fake_error.message
@@ -69,8 +63,6 @@ def fake_error.message
6963
end
7064

7165
it "respects highlight API" do
72-
skip if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3.2")
73-
7466
core_ext_file = lib_dir.join("syntax_suggest").join("core_ext.rb")
7567
require_relative core_ext_file
7668

@@ -91,8 +83,6 @@ def detailed_message(**kwargs)
9183
end
9284

9385
it "can be disabled via falsey kwarg" do
94-
skip if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3.2")
95-
9686
core_ext_file = lib_dir.join("syntax_suggest").join("core_ext.rb")
9787
require_relative core_ext_file
9888

spec/syntax_suggest/unit/code_block_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def foo
3333
array = [block_2, block_1, block_0].sort
3434
expect(array.last).to eq(block_2)
3535

36-
block = CodeBlock.new(lines: CodeLine.new(line: " " * 8 + "foo", index: 4, lex: []))
36+
block = CodeBlock.new(lines: CodeLine.new(line: " " * 8 + "foo", index: 4, tokens: []))
3737
array.prepend(block)
3838
expect(array.max).to eq(block)
3939
end

spec/syntax_suggest/unit/code_line_spec.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ def to_json(*opts)
1717
end
1818

1919
it "supports endless method definitions" do
20-
skip("Unsupported ruby version") unless Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3")
21-
2220
line = CodeLine.from_source(<<~EOM).first
2321
def square(x) = x * x
2422
EOM

spec/syntax_suggest/unit/core_ext_spec.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
module SyntaxSuggest
44
RSpec.describe "Core extension" do
55
it "SyntaxError monkepatch ensures there is a newline to the end of the file" do
6-
skip if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3.2")
7-
86
Dir.mktmpdir do |dir|
97
tmpdir = Pathname(dir)
108
file = tmpdir.join("file.rb")

spec/syntax_suggest/unit/explain_syntax_spec.rb

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,23 @@ module SyntaxSuggest
1717
expect(explain.errors.join.strip).to_not be_empty
1818
end
1919

20-
it "handles %w[]" do
20+
%w[w W i I].each do |type|
21+
it "handles %#{type}-style array" do
22+
source = <<~EOM
23+
node.is_a?(Op) && %#{type}[| ||].include?(node.value) &&
24+
EOM
25+
26+
explain = ExplainSyntax.new(
27+
code_lines: CodeLine.from_source(source)
28+
).call
29+
30+
expect(explain.missing).to eq([])
31+
end
32+
end
33+
34+
it "handles %r-style regexp" do
2135
source = <<~EOM
22-
node.is_a?(Op) && %w[| ||].include?(node.value) &&
36+
node.is_a?(Op) && %r{| ||}.include?(node.value) &&
2337
EOM
2438

2539
explain = ExplainSyntax.new(
@@ -29,6 +43,20 @@ module SyntaxSuggest
2943
expect(explain.missing).to eq([])
3044
end
3145

46+
["", "q", "Q"].each do |type|
47+
it "handles %#{type}-style string" do
48+
source = <<~EOM
49+
node.is_a?(Op) && %#{type}(| ||).include?(node.value) &&
50+
EOM
51+
52+
explain = ExplainSyntax.new(
53+
code_lines: CodeLine.from_source(source)
54+
).call
55+
56+
expect(explain.missing).to eq([])
57+
end
58+
end
59+
3260
it "doesn't falsely identify strings or symbols as critical chars" do
3361
source = <<~EOM
3462
a = ['(', '{', '[', '|']

spec/syntax_suggest/unit/lex_all_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ module SyntaxSuggest
1717
end # 9
1818
EOM
1919

20-
lex = LexAll.new(source: source)
21-
expect(lex.map(&:token).to_s).to include("dog")
22-
expect(lex.first.line).to eq(1)
23-
expect(lex.last.line).to eq(9)
20+
tokens = LexAll.new(source: source)
21+
expect(tokens.map(&:value)).to include("dog")
22+
expect(tokens.first.line).to eq(1)
23+
expect(tokens.last.line).to eq(9)
2424
end
2525
end
2626
end

tool/sync_default_gems.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,13 @@ def lib((upstream, branch), gemspec_in_subdir: false)
295295
"ext/strscan/regint.h",
296296
"ext/strscan/lib/strscan/truffleruby.rb",
297297
]),
298-
syntax_suggest: lib(["ruby/syntax_suggest", "main"], gemspec_in_subdir: true),
298+
syntax_suggest: repo("ruby/syntax_suggest", [
299+
["lib/syntax_suggest.rb", "lib/syntax_suggest.rb"],
300+
["lib/syntax_suggest", "lib/syntax_suggest"],
301+
["syntax_suggest.gemspec", "lib/syntax_suggest/syntax_suggest.gemspec"],
302+
["exe/syntax_suggest", "libexec/syntax_suggest"],
303+
["spec", "spec/syntax_suggest"],
304+
]),
299305
tempfile: lib("ruby/tempfile"),
300306
time: lib("ruby/time"),
301307
timeout: lib("ruby/timeout"),

0 commit comments

Comments
 (0)