summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEarlopain <14981592+Earlopain@users.noreply.github.com>2026-04-07 20:04:19 +0200
committerAlan Wu <XrXr@users.noreply.github.com>2026-04-07 15:01:01 -0400
commitf62bec1b9055159873fab357d3a32388fe307b2d (patch)
tree2c03d7cf39501aea4abe5c6a2533f5be665c22c6
parentd7da198731fb4ea08ce71dcc5e6284b363706f32 (diff)
Fix sync for `syntax_suggest`
It is a bit special in that is uses `spec` for tests. Since https://github.com/ruby/ruby/pull/15015 those did not get synced anymore. This fixes the mapping to what is was before and pulls in missing changes
-rw-r--r--spec/syntax_suggest/integration/ruby_command_line_spec.rb4
-rw-r--r--spec/syntax_suggest/integration/syntax_suggest_spec.rb10
-rw-r--r--spec/syntax_suggest/spec_helper.rb10
-rw-r--r--spec/syntax_suggest/unit/api_spec.rb10
-rw-r--r--spec/syntax_suggest/unit/code_block_spec.rb2
-rw-r--r--spec/syntax_suggest/unit/code_line_spec.rb2
-rw-r--r--spec/syntax_suggest/unit/core_ext_spec.rb2
-rw-r--r--spec/syntax_suggest/unit/explain_syntax_spec.rb32
-rw-r--r--spec/syntax_suggest/unit/lex_all_spec.rb8
-rwxr-xr-xtool/sync_default_gems.rb8
10 files changed, 54 insertions, 34 deletions
diff --git a/spec/syntax_suggest/integration/ruby_command_line_spec.rb b/spec/syntax_suggest/integration/ruby_command_line_spec.rb
index c1ec4be54e..02354ceff0 100644
--- a/spec/syntax_suggest/integration/ruby_command_line_spec.rb
+++ b/spec/syntax_suggest/integration/ruby_command_line_spec.rb
@@ -94,8 +94,6 @@ module SyntaxSuggest
end
it "gem can be tested when executing on Ruby with default gem included" do
- skip if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3.2")
-
out = `#{ruby} -I#{lib_dir} -rsyntax_suggest -e "puts SyntaxError.instance_method(:detailed_message).source_location" 2>&1`
expect($?.success?).to be_truthy
@@ -103,8 +101,6 @@ module SyntaxSuggest
end
it "annotates a syntax error in Ruby 3.2+ when require is not used" do
- skip if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3.2")
-
Dir.mktmpdir do |dir|
tmpdir = Pathname(dir)
script = tmpdir.join("script.rb")
diff --git a/spec/syntax_suggest/integration/syntax_suggest_spec.rb b/spec/syntax_suggest/integration/syntax_suggest_spec.rb
index 015d088c92..79bfdc1b57 100644
--- a/spec/syntax_suggest/integration/syntax_suggest_spec.rb
+++ b/spec/syntax_suggest/integration/syntax_suggest_spec.rb
@@ -4,10 +4,6 @@ require_relative "../spec_helper"
module SyntaxSuggest
RSpec.describe "Integration tests that don't spawn a process (like using the cli)" do
- before(:each) do
- skip "Benchmark is not available" unless defined?(::Benchmark)
- end
-
it "does not timeout on massive files" do
next unless ENV["SYNTAX_SUGGEST_TIMEOUT"]
@@ -17,7 +13,7 @@ module SyntaxSuggest
io = StringIO.new
- benchmark = Benchmark.measure do
+ benchmark_measure do
debug_perf do
SyntaxSuggest.call(
io: io,
@@ -28,7 +24,6 @@ module SyntaxSuggest
end
debug_display(io.string)
- debug_display(benchmark)
expect(io.string).to include(<<~EOM)
6 class SyntaxTree < Ripper
@@ -46,7 +41,7 @@ module SyntaxSuggest
io = StringIO.new
debug_perf do
- benchmark = Benchmark.measure do
+ benchmark_measure do
SyntaxSuggest.call(
io: io,
source: file.read,
@@ -54,7 +49,6 @@ module SyntaxSuggest
)
end
debug_display(io.string)
- debug_display(benchmark)
end
expect(io.string).to_not include("def ruby_install_binstub_path")
diff --git a/spec/syntax_suggest/spec_helper.rb b/spec/syntax_suggest/spec_helper.rb
index b5d2924e69..c0aaf0f4f7 100644
--- a/spec/syntax_suggest/spec_helper.rb
+++ b/spec/syntax_suggest/spec_helper.rb
@@ -85,6 +85,16 @@ def debug_perf
end
end
+def benchmark_measure
+ raise "No block given" unless block_given?
+
+ if defined?(::Benchmark)
+ debug_display(Benchmark.measure { yield })
+ else
+ yield
+ end
+end
+
def run!(cmd, raise_on_nonzero_exit: true)
out = `#{cmd} 2>&1`
raise "Command: #{cmd} failed: #{out}" if !$?.success? && raise_on_nonzero_exit
diff --git a/spec/syntax_suggest/unit/api_spec.rb b/spec/syntax_suggest/unit/api_spec.rb
index e900b9e10b..9299a17bee 100644
--- a/spec/syntax_suggest/unit/api_spec.rb
+++ b/spec/syntax_suggest/unit/api_spec.rb
@@ -8,12 +8,6 @@ end
module SyntaxSuggest
RSpec.describe "Top level SyntaxSuggest api" do
- it "doesn't load prism if env var is set" do
- skip("SYNTAX_SUGGEST_DISABLE_PRISM not set") unless ENV["SYNTAX_SUGGEST_DISABLE_PRISM"]
-
- expect(SyntaxSuggest.use_prism_parser?).to be_falsey
- end
-
it "has a `handle_error` interface" do
fake_error = Object.new
def fake_error.message
@@ -69,8 +63,6 @@ module SyntaxSuggest
end
it "respects highlight API" do
- skip if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3.2")
-
core_ext_file = lib_dir.join("syntax_suggest").join("core_ext.rb")
require_relative core_ext_file
@@ -91,8 +83,6 @@ module SyntaxSuggest
end
it "can be disabled via falsey kwarg" do
- skip if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3.2")
-
core_ext_file = lib_dir.join("syntax_suggest").join("core_ext.rb")
require_relative core_ext_file
diff --git a/spec/syntax_suggest/unit/code_block_spec.rb b/spec/syntax_suggest/unit/code_block_spec.rb
index 3ab2751b27..baf1c63b25 100644
--- a/spec/syntax_suggest/unit/code_block_spec.rb
+++ b/spec/syntax_suggest/unit/code_block_spec.rb
@@ -33,7 +33,7 @@ module SyntaxSuggest
array = [block_2, block_1, block_0].sort
expect(array.last).to eq(block_2)
- block = CodeBlock.new(lines: CodeLine.new(line: " " * 8 + "foo", index: 4, lex: []))
+ block = CodeBlock.new(lines: CodeLine.new(line: " " * 8 + "foo", index: 4, tokens: []))
array.prepend(block)
expect(array.max).to eq(block)
end
diff --git a/spec/syntax_suggest/unit/code_line_spec.rb b/spec/syntax_suggest/unit/code_line_spec.rb
index 5b62cc2757..761c460385 100644
--- a/spec/syntax_suggest/unit/code_line_spec.rb
+++ b/spec/syntax_suggest/unit/code_line_spec.rb
@@ -17,8 +17,6 @@ module SyntaxSuggest
end
it "supports endless method definitions" do
- skip("Unsupported ruby version") unless Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3")
-
line = CodeLine.from_source(<<~EOM).first
def square(x) = x * x
EOM
diff --git a/spec/syntax_suggest/unit/core_ext_spec.rb b/spec/syntax_suggest/unit/core_ext_spec.rb
index 499c38a240..d579cc8dc4 100644
--- a/spec/syntax_suggest/unit/core_ext_spec.rb
+++ b/spec/syntax_suggest/unit/core_ext_spec.rb
@@ -3,8 +3,6 @@ require_relative "../spec_helper"
module SyntaxSuggest
RSpec.describe "Core extension" do
it "SyntaxError monkepatch ensures there is a newline to the end of the file" do
- skip if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3.2")
-
Dir.mktmpdir do |dir|
tmpdir = Pathname(dir)
file = tmpdir.join("file.rb")
diff --git a/spec/syntax_suggest/unit/explain_syntax_spec.rb b/spec/syntax_suggest/unit/explain_syntax_spec.rb
index c62a42b925..7ddb32b8ea 100644
--- a/spec/syntax_suggest/unit/explain_syntax_spec.rb
+++ b/spec/syntax_suggest/unit/explain_syntax_spec.rb
@@ -17,9 +17,23 @@ module SyntaxSuggest
expect(explain.errors.join.strip).to_not be_empty
end
- it "handles %w[]" do
+ %w[w W i I].each do |type|
+ it "handles %#{type}-style array" do
+ source = <<~EOM
+ node.is_a?(Op) && %#{type}[| ||].include?(node.value) &&
+ EOM
+
+ explain = ExplainSyntax.new(
+ code_lines: CodeLine.from_source(source)
+ ).call
+
+ expect(explain.missing).to eq([])
+ end
+ end
+
+ it "handles %r-style regexp" do
source = <<~EOM
- node.is_a?(Op) && %w[| ||].include?(node.value) &&
+ node.is_a?(Op) && %r{| ||}.include?(node.value) &&
EOM
explain = ExplainSyntax.new(
@@ -29,6 +43,20 @@ module SyntaxSuggest
expect(explain.missing).to eq([])
end
+ ["", "q", "Q"].each do |type|
+ it "handles %#{type}-style string" do
+ source = <<~EOM
+ node.is_a?(Op) && %#{type}(| ||).include?(node.value) &&
+ EOM
+
+ explain = ExplainSyntax.new(
+ code_lines: CodeLine.from_source(source)
+ ).call
+
+ expect(explain.missing).to eq([])
+ end
+ end
+
it "doesn't falsely identify strings or symbols as critical chars" do
source = <<~EOM
a = ['(', '{', '[', '|']
diff --git a/spec/syntax_suggest/unit/lex_all_spec.rb b/spec/syntax_suggest/unit/lex_all_spec.rb
index 9621c9ecec..b88ae65344 100644
--- a/spec/syntax_suggest/unit/lex_all_spec.rb
+++ b/spec/syntax_suggest/unit/lex_all_spec.rb
@@ -17,10 +17,10 @@ module SyntaxSuggest
end # 9
EOM
- lex = LexAll.new(source: source)
- expect(lex.map(&:token).to_s).to include("dog")
- expect(lex.first.line).to eq(1)
- expect(lex.last.line).to eq(9)
+ tokens = LexAll.new(source: source)
+ expect(tokens.map(&:value)).to include("dog")
+ expect(tokens.first.line).to eq(1)
+ expect(tokens.last.line).to eq(9)
end
end
end
diff --git a/tool/sync_default_gems.rb b/tool/sync_default_gems.rb
index 4ef99d16e4..ad03e554f8 100755
--- a/tool/sync_default_gems.rb
+++ b/tool/sync_default_gems.rb
@@ -295,7 +295,13 @@ module SyncDefaultGems
"ext/strscan/regint.h",
"ext/strscan/lib/strscan/truffleruby.rb",
]),
- syntax_suggest: lib(["ruby/syntax_suggest", "main"], gemspec_in_subdir: true),
+ syntax_suggest: repo("ruby/syntax_suggest", [
+ ["lib/syntax_suggest.rb", "lib/syntax_suggest.rb"],
+ ["lib/syntax_suggest", "lib/syntax_suggest"],
+ ["syntax_suggest.gemspec", "lib/syntax_suggest/syntax_suggest.gemspec"],
+ ["exe/syntax_suggest", "libexec/syntax_suggest"],
+ ["spec", "spec/syntax_suggest"],
+ ]),
tempfile: lib("ruby/tempfile"),
time: lib("ruby/time"),
timeout: lib("ruby/timeout"),