rbpar 0.1.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.
- data/README +58 -0
- data/bin/rbpar.rb +94 -0
- data/lib/rbpar_engine.rb +196 -0
- data/lib/rbpar_main.rb +68 -0
- data/lib/rbpar_paragraph.rb +344 -0
- data/test/rbpar_engine_test.rb +152 -0
- data/test/rbpar_main_test.rb +212 -0
- data/test/rbpar_paragraph_test.rb +305 -0
- data/test/rbpar_test.rb +11 -0
- metadata +54 -0
@@ -0,0 +1,305 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'rbpar_paragraph'
|
5
|
+
|
6
|
+
class TestRbParParagraph < Test::Unit::TestCase
|
7
|
+
|
8
|
+
def test_init
|
9
|
+
|
10
|
+
test_paragraph1 = Paragraph.new()
|
11
|
+
assert_equal("", test_paragraph1.quote_prefix)
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_quoted
|
16
|
+
test_paragraph = Paragraph.new()
|
17
|
+
line1 = ">> test"
|
18
|
+
assert (test_paragraph.quoted?(line1))
|
19
|
+
|
20
|
+
line2 = "test >>"
|
21
|
+
assert (!test_paragraph.quoted?(line2))
|
22
|
+
|
23
|
+
line3 = "> > test"
|
24
|
+
assert (test_paragraph.quoted?(line3))
|
25
|
+
|
26
|
+
line4 = ">> > test"
|
27
|
+
assert (test_paragraph.quoted?(line4))
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_find_quote_prefix
|
32
|
+
|
33
|
+
# 1. Basic test
|
34
|
+
|
35
|
+
test_paragraph1 = Paragraph.new()
|
36
|
+
|
37
|
+
test_paragraph1 << ">> First line"
|
38
|
+
test_paragraph1 << ">> Second line"
|
39
|
+
test_paragraph1 << "> Third line"
|
40
|
+
|
41
|
+
test_paragraph1.find_quote_prefix()
|
42
|
+
|
43
|
+
assert_equal(">", test_paragraph1.quote_prefix)
|
44
|
+
|
45
|
+
# 2. A longer test
|
46
|
+
|
47
|
+
test_paragraph3 = Paragraph.new()
|
48
|
+
|
49
|
+
test_paragraph3 << ">> First line"
|
50
|
+
test_paragraph3 << ">> Second line"
|
51
|
+
test_paragraph3 << "> Third line"
|
52
|
+
test_paragraph3 << "> Fourth line"
|
53
|
+
test_paragraph3 << "Fifth line"
|
54
|
+
test_paragraph3 << "Sixth line"
|
55
|
+
test_paragraph3 << ">> Seventh line"
|
56
|
+
test_paragraph3 << ">> Eight line"
|
57
|
+
test_paragraph3 << "> Ninth line"
|
58
|
+
test_paragraph3 << "> Tenth line"
|
59
|
+
|
60
|
+
test_paragraph3.find_quote_prefix()
|
61
|
+
|
62
|
+
assert_equal("", test_paragraph3.quote_prefix)
|
63
|
+
|
64
|
+
# a real-life test
|
65
|
+
|
66
|
+
test_paragraph4 = Paragraph.new()
|
67
|
+
|
68
|
+
test_paragraph4 << "> Lorem ipsum dolor sit amet, consectetuer adipiscing elit.\n"
|
69
|
+
test_paragraph4 << "> \n"
|
70
|
+
test_paragraph4 << "> Nam quis lectus. Aenean volutpat urna."
|
71
|
+
|
72
|
+
test_paragraph4.find_quote_prefix()
|
73
|
+
assert_equal(">", test_paragraph4.quote_prefix)
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_split_quoted
|
77
|
+
|
78
|
+
test_paragraph1 = Paragraph.new()
|
79
|
+
|
80
|
+
test_paragraph1 << ">> First line"
|
81
|
+
test_paragraph1 << ">> Second line"
|
82
|
+
test_paragraph1 << "> Third line"
|
83
|
+
test_paragraph1 << "Fourth line"
|
84
|
+
|
85
|
+
test_paragraph1.find_quote_prefix()
|
86
|
+
|
87
|
+
blocks = test_paragraph1.split_to_quoted()
|
88
|
+
assert_equal(2, blocks.length)
|
89
|
+
assert_equal(">> First line", blocks[0][0])
|
90
|
+
assert_equal(">> Second line", blocks[0][1])
|
91
|
+
assert_equal("> Third line", blocks[0][2])
|
92
|
+
assert_equal("Fourth line", blocks[1][0])
|
93
|
+
|
94
|
+
test_paragraph2 = Paragraph.new()
|
95
|
+
|
96
|
+
test_paragraph2 << ">> First line"
|
97
|
+
test_paragraph2 << ">> Second line"
|
98
|
+
test_paragraph2 << "> Third line"
|
99
|
+
test_paragraph2.find_quote_prefix()
|
100
|
+
|
101
|
+
blocks = test_paragraph2.split_to_quoted()
|
102
|
+
assert_equal(2, blocks.length)
|
103
|
+
assert_equal(">> First line", blocks[0][0])
|
104
|
+
assert_equal(">> Second line", blocks[0][1])
|
105
|
+
assert_equal("> Third line", blocks[1][0])
|
106
|
+
|
107
|
+
test_paragraph3 = Paragraph.new()
|
108
|
+
|
109
|
+
test_paragraph3 << ">> First line"
|
110
|
+
test_paragraph3 << ">> Second line"
|
111
|
+
test_paragraph3 << "> Third line"
|
112
|
+
test_paragraph3 << "> Fourth line"
|
113
|
+
test_paragraph3 << "Fifth line"
|
114
|
+
test_paragraph3 << "Sixth line"
|
115
|
+
test_paragraph3 << ">> Seventh line"
|
116
|
+
test_paragraph3 << ">> Eight line"
|
117
|
+
test_paragraph3 << "> Ninth line"
|
118
|
+
test_paragraph3 << "> Tenth line"
|
119
|
+
|
120
|
+
test_paragraph3.find_quote_prefix()
|
121
|
+
|
122
|
+
blocks = test_paragraph3.split_to_quoted()
|
123
|
+
|
124
|
+
assert_equal(3, blocks.length)
|
125
|
+
assert_equal(">> First line", blocks[0][0])
|
126
|
+
assert_equal(">> Second line", blocks[0][1])
|
127
|
+
assert_equal("> Third line", blocks[0][2])
|
128
|
+
assert_equal("> Fourth line", blocks[0][3])
|
129
|
+
assert_equal("Fifth line", blocks[1][0])
|
130
|
+
assert_equal("Sixth line", blocks[1][1])
|
131
|
+
assert_equal(">> Seventh line", blocks[2][0])
|
132
|
+
assert_equal(">> Eight line", blocks[2][1])
|
133
|
+
assert_equal("> Ninth line", blocks[2][2])
|
134
|
+
assert_equal("> Tenth line", blocks[2][3])
|
135
|
+
|
136
|
+
# spaces within quotes
|
137
|
+
|
138
|
+
test_paragraph4 = Paragraph.new()
|
139
|
+
|
140
|
+
test_paragraph4 << "> > First line"
|
141
|
+
test_paragraph4 << "> > Second line"
|
142
|
+
test_paragraph4 << "> Third line"
|
143
|
+
test_paragraph4.find_quote_prefix()
|
144
|
+
|
145
|
+
blocks = test_paragraph4.split_to_quoted()
|
146
|
+
assert_equal(2, blocks.length)
|
147
|
+
assert_equal("> > First line", blocks[0][0])
|
148
|
+
assert_equal("> > Second line", blocks[0][1])
|
149
|
+
assert_equal("> Third line", blocks[1][0])
|
150
|
+
|
151
|
+
# empty quoted lines are not removed, but are their own
|
152
|
+
# paragraphs
|
153
|
+
|
154
|
+
test_paragraph5 = Paragraph.new()
|
155
|
+
|
156
|
+
test_paragraph5 << "> > First line"
|
157
|
+
test_paragraph5 << "> > Second line"
|
158
|
+
test_paragraph5 << "> Third line after this!"
|
159
|
+
test_paragraph5 << ">"
|
160
|
+
test_paragraph5.find_quote_prefix()
|
161
|
+
|
162
|
+
blocks = test_paragraph5.split_to_quoted()
|
163
|
+
assert_equal(3, blocks.length)
|
164
|
+
assert_equal("> > First line", blocks[0][0])
|
165
|
+
assert_equal("> > Second line", blocks[0][1])
|
166
|
+
assert_equal("> Third line after this!", blocks[1][0])
|
167
|
+
assert_nil(blocks[1][1])
|
168
|
+
assert_equal(">", blocks[2][0])
|
169
|
+
|
170
|
+
# In this test the empty line _should not_ be its own paragraph,
|
171
|
+
# since the prefix is ">" and the line does not appear to be
|
172
|
+
# empty. This is expected behavior.
|
173
|
+
|
174
|
+
test_paragraph6 = Paragraph.new()
|
175
|
+
|
176
|
+
test_paragraph6 << "> > First line"
|
177
|
+
test_paragraph6 << "> > Second line"
|
178
|
+
test_paragraph6 << "> >"
|
179
|
+
test_paragraph6 << "> Third line"
|
180
|
+
test_paragraph6.find_quote_prefix()
|
181
|
+
|
182
|
+
blocks = test_paragraph6.split_to_quoted()
|
183
|
+
assert_equal(2, blocks.length)
|
184
|
+
assert_equal("> > First line", blocks[0][0])
|
185
|
+
assert_equal("> > Second line", blocks[0][1])
|
186
|
+
assert_equal("> >", blocks[0][2])
|
187
|
+
assert_equal("> Third line", blocks[1][0])
|
188
|
+
|
189
|
+
# See that the empty line is included in the results
|
190
|
+
|
191
|
+
test_paragraph7 = Paragraph.new()
|
192
|
+
|
193
|
+
test_paragraph7 << "> text text"
|
194
|
+
test_paragraph7 << ">"
|
195
|
+
test_paragraph7 << "> text"
|
196
|
+
test_paragraph7.find_quote_prefix()
|
197
|
+
|
198
|
+
blocks = test_paragraph7.split_to_quoted()
|
199
|
+
assert_equal(3, blocks.length)
|
200
|
+
assert_equal("> text text", blocks[0][0])
|
201
|
+
assert_equal(">", blocks[1][0])
|
202
|
+
assert_equal("> text", blocks[2][0])
|
203
|
+
|
204
|
+
test_paragraph8 = Paragraph.new()
|
205
|
+
|
206
|
+
test_paragraph8 << ">"
|
207
|
+
test_paragraph8 << "> text text"
|
208
|
+
test_paragraph8 << "> text"
|
209
|
+
test_paragraph8.find_quote_prefix()
|
210
|
+
|
211
|
+
blocks = test_paragraph8.split_to_quoted()
|
212
|
+
assert_equal(2, blocks.length)
|
213
|
+
assert_equal(">", blocks[0][0])
|
214
|
+
assert_equal("> text text", blocks[1][0])
|
215
|
+
assert_equal("> text", blocks[1][1])
|
216
|
+
|
217
|
+
end
|
218
|
+
|
219
|
+
def test_get_paragraphs
|
220
|
+
|
221
|
+
# basic test for quoted text
|
222
|
+
|
223
|
+
test_paragraph1 = Paragraph.new()
|
224
|
+
test_paragraph1 << ">> First line"
|
225
|
+
test_paragraph1 << ">> Second line"
|
226
|
+
test_paragraph1 << "> Third line"
|
227
|
+
test_paragraph1 << "Fourth line"
|
228
|
+
|
229
|
+
paragraphs = test_paragraph1.get_paragraphs()
|
230
|
+
|
231
|
+
assert_equal(3, paragraphs.length)
|
232
|
+
|
233
|
+
assert_equal(">> First line", paragraphs[0][0])
|
234
|
+
assert_equal(">> Second line", paragraphs[0][1])
|
235
|
+
assert_equal("> Third line", paragraphs[1][0])
|
236
|
+
assert_equal("Fourth line", paragraphs[2][0])
|
237
|
+
|
238
|
+
# longer test for quoted text
|
239
|
+
|
240
|
+
test_paragraph2 = Paragraph.new()
|
241
|
+
|
242
|
+
test_paragraph2 << ">> First line"
|
243
|
+
test_paragraph2 << ">> Second line"
|
244
|
+
test_paragraph2 << "> Third line"
|
245
|
+
test_paragraph2 << "> Fourth line"
|
246
|
+
test_paragraph2 << "Fifth line"
|
247
|
+
test_paragraph2 << "Sixth line"
|
248
|
+
test_paragraph2 << ">> Seventh line"
|
249
|
+
test_paragraph2 << ">> Eight line"
|
250
|
+
test_paragraph2 << "> Ninth line"
|
251
|
+
test_paragraph2 << "> Tenth line"
|
252
|
+
|
253
|
+
paragraphs = test_paragraph2.get_paragraphs()
|
254
|
+
|
255
|
+
assert_equal(5, paragraphs.length)
|
256
|
+
|
257
|
+
assert_equal(">> First line", paragraphs[0][0])
|
258
|
+
assert_equal(">> Second line", paragraphs[0][1])
|
259
|
+
assert_equal("> Third line", paragraphs[1][0])
|
260
|
+
assert_equal("> Fourth line", paragraphs[1][1])
|
261
|
+
assert_equal("Fifth line", paragraphs[2][0])
|
262
|
+
assert_equal("Sixth line", paragraphs[2][1])
|
263
|
+
assert_equal(">> Seventh line", paragraphs[3][0])
|
264
|
+
assert_equal(">> Eight line", paragraphs[3][1])
|
265
|
+
assert_equal("> Ninth line", paragraphs[4][0])
|
266
|
+
assert_equal("> Tenth line", paragraphs[4][1])
|
267
|
+
|
268
|
+
# test with some simulated data that looks a bit like real email
|
269
|
+
|
270
|
+
lines3 = [
|
271
|
+
"On 12/1/07, Lorem Ipsum wrote:\n",
|
272
|
+
"\n",
|
273
|
+
"> Lorem ipsum dolor sit amet, consectetuer adipiscing elit.\n",
|
274
|
+
"> Praesent viverra magna sed urna.\n",
|
275
|
+
"> \n",
|
276
|
+
"> On 11/29/07, The previous Lorem Ipsum wrote:\n",
|
277
|
+
"> > Vivamus imperdiet purus eget velit. Pellentesque vehicula\n",
|
278
|
+
"> > gravida justo. In facilisis. Curabitur at tortor eu ante\n",
|
279
|
+
"> > mattis pulvinar. Cras lobortis, augue malesuada accumsan\n",
|
280
|
+
"> > vehicula, erat tortor ultricies nulla, ac interdum odio tortor.\n"
|
281
|
+
]
|
282
|
+
|
283
|
+
test_paragraph3 = Paragraph.new()
|
284
|
+
lines3.each do |line|
|
285
|
+
test_paragraph3 << line
|
286
|
+
end
|
287
|
+
|
288
|
+
paragraphs = test_paragraph3.get_paragraphs()
|
289
|
+
|
290
|
+
assert_equal(6, paragraphs.length)
|
291
|
+
|
292
|
+
assert_equal("On 12/1/07, Lorem Ipsum wrote:\n", paragraphs[0][0])
|
293
|
+
assert_equal("\n", paragraphs[1][0])
|
294
|
+
assert_equal("> Lorem ipsum dolor sit amet, consectetuer adipiscing elit.\n", paragraphs[2][0])
|
295
|
+
assert_equal("> Praesent viverra magna sed urna.\n", paragraphs[2][1])
|
296
|
+
assert_equal("> \n", paragraphs[3][0])
|
297
|
+
assert_equal("> On 11/29/07, The previous Lorem Ipsum wrote:\n", paragraphs[4][0])
|
298
|
+
assert_equal("> > Vivamus imperdiet purus eget velit. Pellentesque vehicula\n", paragraphs[5][0])
|
299
|
+
assert_equal("> > gravida justo. In facilisis. Curabitur at tortor eu ante\n", paragraphs[5][1])
|
300
|
+
assert_equal("> > mattis pulvinar. Cras lobortis, augue malesuada accumsan\n", paragraphs[5][2])
|
301
|
+
assert_equal("> > vehicula, erat tortor ultricies nulla, ac interdum odio tortor.\n", paragraphs[5][3])
|
302
|
+
|
303
|
+
end
|
304
|
+
|
305
|
+
end
|
data/test/rbpar_test.rb
ADDED
metadata
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.4
|
3
|
+
specification_version: 1
|
4
|
+
name: rbpar
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.1.0
|
7
|
+
date: 2007-12-04 00:00:00 +02:00
|
8
|
+
summary: A program for managing pargraph formatting
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: ismo@iki.fi
|
12
|
+
homepage: ""
|
13
|
+
rubyforge_project:
|
14
|
+
description:
|
15
|
+
autorequire: rbpar
|
16
|
+
default_executable: rbpar.rb
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- Ismo Puustinen
|
31
|
+
files:
|
32
|
+
- bin/rbpar.rb
|
33
|
+
- test/rbpar_engine_test.rb
|
34
|
+
- test/rbpar_main_test.rb
|
35
|
+
- test/rbpar_paragraph_test.rb
|
36
|
+
- test/rbpar_test.rb
|
37
|
+
- lib/rbpar_engine.rb
|
38
|
+
- lib/rbpar_main.rb
|
39
|
+
- lib/rbpar_paragraph.rb
|
40
|
+
- README
|
41
|
+
test_files:
|
42
|
+
- test/rbpar_test.rb
|
43
|
+
rdoc_options: []
|
44
|
+
|
45
|
+
extra_rdoc_files:
|
46
|
+
- README
|
47
|
+
executables:
|
48
|
+
- rbpar.rb
|
49
|
+
extensions: []
|
50
|
+
|
51
|
+
requirements: []
|
52
|
+
|
53
|
+
dependencies: []
|
54
|
+
|