forked from rubocop/rubocop-ast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
str_node_spec.rb
86 lines (67 loc) · 1.63 KB
/
str_node_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# frozen_string_literal: true
RSpec.describe RuboCop::AST::StrNode do
subject(:str_node) { parse_source(source).ast }
describe '.new' do
context 'with a normal string' do
let(:source) { "'foo'" }
it { is_expected.to be_a(described_class) }
end
context 'with a string with interpolation' do
let(:source) { '"#{foo}"' }
it { is_expected.to be_a(described_class) }
end
context 'with a heredoc' do
let(:source) do
<<~RUBY
<<-CODE
foo
bar
CODE
RUBY
end
it { is_expected.to be_a(described_class) }
end
end
describe '#character_literal?' do
context 'with a character literal' do
let(:source) { '?\n' }
it { is_expected.to be_character_literal }
end
context 'with a normal string literal' do
let(:source) { '"\n"' }
it { is_expected.not_to be_character_literal }
end
context 'with a heredoc' do
let(:source) do
<<~RUBY
<<-CODE
foo
bar
CODE
RUBY
end
it { is_expected.not_to be_character_literal }
end
end
describe '#heredoc?' do
context 'with a normal string' do
let(:source) { "'foo'" }
it { is_expected.not_to be_heredoc }
end
context 'with a string with interpolation' do
let(:source) { '"#{foo}"' }
it { is_expected.not_to be_heredoc }
end
context 'with a heredoc' do
let(:source) do
<<~RUBY
<<-CODE
foo
bar
CODE
RUBY
end
it { is_expected.to be_heredoc }
end
end
end