-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dc28255
commit bffe9b5
Showing
4 changed files
with
56 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# frozen_string_literal: true | ||
|
||
module RuboCop | ||
module AST | ||
# A node extension for `dstr` nodes. This will be used | ||
# in place of a plain node when the builder constructs the AST, making | ||
# its methods available to all `dstr` nodes within RuboCop. | ||
class DstrNode < StrNode | ||
def value | ||
child_nodes.map do |child| | ||
child.respond_to?(:value) ? child.value : child.source | ||
end.join | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe RuboCop::AST::DstrNode do | ||
subject(:dstr_node) { parse_source(source).ast } | ||
|
||
describe '#value' do | ||
subject { dstr_node.value } | ||
|
||
context 'with a multiline string' do | ||
let(:source) do | ||
<<~RUBY | ||
'this is a multiline ' \ | ||
'string' | ||
RUBY | ||
end | ||
|
||
it { is_expected.to eq('this is a multiline string') } | ||
end | ||
|
||
context 'with interpolation' do | ||
let(:source) do | ||
'"foo #{bar} baz"' | ||
end | ||
|
||
it { is_expected.to eq('foo #{bar} baz') } | ||
end | ||
|
||
context 'with implicit concatenation' do | ||
let(:source) do | ||
<<~RUBY | ||
'foo ' 'bar ' 'baz' | ||
RUBY | ||
end | ||
|
||
it { is_expected.to eq('foo bar baz') } | ||
end | ||
end | ||
end |