lovely_rufus 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -7
- data/.ruby-version +1 -1
- data/Gemfile.lock +41 -26
- data/README.md +2 -2
- data/Rakefile +5 -6
- data/bin/lovely-rufus +1 -1
- data/config/reek.yml +7 -7
- data/lib/lovely_rufus.rb +9 -6
- data/lib/lovely_rufus/cli_wrapper.rb +1 -2
- data/lib/lovely_rufus/layers/basic_wrapper.rb +14 -0
- data/lib/lovely_rufus/layers/code_comment_stripper.rb +13 -0
- data/lib/lovely_rufus/layers/email_quote_stripper.rb +15 -0
- data/lib/lovely_rufus/layers/hangout_wrapper.rb +57 -0
- data/lib/lovely_rufus/layers/layer.rb +15 -0
- data/lib/lovely_rufus/layers/one_letter_gluer.rb +14 -0
- data/lib/lovely_rufus/layers/quote_stripper.rb +29 -0
- data/lib/lovely_rufus/text_wrapper.rb +11 -7
- data/lovely_rufus.gemspec +6 -4
- data/{spec/lovely_rufus/cli_wrapper_spec.rb → test/lovely_rufus/cli_wrapper_test.rb} +5 -5
- data/test/lovely_rufus/layers/basic_wrapper_test.rb +55 -0
- data/test/lovely_rufus/layers/code_comment_stripper_test.rb +90 -0
- data/test/lovely_rufus/layers/email_quote_stripper_test.rb +101 -0
- data/test/lovely_rufus/layers/hangout_wrapper_test.rb +40 -0
- data/test/lovely_rufus/layers/one_letter_gluer_test.rb +33 -0
- data/{spec/lovely_rufus/settings_spec.rb → test/lovely_rufus/settings_test.rb} +1 -1
- data/{spec/lovely_rufus/text_wrapper_spec.rb → test/lovely_rufus/text_wrapper_test.rb} +2 -2
- data/{spec/lovely_rufus/text_wrapper_spec.yml → test/lovely_rufus/text_wrapper_test.yml} +0 -0
- data/{spec/lovely_rufus/wrap_spec.rb → test/lovely_rufus/wrap_test.rb} +3 -3
- data/{spec/lovely_rufus_spec.rb → test/lovely_rufus_test.rb} +1 -1
- data/test/test_helper.rb +37 -0
- metadata +51 -33
- data/lib/lovely_rufus/basic_wrapper.rb +0 -12
- data/lib/lovely_rufus/hangout_wrapper.rb +0 -56
- data/lib/lovely_rufus/layer.rb +0 -14
- data/lib/lovely_rufus/one_letter_gluer.rb +0 -12
- data/lib/lovely_rufus/quote_stripper.rb +0 -32
- data/spec/lovely_rufus/basic_wrapper_spec.rb +0 -53
- data/spec/lovely_rufus/hangout_wrapper_spec.rb +0 -38
- data/spec/lovely_rufus/one_letter_gluer_spec.rb +0 -31
- data/spec/lovely_rufus/quote_stripper_spec.rb +0 -131
- data/spec/spec_helper.rb +0 -14
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lovely_rufus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Szotkowski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: private_attr
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bogus
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,14 +86,14 @@ dependencies:
|
|
72
86
|
requirements:
|
73
87
|
- - "~>"
|
74
88
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
89
|
+
version: '2.0'
|
76
90
|
type: :development
|
77
91
|
prerelease: false
|
78
92
|
version_requirements: !ruby/object:Gem::Requirement
|
79
93
|
requirements:
|
80
94
|
- - "~>"
|
81
95
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
96
|
+
version: '2.0'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: rerun
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -100,14 +114,14 @@ dependencies:
|
|
100
114
|
requirements:
|
101
115
|
- - "~>"
|
102
116
|
- !ruby/object:Gem::Version
|
103
|
-
version: 0.
|
117
|
+
version: 0.29.0
|
104
118
|
type: :development
|
105
119
|
prerelease: false
|
106
120
|
version_requirements: !ruby/object:Gem::Requirement
|
107
121
|
requirements:
|
108
122
|
- - "~>"
|
109
123
|
- !ruby/object:Gem::Version
|
110
|
-
version: 0.
|
124
|
+
version: 0.29.0
|
111
125
|
description: An executable and a Ruby library for wrapping paragraphs of text.
|
112
126
|
email: chastell@chastell.net
|
113
127
|
executables:
|
@@ -125,27 +139,30 @@ files:
|
|
125
139
|
- bin/lovely-rufus
|
126
140
|
- config/reek.yml
|
127
141
|
- lib/lovely_rufus.rb
|
128
|
-
- lib/lovely_rufus/basic_wrapper.rb
|
129
142
|
- lib/lovely_rufus/cli_wrapper.rb
|
130
|
-
- lib/lovely_rufus/
|
131
|
-
- lib/lovely_rufus/
|
132
|
-
- lib/lovely_rufus/
|
133
|
-
- lib/lovely_rufus/
|
143
|
+
- lib/lovely_rufus/layers/basic_wrapper.rb
|
144
|
+
- lib/lovely_rufus/layers/code_comment_stripper.rb
|
145
|
+
- lib/lovely_rufus/layers/email_quote_stripper.rb
|
146
|
+
- lib/lovely_rufus/layers/hangout_wrapper.rb
|
147
|
+
- lib/lovely_rufus/layers/layer.rb
|
148
|
+
- lib/lovely_rufus/layers/one_letter_gluer.rb
|
149
|
+
- lib/lovely_rufus/layers/quote_stripper.rb
|
134
150
|
- lib/lovely_rufus/settings.rb
|
135
151
|
- lib/lovely_rufus/text_wrapper.rb
|
136
152
|
- lib/lovely_rufus/wrap.rb
|
137
153
|
- lovely_rufus.gemspec
|
138
|
-
-
|
139
|
-
-
|
140
|
-
-
|
141
|
-
-
|
142
|
-
-
|
143
|
-
-
|
144
|
-
-
|
145
|
-
-
|
146
|
-
-
|
147
|
-
-
|
148
|
-
-
|
154
|
+
- test/lovely_rufus/cli_wrapper_test.rb
|
155
|
+
- test/lovely_rufus/layers/basic_wrapper_test.rb
|
156
|
+
- test/lovely_rufus/layers/code_comment_stripper_test.rb
|
157
|
+
- test/lovely_rufus/layers/email_quote_stripper_test.rb
|
158
|
+
- test/lovely_rufus/layers/hangout_wrapper_test.rb
|
159
|
+
- test/lovely_rufus/layers/one_letter_gluer_test.rb
|
160
|
+
- test/lovely_rufus/settings_test.rb
|
161
|
+
- test/lovely_rufus/text_wrapper_test.rb
|
162
|
+
- test/lovely_rufus/text_wrapper_test.yml
|
163
|
+
- test/lovely_rufus/wrap_test.rb
|
164
|
+
- test/lovely_rufus_test.rb
|
165
|
+
- test/test_helper.rb
|
149
166
|
homepage: http://github.com/chastell/lovely_rufus
|
150
167
|
licenses:
|
151
168
|
- AGPL-3.0
|
@@ -166,18 +183,19 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
166
183
|
version: '0'
|
167
184
|
requirements: []
|
168
185
|
rubyforge_project:
|
169
|
-
rubygems_version: 2.
|
186
|
+
rubygems_version: 2.4.5
|
170
187
|
signing_key:
|
171
188
|
specification_version: 4
|
172
189
|
summary: 'lovely_rufus: text wrapper'
|
173
190
|
test_files:
|
174
|
-
-
|
175
|
-
-
|
176
|
-
-
|
177
|
-
-
|
178
|
-
-
|
179
|
-
-
|
180
|
-
-
|
181
|
-
-
|
182
|
-
-
|
183
|
-
-
|
191
|
+
- test/lovely_rufus/cli_wrapper_test.rb
|
192
|
+
- test/lovely_rufus/layers/basic_wrapper_test.rb
|
193
|
+
- test/lovely_rufus/layers/code_comment_stripper_test.rb
|
194
|
+
- test/lovely_rufus/layers/email_quote_stripper_test.rb
|
195
|
+
- test/lovely_rufus/layers/hangout_wrapper_test.rb
|
196
|
+
- test/lovely_rufus/layers/one_letter_gluer_test.rb
|
197
|
+
- test/lovely_rufus/settings_test.rb
|
198
|
+
- test/lovely_rufus/text_wrapper_test.rb
|
199
|
+
- test/lovely_rufus/wrap_test.rb
|
200
|
+
- test/lovely_rufus_test.rb
|
201
|
+
- test/test_helper.rb
|
@@ -1,12 +0,0 @@
|
|
1
|
-
require_relative 'layer'
|
2
|
-
require_relative 'wrap'
|
3
|
-
|
4
|
-
module LovelyRufus
|
5
|
-
class BasicWrapper < Layer
|
6
|
-
def call(wrap)
|
7
|
-
unwrapped = wrap.text.tr("\n", ' ').strip
|
8
|
-
wrapped = unwrapped.gsub(/(.{1,#{wrap.width}})( |$\n?)/, "\\1\n")
|
9
|
-
next_layer.call(Wrap[wrapped, width: wrap.width])
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
require_relative 'basic_wrapper'
|
2
|
-
require_relative 'layer'
|
3
|
-
require_relative 'wrap'
|
4
|
-
|
5
|
-
module LovelyRufus
|
6
|
-
class HangoutWrapper < Layer
|
7
|
-
def call(wrap)
|
8
|
-
@wrap = wrap
|
9
|
-
final = hangout_line ? rewrapped : wrap
|
10
|
-
next_layer.call(final)
|
11
|
-
end
|
12
|
-
|
13
|
-
attr_reader :wrap
|
14
|
-
private :wrap
|
15
|
-
|
16
|
-
private
|
17
|
-
|
18
|
-
module HangoutFinder
|
19
|
-
module_function
|
20
|
-
|
21
|
-
def between?(line_a, line_b)
|
22
|
-
last_space = line_a.chomp.rindex(/\p{space}/)
|
23
|
-
last_space and last_space >= line_b.chomp.size
|
24
|
-
end
|
25
|
-
|
26
|
-
def reverse?(line_a, line_b)
|
27
|
-
cut = line_a.chomp.rindex(/\p{space}/)
|
28
|
-
a_after = line_a[0...cut] + "\n"
|
29
|
-
b_after = line_a[(cut + 1)..-1] + line_b
|
30
|
-
b_after.chomp.rindex(/\p{space}/) > a_after.size
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def hangout_line
|
35
|
-
lines.each_cons(2).with_index do |(a, b), i|
|
36
|
-
if HangoutFinder.between?(a, b)
|
37
|
-
return a unless i == lines.size - 2 and HangoutFinder.reverse?(a, b)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def lines
|
43
|
-
@lines ||= wrap.lines
|
44
|
-
end
|
45
|
-
|
46
|
-
def rewrapped
|
47
|
-
hangout_line[-1] = NBSP
|
48
|
-
HangoutWrapper.new.call(wrapped)
|
49
|
-
end
|
50
|
-
|
51
|
-
def wrapped
|
52
|
-
unfolded = Wrap[lines.join, width: wrap.width]
|
53
|
-
BasicWrapper.new.call(unfolded)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
data/lib/lovely_rufus/layer.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
module LovelyRufus
|
2
|
-
class Layer
|
3
|
-
def initialize(next_layer = -> (wrap) { wrap })
|
4
|
-
@next_layer = next_layer
|
5
|
-
end
|
6
|
-
|
7
|
-
def call(_opts = {})
|
8
|
-
fail 'Layer subclasses must define #call'
|
9
|
-
end
|
10
|
-
|
11
|
-
attr_reader :next_layer
|
12
|
-
private :next_layer
|
13
|
-
end
|
14
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
require_relative 'layer'
|
2
|
-
require_relative 'wrap'
|
3
|
-
|
4
|
-
module LovelyRufus
|
5
|
-
class OneLetterGluer < Layer
|
6
|
-
def call(wrap)
|
7
|
-
pattern = /(?<=\p{space})(&|\p{letter})\p{space}/
|
8
|
-
text = wrap.text.gsub(pattern, "\\1\\2#{NBSP}")
|
9
|
-
next_layer.call(Wrap[text, width: wrap.width])
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
require_relative 'layer'
|
2
|
-
require_relative 'wrap'
|
3
|
-
|
4
|
-
module LovelyRufus
|
5
|
-
class QuoteStripper < Layer
|
6
|
-
def call(wrap)
|
7
|
-
@wrap = wrap
|
8
|
-
wrapped = next_layer.call(stripped_wrap)
|
9
|
-
quoted = wrapped.lines.map { |line| fixed_quote + line }.join
|
10
|
-
Wrap[quoted, width: wrapped.width + fixed_quote.size]
|
11
|
-
end
|
12
|
-
|
13
|
-
attr_reader :wrap
|
14
|
-
private :wrap
|
15
|
-
|
16
|
-
private
|
17
|
-
|
18
|
-
def fixed_quote
|
19
|
-
quote.size > 0 ? quote.delete(' ') + ' ' : ''
|
20
|
-
end
|
21
|
-
|
22
|
-
def quote
|
23
|
-
starts = wrap.lines.map { |line| line[QUOTES] }.uniq
|
24
|
-
starts.size == 1 ? starts.first || '' : ''
|
25
|
-
end
|
26
|
-
|
27
|
-
def stripped_wrap
|
28
|
-
stripped_text = wrap.lines.map { |line| line[quote.size..-1] }.join
|
29
|
-
Wrap[stripped_text, width: wrap.width - fixed_quote.size]
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
require_relative '../spec_helper'
|
2
|
-
require_relative '../../lib/lovely_rufus/basic_wrapper'
|
3
|
-
require_relative '../../lib/lovely_rufus/wrap'
|
4
|
-
|
5
|
-
module LovelyRufus
|
6
|
-
describe BasicWrapper do
|
7
|
-
describe '#call' do
|
8
|
-
it 'wraps text to the given width' do
|
9
|
-
text = 'I go crazy when I hear a cymbal and a hi-hat ' \
|
10
|
-
'with a souped-up tempo'
|
11
|
-
wrap = <<-end.dedent
|
12
|
-
I go crazy when I hear
|
13
|
-
a cymbal and a hi-hat
|
14
|
-
with a souped-up tempo
|
15
|
-
end
|
16
|
-
bw = BasicWrapper.new
|
17
|
-
bw.call(Wrap[text, width: 22]).must_equal Wrap[wrap, width: 22]
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'extends past the given width when necessary' do
|
21
|
-
text = 'I’m killing your brain like a poisonous mushroom'
|
22
|
-
wrap = <<-end.dedent
|
23
|
-
I’m
|
24
|
-
killing
|
25
|
-
your
|
26
|
-
brain
|
27
|
-
like
|
28
|
-
a
|
29
|
-
poisonous
|
30
|
-
mushroom
|
31
|
-
end
|
32
|
-
bw = BasicWrapper.new
|
33
|
-
bw.call(Wrap[text, width: 5]).must_equal Wrap[wrap, width: 5]
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'rewraps a String from zero' do
|
37
|
-
text = <<-end.dedent
|
38
|
-
turn off
|
39
|
-
the lights and I’ll glow
|
40
|
-
end
|
41
|
-
wrap = "turn off the lights and I’ll glow\n"
|
42
|
-
BasicWrapper.new.call(Wrap[text]).must_equal Wrap[wrap]
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'passes the fixed text to the next layer and returns its outcome' do
|
46
|
-
final = fake(:wrap)
|
47
|
-
layer = fake(:layer)
|
48
|
-
mock(layer).call(Wrap["I\nO\nU\n", width: 2]) { final }
|
49
|
-
BasicWrapper.new(layer).call(Wrap['I O U', width: 2]).must_equal final
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
require_relative '../spec_helper'
|
2
|
-
require_relative '../../lib/lovely_rufus/hangout_wrapper'
|
3
|
-
require_relative '../../lib/lovely_rufus/wrap'
|
4
|
-
|
5
|
-
module LovelyRufus
|
6
|
-
describe HangoutWrapper do
|
7
|
-
describe '#call' do
|
8
|
-
it 'removes hangouts from the text' do
|
9
|
-
text = <<-end.dedent
|
10
|
-
I go crazy when I hear a cymbal and
|
11
|
-
a hi-hat with a souped-up tempo
|
12
|
-
end
|
13
|
-
wrap = <<-end.dedent
|
14
|
-
I go crazy when I hear a cymbal
|
15
|
-
and a hi-hat with a souped-up tempo
|
16
|
-
end
|
17
|
-
hw = HangoutWrapper.new
|
18
|
-
hw.call(Wrap[text, width: 35]).must_equal Wrap[wrap, width: 35]
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'passes the fixed text to the next layer and returns its outcome' do
|
22
|
-
final = fake(:wrap)
|
23
|
-
layer = fake(:layer)
|
24
|
-
mock(layer).call(any(Wrap)) { final }
|
25
|
-
wrapped = HangoutWrapper.new(layer).call(Wrap["I O\nU", width: 4])
|
26
|
-
wrapped.must_equal final
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'doesn’t let the last line to hang out' do
|
30
|
-
text = <<-end.dedent
|
31
|
-
Just found out the Finnish term for grammar Nazi is pilkunnussija.
|
32
|
-
Direct translation: comma fucker. You’re welcome.
|
33
|
-
end
|
34
|
-
HangoutWrapper.new.call(Wrap[text, width: 76]).text.must_equal text
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
require_relative '../spec_helper'
|
2
|
-
require_relative '../../lib/lovely_rufus/one_letter_gluer'
|
3
|
-
require_relative '../../lib/lovely_rufus/wrap'
|
4
|
-
|
5
|
-
module LovelyRufus
|
6
|
-
describe OneLetterGluer do
|
7
|
-
describe '#call' do
|
8
|
-
it 'replaces spaces after one-letter words with non-break spaces' do
|
9
|
-
text = 'I go crazy when I hear a cymbal and a hi-hat'
|
10
|
-
glue = 'I go crazy when I hear a cymbal and a hi-hat'
|
11
|
-
olg = OneLetterGluer.new
|
12
|
-
olg.call(Wrap[text, width: 42]).must_equal Wrap[glue, width: 42]
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'glues subsequent one-letter words' do
|
16
|
-
text = 'one-letter words in English: a, I & o'
|
17
|
-
glue = 'one-letter words in English: a, I & o'
|
18
|
-
olg = OneLetterGluer.new
|
19
|
-
olg.call(Wrap[text, width: 42]).must_equal Wrap[glue, width: 42]
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'passes the fixed text to the next layer and returns its outcome' do
|
23
|
-
final = fake(:wrap)
|
24
|
-
layer = fake(:layer)
|
25
|
-
mock(layer).call(Wrap['I O U', width: 69]) { final }
|
26
|
-
glued = OneLetterGluer.new(layer).call(Wrap['I O U', width: 69])
|
27
|
-
glued.must_equal final
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,131 +0,0 @@
|
|
1
|
-
require_relative '../spec_helper'
|
2
|
-
require_relative '../../lib/lovely_rufus/quote_stripper'
|
3
|
-
require_relative '../../lib/lovely_rufus/wrap'
|
4
|
-
|
5
|
-
module LovelyRufus
|
6
|
-
describe QuoteStripper do
|
7
|
-
describe '#call' do
|
8
|
-
it 'strips quotes and adjusts width before calling the next layer' do
|
9
|
-
quoted = <<-end.dedent
|
10
|
-
> to the extreme I rock a mic like a vandal
|
11
|
-
> light up a stage and wax a chump like a candle
|
12
|
-
end
|
13
|
-
unquoted = <<-end.dedent
|
14
|
-
to the extreme I rock a mic like a vandal
|
15
|
-
light up a stage and wax a chump like a candle
|
16
|
-
end
|
17
|
-
layer = fake(:layer, call: Wrap[unquoted, width: 70])
|
18
|
-
QuoteStripper.new(layer).call(Wrap[quoted, width: 72])
|
19
|
-
layer.must_have_received :call, [Wrap[unquoted, width: 70]]
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'adds quotes back in (and adjusts width) before returning' do
|
23
|
-
quoted = <<-end.dedent
|
24
|
-
> take heed, ’cause I’m a lyrical poet
|
25
|
-
> Miami’s on the scene just in case you didn’t know it
|
26
|
-
end
|
27
|
-
wrap = Wrap[quoted, width: 72]
|
28
|
-
QuoteStripper.new.call(wrap).must_equal wrap
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'does not touch non-quoted texts' do
|
32
|
-
plain = <<-end.dedent
|
33
|
-
my town, that created all the bass sound
|
34
|
-
enough to shake and kick holes in the ground
|
35
|
-
end
|
36
|
-
wrap = Wrap[plain, width: 72]
|
37
|
-
QuoteStripper.new.call(wrap).must_equal wrap
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'does not alter text contents' do
|
41
|
-
wrap = Wrap['> Ice > Ice > Baby']
|
42
|
-
QuoteStripper.new.call(wrap).must_equal wrap
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'strips multilevel quotes' do
|
46
|
-
quoted = <<-end.dedent
|
47
|
-
>> ’cause my style’s like a chemical spill
|
48
|
-
>> feasible rhymes that you can vision and feel
|
49
|
-
end
|
50
|
-
unquoted = <<-end.dedent
|
51
|
-
’cause my style’s like a chemical spill
|
52
|
-
feasible rhymes that you can vision and feel
|
53
|
-
end
|
54
|
-
layer = fake(:layer, call: Wrap[unquoted, width: 69])
|
55
|
-
QuoteStripper.new(layer).call(Wrap[quoted, width: 72])
|
56
|
-
layer.must_have_received :call, [Wrap[unquoted, width: 69]]
|
57
|
-
end
|
58
|
-
|
59
|
-
it 'strips broken quotes properly' do
|
60
|
-
quoted = <<-end.dedent
|
61
|
-
> > >conducted and formed this is a hell of a concept
|
62
|
-
> > >we make it hype and you want to step with this
|
63
|
-
end
|
64
|
-
unquoted = <<-end.dedent
|
65
|
-
conducted and formed this is a hell of a concept
|
66
|
-
we make it hype and you want to step with this
|
67
|
-
end
|
68
|
-
layer = fake(:layer, call: Wrap[unquoted, width: 68])
|
69
|
-
QuoteStripper.new(layer).call(Wrap[quoted, width: 72])
|
70
|
-
layer.must_have_received :call, [Wrap[unquoted, width: 68]]
|
71
|
-
end
|
72
|
-
|
73
|
-
it 'fixes broken quotes when adding them back in' do
|
74
|
-
quoted = <<-end.dedent
|
75
|
-
> > >Shay plays on the fade,
|
76
|
-
> > >slice like a ninja
|
77
|
-
> > >cut like a razor blade
|
78
|
-
end
|
79
|
-
fixed = <<-end.dedent
|
80
|
-
>>> Shay plays on the fade,
|
81
|
-
>>> slice like a ninja
|
82
|
-
>>> cut like a razor blade
|
83
|
-
end
|
84
|
-
wrap = Wrap[quoted, width: 72]
|
85
|
-
QuoteStripper.new.call(wrap).must_equal Wrap[fixed, width: 72]
|
86
|
-
end
|
87
|
-
|
88
|
-
it 'strips // code comments' do
|
89
|
-
quoted = <<-end.dedent
|
90
|
-
// so fast other DJs say ‘damn!’
|
91
|
-
// if my rhyme was a drug I’d sell it by the gram
|
92
|
-
end
|
93
|
-
unquoted = <<-end.dedent
|
94
|
-
so fast other DJs say ‘damn!’
|
95
|
-
if my rhyme was a drug I’d sell it by the gram
|
96
|
-
end
|
97
|
-
layer = fake(:layer, call: Wrap[unquoted, width: 69])
|
98
|
-
QuoteStripper.new(layer).call(Wrap[quoted, width: 72])
|
99
|
-
layer.must_have_received :call, [Wrap[unquoted, width: 69]]
|
100
|
-
end
|
101
|
-
|
102
|
-
it 'strips # code comments' do
|
103
|
-
quoted = <<-end.dedent
|
104
|
-
# keep my composure when it’s time to get loose
|
105
|
-
# magnetized by the mic while I kick my juice
|
106
|
-
end
|
107
|
-
unquoted = <<-end.dedent
|
108
|
-
keep my composure when it’s time to get loose
|
109
|
-
magnetized by the mic while I kick my juice
|
110
|
-
end
|
111
|
-
layer = fake(:layer, call: Wrap[unquoted, width: 70])
|
112
|
-
QuoteStripper.new(layer).call(Wrap[quoted, width: 72])
|
113
|
-
layer.must_have_received :call, [Wrap[unquoted, width: 70]]
|
114
|
-
end
|
115
|
-
|
116
|
-
it 'only considers homogenous characters as comments' do
|
117
|
-
quoted = <<-end.dedent
|
118
|
-
> /if there was a problem,
|
119
|
-
> yo – I’ll solve it!/
|
120
|
-
end
|
121
|
-
unquoted = <<-end.dedent
|
122
|
-
/if there was a problem,
|
123
|
-
yo – I’ll solve it!/
|
124
|
-
end
|
125
|
-
layer = fake(:layer, call: Wrap[unquoted, width: 70])
|
126
|
-
QuoteStripper.new(layer).call(Wrap[quoted, width: 72])
|
127
|
-
layer.must_have_received :call, [Wrap[unquoted, width: 70]]
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|