rainbow 3.0.0 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,14 +0,0 @@
1
- require 'spec_helper'
2
- require 'rainbow'
3
-
4
- RSpec.describe 'uncolor method' do
5
-
6
- it 'strips ansi color escape code' do
7
- expect(Rainbow.uncolor("\e[35mhello\e[0mm")).to eq 'hellom'
8
- end
9
-
10
- it 'does not strip scroll down escape code' do
11
- expect(Rainbow.uncolor("\e[1Thello")).to eq "\e[1Thello"
12
- end
13
-
14
- end
data/spec/spec_helper.rb DELETED
@@ -1,10 +0,0 @@
1
- if ENV["CI"] && (!defined?(RUBY_ENGINE) || RUBY_ENGINE == "ruby")
2
- require 'coveralls'
3
- Coveralls.wear!
4
- end
5
-
6
- Dir[File.expand_path('../support/**/*.rb', __FILE__)].each { |file| require file }
7
-
8
- RSpec.configure do |config|
9
- config.disable_monkey_patching!
10
- end
@@ -1,9 +0,0 @@
1
- RSpec.shared_examples_for "presenter with shortcut color methods" do
2
- %i[black red green yellow blue magenta cyan white aqua].each do |name|
3
- describe "##{name}" do
4
- subject { presenter.public_send(name) }
5
-
6
- it { should eq(presenter.color(name)) }
7
- end
8
- end
9
- end
@@ -1,296 +0,0 @@
1
- require 'spec_helper'
2
- require 'rainbow/color'
3
-
4
- module Rainbow
5
- RSpec.describe Color do
6
- describe '.build' do
7
- subject { described_class.build(ground, values) }
8
-
9
- let(:ground) { :foreground }
10
-
11
- context "when single fixnum given" do
12
- let(:values) { [1] }
13
-
14
- it { should be_instance_of(Color::Indexed) }
15
-
16
- specify { expect(subject.ground).to eq(ground) }
17
- specify { expect(subject.num).to eq(1) }
18
- end
19
-
20
- context "when single ansi symbol given" do
21
- let(:values) { [:red] }
22
-
23
- it { should be_instance_of(Color::Named) }
24
-
25
- specify { expect(subject.ground).to eq(ground) }
26
- specify { expect(subject.num).to eq(1) }
27
- end
28
-
29
- context "when single x11 symbol given" do
30
- let(:values) { [:midnightblue] }
31
-
32
- it { should be_instance_of(Color::X11Named) }
33
-
34
- specify { expect(subject.ground).to eq(ground) }
35
- specify { expect(subject.r).to eq(25) }
36
- specify { expect(subject.g).to eq(25) }
37
- specify { expect(subject.b).to eq(112) }
38
- end
39
-
40
- context "when single string given" do
41
- let(:values) { ['#deadcc'] }
42
-
43
- it { should be_instance_of(Color::RGB) }
44
-
45
- specify { expect(subject.ground).to eq(ground) }
46
- specify { expect(subject.r).to eq(222) }
47
- specify { expect(subject.g).to eq(173) }
48
- specify { expect(subject.b).to eq(204) }
49
- end
50
-
51
- context "when 2 elements" do
52
- let(:values) { [1, 2] }
53
-
54
- it 'raises ArgumentError' do
55
- expect { subject }.to raise_error(ArgumentError)
56
- end
57
- end
58
-
59
- context "when 3 elements given" do
60
- let(:values) { [1, 2, 3] }
61
-
62
- it { should be_instance_of(Color::RGB) }
63
-
64
- specify { expect(subject.ground).to eq(ground) }
65
- specify { expect(subject.r).to eq(1) }
66
- specify { expect(subject.g).to eq(2) }
67
- specify { expect(subject.b).to eq(3) }
68
- end
69
-
70
- context "when 4 elements" do
71
- let(:values) { [1, 2, 3, 4] }
72
-
73
- it 'raises ArgumentError' do
74
- expect { subject }.to raise_error(ArgumentError)
75
- end
76
- end
77
- end
78
- end
79
-
80
- RSpec.describe Color::Indexed do
81
- let(:color) { described_class.new(ground, 5) }
82
-
83
- describe '#codes' do
84
- subject { color.codes }
85
-
86
- context "when ground is :foreground" do
87
- let(:ground) { :foreground }
88
-
89
- it { should eq([35]) }
90
- end
91
-
92
- context "when ground is :background" do
93
- let(:ground) { :background }
94
-
95
- it { should eq([45]) }
96
- end
97
- end
98
- end
99
-
100
- RSpec.describe Color::Named do
101
- let(:color) { described_class.new(ground, name) }
102
-
103
- describe '#codes' do
104
- subject { color.codes }
105
-
106
- context "when ground is :foreground" do
107
- let(:ground) { :foreground }
108
-
109
- context "and name is :black" do
110
- let(:name) { :black }
111
-
112
- it { should eq([30]) }
113
- end
114
-
115
- context "and name is :red" do
116
- let(:name) { :red }
117
-
118
- it { should eq([31]) }
119
- end
120
-
121
- context "and name is :green" do
122
- let(:name) { :green }
123
-
124
- it { should eq([32]) }
125
- end
126
-
127
- context "and name is :yellow" do
128
- let(:name) { :yellow }
129
-
130
- it { should eq([33]) }
131
- end
132
-
133
- context "and name is :blue" do
134
- let(:name) { :blue }
135
-
136
- it { should eq([34]) }
137
- end
138
-
139
- context "and name is :magenta" do
140
- let(:name) { :magenta }
141
-
142
- it { should eq([35]) }
143
- end
144
-
145
- context "and name is :cyan" do
146
- let(:name) { :cyan }
147
-
148
- it { should eq([36]) }
149
- end
150
-
151
- context "and name is :white" do
152
- let(:name) { :white }
153
-
154
- it { should eq([37]) }
155
- end
156
-
157
- context "and name is invalid" do
158
- let(:name) { :foo }
159
-
160
- it 'raises ArgumentError' do
161
- expect { subject }.to raise_error(ArgumentError)
162
- end
163
- end
164
- end
165
-
166
- context "when ground is :background" do
167
- let(:ground) { :background }
168
-
169
- context "and name is :black" do
170
- let(:name) { :black }
171
-
172
- it { should eq([40]) }
173
- end
174
-
175
- context "and name is :red" do
176
- let(:name) { :red }
177
-
178
- it { should eq([41]) }
179
- end
180
-
181
- context "and name is :green" do
182
- let(:name) { :green }
183
-
184
- it { should eq([42]) }
185
- end
186
-
187
- context "and name is :yellow" do
188
- let(:name) { :yellow }
189
-
190
- it { should eq([43]) }
191
- end
192
-
193
- context "and name is :blue" do
194
- let(:name) { :blue }
195
-
196
- it { should eq([44]) }
197
- end
198
-
199
- context "and name is :magenta" do
200
- let(:name) { :magenta }
201
-
202
- it { should eq([45]) }
203
- end
204
-
205
- context "and name is :cyan" do
206
- let(:name) { :cyan }
207
-
208
- it { should eq([46]) }
209
- end
210
-
211
- context "and name is :white" do
212
- let(:name) { :white }
213
-
214
- it { should eq([47]) }
215
- end
216
-
217
- context "and name is invalid" do
218
- let(:name) { :foo }
219
-
220
- it 'raises ArgumentError' do
221
- expect { subject }.to raise_error(ArgumentError)
222
- end
223
- end
224
- end
225
- end
226
- end
227
-
228
- RSpec.describe Color::RGB do
229
- let(:color) { described_class.new(ground, r, g, b) }
230
-
231
- describe '#codes' do
232
- subject { color.codes }
233
-
234
- let(:ground) { :foreground }
235
- let(:r) { 0 }
236
- let(:g) { 128 }
237
- let(:b) { 255 }
238
-
239
- context "when ground is :foreground" do
240
- let(:ground) { :foreground }
241
-
242
- it { should eq([38, 5, 39]) }
243
- end
244
-
245
- context "when ground is :background" do
246
- let(:ground) { :background }
247
-
248
- it { should eq([48, 5, 39]) }
249
- end
250
-
251
- context "when a component is lower than 0" do
252
- let(:r) { -1 }
253
-
254
- it 'raises ArgumentError' do
255
- expect { subject }.to raise_error(ArgumentError)
256
- end
257
- end
258
-
259
- context "when a component is greater than 255" do
260
- let(:b) { 256 }
261
-
262
- it 'raises ArgumentError' do
263
- expect { subject }.to raise_error(ArgumentError)
264
- end
265
- end
266
- end
267
- end
268
-
269
- RSpec.describe Color::X11Named do
270
- let(:color) { described_class.new(ground, name) }
271
-
272
- describe '#codes' do
273
- subject { color.codes }
274
-
275
- context "when ground is :foreground" do
276
- let(:name) { :midnightblue }
277
- let(:ground) { :foreground }
278
- it { should eq([38, 5, 18]) }
279
- end
280
-
281
- context "when ground is :background" do
282
- let(:name) { :midnightblue }
283
- let(:ground) { :background }
284
- it { should eq([48, 5, 18]) }
285
- end
286
-
287
- context "when name is invalid" do
288
- let(:name) { :foo }
289
- let(:ground) { :background }
290
- it 'raises ArgumentError' do
291
- expect { subject }.to raise_error(ArgumentError)
292
- end
293
- end
294
- end
295
- end
296
- end
@@ -1,110 +0,0 @@
1
- require 'spec_helper'
2
- require 'rainbow/null_presenter'
3
-
4
- module Rainbow
5
- RSpec.describe NullPresenter do
6
- let(:presenter) { described_class.new('hello') }
7
-
8
- shared_examples_for "rainbow null string method" do
9
- it "doesn't wrap the text with any sgr sequence" do
10
- expect(subject).to eq('hello')
11
- end
12
-
13
- it "returns an instance of Rainbow::NullPresenter" do
14
- expect(subject).to be_kind_of(Rainbow::NullPresenter)
15
- end
16
- end
17
-
18
- describe '#color' do
19
- subject { presenter.color(:arg1, 'arg2') }
20
-
21
- it_behaves_like "rainbow null string method"
22
- end
23
-
24
- describe '#foreground' do
25
- subject { presenter.foreground(:arg1, 'arg2') }
26
-
27
- it_behaves_like "rainbow null string method"
28
- end
29
-
30
- describe '#fg' do
31
- subject { presenter.fg(:arg1, 'arg2') }
32
-
33
- it_behaves_like "rainbow null string method"
34
- end
35
-
36
- describe '#background' do
37
- subject { presenter.background(:arg1, 'arg2') }
38
-
39
- it_behaves_like "rainbow null string method"
40
- end
41
-
42
- describe '#bg' do
43
- subject { presenter.bg(:arg1, 'arg2') }
44
-
45
- it_behaves_like "rainbow null string method"
46
- end
47
-
48
- describe '#reset' do
49
- subject { presenter.reset }
50
-
51
- it_behaves_like "rainbow null string method"
52
- end
53
-
54
- describe '#bright' do
55
- subject { presenter.bright }
56
-
57
- it_behaves_like "rainbow null string method"
58
- end
59
-
60
- describe '#bold' do
61
- subject { presenter.bold }
62
-
63
- it_behaves_like "rainbow null string method"
64
- end
65
-
66
- describe '#faint' do
67
- subject { presenter.faint }
68
-
69
- it_behaves_like "rainbow null string method"
70
- end
71
-
72
- describe '#dark' do
73
- subject { presenter.dark }
74
-
75
- it_behaves_like "rainbow null string method"
76
- end
77
-
78
- describe '#italic' do
79
- subject { presenter.italic }
80
-
81
- it_behaves_like "rainbow null string method"
82
- end
83
-
84
- describe '#underline' do
85
- subject { presenter.underline }
86
-
87
- it_behaves_like "rainbow null string method"
88
- end
89
-
90
- describe '#blink' do
91
- subject { presenter.blink }
92
-
93
- it_behaves_like "rainbow null string method"
94
- end
95
-
96
- describe '#inverse' do
97
- subject { presenter.inverse }
98
-
99
- it_behaves_like "rainbow null string method"
100
- end
101
-
102
- describe '#hide' do
103
- subject { presenter.hide }
104
-
105
- it_behaves_like "rainbow null string method"
106
- end
107
-
108
- it_behaves_like "presenter with shortcut color methods"
109
- end
110
- end
@@ -1,199 +0,0 @@
1
- require 'spec_helper'
2
- require 'rainbow/presenter'
3
-
4
- module Rainbow
5
- RSpec.describe Presenter do
6
- let(:presenter) { described_class.new('hello') }
7
-
8
- shared_examples_for "rainbow string method" do
9
- it "wraps the text with a sgr sequence" do
10
- expect(subject).to eq('[hello]')
11
- end
12
-
13
- it "returns an instance of Rainbow::Presenter" do
14
- expect(subject).to be_kind_of(Rainbow::Presenter)
15
- end
16
- end
17
-
18
- shared_examples_for "text color method" do
19
- let(:color) { double('color', codes: [1, 2]) }
20
-
21
- before do
22
- allow(Color).to receive(:build)
23
- .with(:foreground, [:arg1, 'arg2']) { color }
24
- end
25
-
26
- it_behaves_like "rainbow string method"
27
-
28
- it 'wraps with color codes' do
29
- subject
30
- expect(StringUtils).to have_received(:wrap_with_sgr)
31
- .with('hello', [1, 2])
32
- end
33
- end
34
-
35
- shared_examples_for "text background method" do
36
- let(:color) { double('color', codes: [1, 2]) }
37
-
38
- before do
39
- allow(Color).to receive(:build)
40
- .with(:background, [:arg1, 'arg2']) { color }
41
- end
42
-
43
- it_behaves_like "rainbow string method"
44
-
45
- it 'wraps with color codes' do
46
- subject
47
- expect(StringUtils).to have_received(:wrap_with_sgr)
48
- .with('hello', [1, 2])
49
- end
50
- end
51
-
52
- before do
53
- allow(StringUtils).to receive(:wrap_with_sgr) { '[hello]' }
54
- end
55
-
56
- describe '#color' do
57
- subject { presenter.color(:arg1, 'arg2') }
58
-
59
- it_behaves_like "text color method"
60
- end
61
-
62
- describe '#foreground' do
63
- subject { presenter.foreground(:arg1, 'arg2') }
64
-
65
- it_behaves_like "text color method"
66
- end
67
-
68
- describe '#fg' do
69
- subject { presenter.fg(:arg1, 'arg2') }
70
-
71
- it_behaves_like "text color method"
72
- end
73
-
74
- describe '#background' do
75
- subject { presenter.background(:arg1, 'arg2') }
76
-
77
- it_behaves_like "text background method"
78
- end
79
-
80
- describe '#bg' do
81
- subject { presenter.bg(:arg1, 'arg2') }
82
-
83
- it_behaves_like "text background method"
84
- end
85
-
86
- describe '#reset' do
87
- subject { presenter.reset }
88
-
89
- it_behaves_like "rainbow string method"
90
-
91
- it 'wraps with 0 code' do
92
- subject
93
- expect(StringUtils).to have_received(:wrap_with_sgr).with('hello', [0])
94
- end
95
- end
96
-
97
- describe '#bright' do
98
- subject { presenter.bright }
99
-
100
- it_behaves_like "rainbow string method"
101
-
102
- it 'wraps with 1 code' do
103
- subject
104
- expect(StringUtils).to have_received(:wrap_with_sgr).with('hello', [1])
105
- end
106
- end
107
-
108
- describe '#bold' do
109
- subject { presenter.bold }
110
-
111
- it_behaves_like "rainbow string method"
112
-
113
- it 'wraps with 1 code' do
114
- subject
115
- expect(StringUtils).to have_received(:wrap_with_sgr).with('hello', [1])
116
- end
117
- end
118
-
119
- describe '#faint' do
120
- subject { presenter.faint }
121
-
122
- it_behaves_like "rainbow string method"
123
-
124
- it 'wraps with 2 code' do
125
- subject
126
- expect(StringUtils).to have_received(:wrap_with_sgr).with('hello', [2])
127
- end
128
- end
129
-
130
- describe '#dark' do
131
- subject { presenter.dark }
132
-
133
- it_behaves_like "rainbow string method"
134
-
135
- it 'wraps with 2 code' do
136
- subject
137
- expect(StringUtils).to have_received(:wrap_with_sgr).with('hello', [2])
138
- end
139
- end
140
-
141
- describe '#italic' do
142
- subject { presenter.italic }
143
-
144
- it_behaves_like "rainbow string method"
145
-
146
- it 'wraps with 3 code' do
147
- subject
148
- expect(StringUtils).to have_received(:wrap_with_sgr)
149
- .with('hello', [3])
150
- end
151
- end
152
-
153
- describe '#underline' do
154
- subject { presenter.underline }
155
-
156
- it_behaves_like "rainbow string method"
157
-
158
- it 'wraps with 4 code' do
159
- subject
160
- expect(StringUtils).to have_received(:wrap_with_sgr).with('hello', [4])
161
- end
162
- end
163
-
164
- describe '#blink' do
165
- subject { presenter.blink }
166
-
167
- it_behaves_like "rainbow string method"
168
-
169
- it 'wraps with 5 code' do
170
- subject
171
- expect(StringUtils).to have_received(:wrap_with_sgr).with('hello', [5])
172
- end
173
- end
174
-
175
- describe '#inverse' do
176
- subject { presenter.inverse }
177
-
178
- it_behaves_like "rainbow string method"
179
-
180
- it 'wraps with 7 code' do
181
- subject
182
- expect(StringUtils).to have_received(:wrap_with_sgr).with('hello', [7])
183
- end
184
- end
185
-
186
- describe '#hide' do
187
- subject { presenter.hide }
188
-
189
- it_behaves_like "rainbow string method"
190
-
191
- it 'wraps with 8 code' do
192
- subject
193
- expect(StringUtils).to have_received(:wrap_with_sgr).with('hello', [8])
194
- end
195
- end
196
-
197
- it_behaves_like "presenter with shortcut color methods"
198
- end
199
- end