Skip to content

Commit

Permalink
Add support for case-in statements
Browse files Browse the repository at this point in the history
  • Loading branch information
jdelStrother authored and k0kubun committed Dec 9, 2023
1 parent 88049a6 commit 616cf38
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/haml/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class Parser
#
BLOCK_WITH_SPACES = /do\s*\|\s*[^\|]*\s+\|\z/

MID_BLOCK_KEYWORDS = %w[else elsif rescue ensure end when].freeze
MID_BLOCK_KEYWORDS = %w[else elsif rescue ensure end when in].freeze
START_BLOCK_KEYWORDS = %w[if begin case unless].freeze
# Try to parse assignments to block starters as best as possible
START_BLOCK_KEYWORD_REGEX = /(?:\w+(?:,\s*\w+)*\s*=\s*)?(#{START_BLOCK_KEYWORDS.join('|')})/
Expand Down
13 changes: 13 additions & 0 deletions test/haml/engine/silent_script_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,19 @@
HAML
end

it 'renders case-in' do
skip 'pattern-matching not supported' if RUBY_VERSION < '2.7' || RUBY_ENGINE == 'truffleruby'
assert_render(<<-HTML.unindent, <<-'HAML'.unindent)
ok
HTML
- case [:foo, 'ok']
- in [:foo, msg]
= msg
- else
ng
HAML
end

it 'renders begin-rescue' do
assert_render(<<-HTML.unindent, <<-HAML.unindent)
hello
Expand Down

0 comments on commit 616cf38

Please sign in to comment.