Skip to content

Commit db2dca2

Browse files
committed
Fix typo for %I delimiter check
Also add tests for the other types which currently don't have one
1 parent 12e755a commit db2dca2

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## 2.0.3
44

55
- Fix: Correctly identify trailing slashes when using Prism > 1.8.0. (https://github.com/ruby/syntax_suggest/pull/243)
6+
- Fix: Correctly handle `%I` delimiters. (https://github.com/ruby/syntax_suggest/pull/249)
67
- Internal: Add tests to multiple versions of prism
78

89
## 2.0.2

lib/syntax_suggest/left_right_lex_count.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def count_lex(lex)
6262
# Means it's a string or a symbol `"{"` rather than being
6363
# part of a data structure (like a hash) `{ a: b }`
6464
# ignore it.
65-
when :on_words_beg, :on_symbos_beg, :on_qwords_beg,
65+
when :on_words_beg, :on_symbols_beg, :on_qwords_beg,
6666
:on_qsymbols_beg, :on_regexp_beg, :on_tstring_beg
6767
# ^^^
6868
# Handle shorthand syntaxes like `%Q{ i am a string }`

spec/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 = ['(', '{', '[', '|']

0 commit comments

Comments
 (0)