poefy 1.1.1 → 2.0.1

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.
@@ -1,621 +1,621 @@
1
- #!/usr/bin/env ruby
2
- # Encoding: UTF-8
3
-
4
- ################################################################################
5
-
6
- describe Poefy::Poem, "-- Unit tests" do
7
-
8
- describe "#transform_input_regex" do
9
-
10
- # Singleton which includes the method.
11
- # Make the private methods public.
12
- let(:obj) do
13
- class Sing
14
- include Poefy::PoeticForms
15
- include Poefy::StringManipulation
16
- public *private_instance_methods
17
- end.new
18
- end
19
-
20
- describe "using rhyme string 'aabba'" do
21
- normal_input = [
22
- [/^T/,
23
- {
24
- 1=>/^T/,
25
- 2=>/^T/,
26
- 3=>/^T/,
27
- 4=>/^T/,
28
- 5=>/^T/
29
- }],
30
- [/^T/i,
31
- {
32
- 1=>/^T/i,
33
- 2=>/^T/i,
34
- 3=>/^T/i,
35
- 4=>/^T/i,
36
- 5=>/^T/i
37
- }],
38
- ['rgegerg',
39
- {
40
- 1=>/rgegerg/,
41
- 2=>/rgegerg/,
42
- 3=>/rgegerg/,
43
- 4=>/rgegerg/,
44
- 5=>/rgegerg/
45
- }],
46
- ['^[A-Z]',
47
- {
48
- 1=>/^[A-Z]/,
49
- 2=>/^[A-Z]/,
50
- 3=>/^[A-Z]/,
51
- 4=>/^[A-Z]/,
52
- 5=>/^[A-Z]/
53
- }],
54
- ['[A-Z]',
55
- {
56
- 1=>/[A-Z]/,
57
- 2=>/[A-Z]/,
58
- 3=>/[A-Z]/,
59
- 4=>/[A-Z]/,
60
- 5=>/[A-Z]/
61
- }],
62
- ['^[^e]*$',
63
- {
64
- 1=>/^[^e]*$/,
65
- 2=>/^[^e]*$/,
66
- 3=>/^[^e]*$/,
67
- 4=>/^[^e]*$/,
68
- 5=>/^[^e]*$/
69
- }],
70
- [[/a/,/b/,/c/,/d/,/e/],
71
- {
72
- 1=>/a/,
73
- 2=>/b/,
74
- 3=>/c/,
75
- 4=>/d/,
76
- 5=>/e/
77
- }],
78
- [['a','b','c','d','e'],
79
- {
80
- 1=>/a/,
81
- 2=>/b/,
82
- 3=>/c/,
83
- 4=>/d/,
84
- 5=>/e/
85
- }],
86
- [['a',/b/,'c',/d/,/e/],
87
- {
88
- 1=>/a/,
89
- 2=>/b/,
90
- 3=>/c/,
91
- 4=>/d/,
92
- 5=>/e/
93
- }],
94
- [[/a/,/b/,/c/,/d/,/e/],
95
- {
96
- 1=>/a/,
97
- 2=>/b/,
98
- 3=>/c/,
99
- 4=>/d/,
100
- 5=>/e/
101
- }],
102
- [{1=>'a', 2=>'b', 3=>'c', 4=>'d', 5=>'e'},
103
- {
104
- 1=>/a/,
105
- 2=>/b/,
106
- 3=>/c/,
107
- 4=>/d/,
108
- 5=>/e/
109
- }],
110
- [{1=>/a/, 2=>/b/, 3=>/c/, 4=>/d/, 5=>/e/},
111
- {
112
- 1=>/a/,
113
- 2=>/b/,
114
- 3=>/c/,
115
- 4=>/d/,
116
- 5=>/e/
117
- }],
118
- [{1=>/a/, 2=>'b', 3=>'c', 4=>/d/, 5=>/e/},
119
- {
120
- 1=>/a/,
121
- 2=>/b/,
122
- 3=>/c/,
123
- 4=>/d/,
124
- 5=>/e/
125
- }],
126
- [{0=>/o/, 3=>'c', 4=>/d/},
127
- {
128
- 1=>/o/,
129
- 2=>/o/,
130
- 3=>/c/,
131
- 4=>/d/,
132
- 5=>/o/
133
- }],
134
- ["['(?=^[A-Z])(?=^[^eE]*$)', '^[^eE]*$', '^[^eE]*$', '^[^eE]*$', '^[^eE]*$']",
135
- {
136
- 1=>/['(?=^[A-Z])(?=^[^eE]*$)', '^[^eE]*$', '^[^eE]*$', '^[^eE]*$', '^[^eE]*$']/,
137
- 2=>/['(?=^[A-Z])(?=^[^eE]*$)', '^[^eE]*$', '^[^eE]*$', '^[^eE]*$', '^[^eE]*$']/,
138
- 3=>/['(?=^[A-Z])(?=^[^eE]*$)', '^[^eE]*$', '^[^eE]*$', '^[^eE]*$', '^[^eE]*$']/,
139
- 4=>/['(?=^[A-Z])(?=^[^eE]*$)', '^[^eE]*$', '^[^eE]*$', '^[^eE]*$', '^[^eE]*$']/,
140
- 5=>/['(?=^[A-Z])(?=^[^eE]*$)', '^[^eE]*$', '^[^eE]*$', '^[^eE]*$', '^[^eE]*$']/
141
- }],
142
- [['(?=^[A-Z])(?=^[^eE]*$)', '^[^eE]*$', '^[^eE]*$', '^[^eE]*$', '^[^eE]*$'],
143
- {
144
- 1=>/(?=^[A-Z])(?=^[^eE]*$)/,
145
- 2=>/^[^eE]*$/,
146
- 3=>/^[^eE]*$/,
147
- 4=>/^[^eE]*$/,
148
- 5=>/^[^eE]*$/
149
- }],
150
- ["{1: '(?=^[A-Z])(?=^[^eE]*$)', 2: '^[^eE]*$', 3: '^[^eE]*$', 4: '^[^eE]*$', 5: '^[^eE]*$'}",
151
- {
152
- 1=>/(?=^[A-Z])(?=^[^eE]*$)/,
153
- 2=>/^[^eE]*$/,
154
- 3=>/^[^eE]*$/,
155
- 4=>/^[^eE]*$/,
156
- 5=>/^[^eE]*$/
157
- }],
158
- [{1=>'(?=^[A-Z])(?=^[^eE]*$)', 2=>'^[^eE]*$', 3=>'^[^eE]*$', 4=>'^[^eE]*$', 5=>'^[^eE]*$'},
159
- {
160
- 1=>/(?=^[A-Z])(?=^[^eE]*$)/,
161
- 2=>/^[^eE]*$/,
162
- 3=>/^[^eE]*$/,
163
- 4=>/^[^eE]*$/,
164
- 5=>/^[^eE]*$/
165
- }],
166
- [{1=>/(?=^[A-Z])(?=^[^eE]*$)/, 2=>'^[^eE]*$', 3=>'^[^eE]*$', 4=>/^[^eE]*$/, 5=>'^[^eE]*$'},
167
- {
168
- 1=>/(?=^[A-Z])(?=^[^eE]*$)/,
169
- 2=>/^[^eE]*$/,
170
- 3=>/^[^eE]*$/,
171
- 4=>/^[^eE]*$/,
172
- 5=>/^[^eE]*$/
173
- }],
174
- ["{0: '^[^eE]*$', 1: '(?=^[A-Z])(?=^[^eE]*$)'}",
175
- {
176
- 1=>/(?=^[A-Z])(?=^[^eE]*$)/,
177
- 2=>/^[^eE]*$/,
178
- 3=>/^[^eE]*$/,
179
- 4=>/^[^eE]*$/,
180
- 5=>/^[^eE]*$/
181
- }],
182
- [{0=>'^[^eE]*$', 1=>'(?=^[A-Z])(?=^[^eE]*$)'},
183
- {
184
- 1=>/(?=^[A-Z])(?=^[^eE]*$)/,
185
- 2=>/^[^eE]*$/,
186
- 3=>/^[^eE]*$/,
187
- 4=>/^[^eE]*$/,
188
- 5=>/^[^eE]*$/
189
- }],
190
- ["{1: '(?=^[A-Z])(?=^[^eE]*$)', 2: '^[^eE]*$', 3: '^[^eE]*$', 5: '^[^eE]*$'}",
191
- {
192
- 1=>/(?=^[A-Z])(?=^[^eE]*$)/,
193
- 2=>/^[^eE]*$/,
194
- 3=>/^[^eE]*$/,
195
- 4=>//,
196
- 5=>/^[^eE]*$/
197
- }],
198
- ["{1: '(?=^[A-Z])(?=^[^eE]*$)', 4: '^[^eE]*$'}",
199
- {
200
- 1=>/(?=^[A-Z])(?=^[^eE]*$)/,
201
- 2=>//,
202
- 3=>//,
203
- 4=>/^[^eE]*$/,
204
- 5=>//
205
- }],
206
- ["{1: '(?=^[A-Z])(?=^[^eE]*$)', 2: '^[^eE]*$', 3: '^[^eE]*$', -1: '^[^eE]*$', -2: '^[^eE]*$'}",
207
- {
208
- 1=>/(?=^[A-Z])(?=^[^eE]*$)/,
209
- 2=>/^[^eE]*$/,
210
- 3=>/^[^eE]*$/,
211
- 4=>/^[^eE]*$/,
212
- 5=>/^[^eE]*$/
213
- }],
214
- ['{7: \'^\S+$\'}',
215
- {
216
- 1=>//,
217
- 2=>//,
218
- 3=>//,
219
- 4=>//,
220
- 5=>//,
221
- 7=>/^\S+$/
222
- }],
223
- [{'3m1'=>/a/, 2=>'b', 0=>/c/},
224
- {
225
- 1=>/a/,
226
- 2=>/b/,
227
- 3=>/c/,
228
- 4=>/a/,
229
- 5=>/c/
230
- }],
231
- ]
232
- weird_input = [
233
- ['x',
234
- { 1=>/x/,
235
- 2=>/x/,
236
- 3=>/x/,
237
- 4=>/x/,
238
- 5=>/x/
239
- }],
240
- ['xxxx',
241
- { 1=>/xxxx/,
242
- 2=>/xxxx/,
243
- 3=>/xxxx/,
244
- 4=>/xxxx/,
245
- 5=>/xxxx/
246
- }],
247
- ['xxxx40',
248
- { 1=>/xxxx40/,
249
- 2=>/xxxx40/,
250
- 3=>/xxxx40/,
251
- 4=>/xxxx40/,
252
- 5=>/xxxx40/
253
- }],
254
- ['xx40xx',
255
- { 1=>/xx40xx/,
256
- 2=>/xx40xx/,
257
- 3=>/xx40xx/,
258
- 4=>/xx40xx/,
259
- 5=>/xx40xx/
260
- }],
261
- ['<40xxxx></40xxxx>',
262
- { 1=>/<40xxxx><\/40xxxx>/,
263
- 2=>/<40xxxx><\/40xxxx>/,
264
- 3=>/<40xxxx><\/40xxxx>/,
265
- 4=>/<40xxxx><\/40xxxx>/,
266
- 5=>/<40xxxx><\/40xxxx>/
267
- }],
268
- ['{xxxxx: xxxxx}',
269
- {1=>//,2=>//,3=>//,4=>//,5=>//}],
270
- ['{2: f}',
271
- {1=>//,2=>/f/,3=>//,4=>//,5=>//}],
272
- [:foo,
273
- {1=>/foo/,2=>/foo/,3=>/foo/,4=>/foo/,5=>/foo/}],
274
- [{0=>:foo, 4=>:bar},
275
- {1=>/foo/,2=>/foo/,3=>/foo/,4=>/bar/,5=>/foo/}],
276
- [123,
277
- {1=>/123/,2=>/123/,3=>/123/,4=>/123/,5=>/123/}],
278
- [Object,
279
- {1=>/Object/,2=>/Object/,3=>/Object/,4=>/Object/,5=>/Object/}],
280
- [GC,
281
- {1=>/GC/,2=>/GC/,3=>/GC/,4=>/GC/,5=>/GC/}],
282
- [TypeError.new('foo'),
283
- {1=>/foo/,2=>/foo/,3=>/foo/,4=>/foo/,5=>/foo/}],
284
- ['{xxxxx}',
285
- {1=>//,2=>//,3=>//,4=>//,5=>//}],
286
- ['{{xxxxx}}',
287
- {1=>//,2=>//,3=>//,4=>//,5=>//}],
288
- ['{3: }',
289
- {1=>//,2=>//,3=>//,4=>//,5=>//}],
290
- ['{40}',
291
- {1=>//,2=>//,3=>//,4=>//,40=>//,5=>//}],
292
- ['{[40]}',
293
- {1=>//,2=>//,3=>//,4=>//,5=>//}],
294
- ['{{40}}',
295
- {1=>//,2=>//,3=>//,4=>//,5=>//}],
296
- ['{{}}',
297
- {1=>//,2=>//,3=>//,4=>//,5=>//}],
298
- ['{1: 12',
299
- {1=>/{1: 12/,2=>/{1: 12/,3=>/{1: 12/,4=>/{1: 12/,5=>/{1: 12/}],
300
- ]
301
- error_input = [
302
- "{1: /(?=^[A-Z])(?=^[^eE]*$)/, 4: /^[^eE]*$/}",
303
- '{3: 4: 5}',
304
- '{xxxxx: 8000, 0: xxxxx: 8000}',
305
- ]
306
- describe "normal input" do
307
- normal_input.each do |pair|
308
- it "regex: #{pair.first}" do
309
- rhyme = obj.tokenise_rhyme('aabba')
310
- out = obj.transform_input_regex(pair.first, 'aabba')
311
- again = obj.transform_input_regex(out, 'aabba')
312
- expect(out).to eq pair.last
313
- expect(again).to eq out
314
- expect(again).to eq pair.last
315
- end
316
- end
317
- end
318
- describe "weird (but technically fine) input" do
319
- weird_input.each do |pair|
320
- it "regex: #{pair.first}" do
321
- rhyme = obj.tokenise_rhyme('aabba')
322
- out = obj.transform_input_regex(pair.first, 'aabba')
323
- again = obj.transform_input_regex(out, 'aabba')
324
- expect(out).to eq pair.last
325
- expect(again).to eq out
326
- expect(again).to eq pair.last
327
- end
328
- end
329
- end
330
- describe "error input" do
331
- error_input.each do |i|
332
- it "regex: #{i}" do
333
- rhyme = obj.tokenise_rhyme('aabba')
334
- expect {
335
- obj.transform_input_regex(i, 'aabba')
336
- }.to raise_error(Poefy::RegexError)
337
- end
338
- end
339
- end
340
- end
341
- end
342
-
343
- ##############################################################################
344
-
345
- describe "#transform_input_syllable" do
346
-
347
- # Singleton which includes the method.
348
- # Make the private methods public.
349
- let(:obj) do
350
- class Sing
351
- include Poefy::PoeticForms
352
- include Poefy::StringManipulation
353
- public *private_instance_methods
354
- end.new
355
- end
356
- describe "using rhyme string 'aabba'" do
357
- normal_input = [
358
- [0,
359
- {1=>0,2=>0,3=>0,4=>0,5=>0}],
360
- [10,
361
- {1=>10,2=>10,3=>10,4=>10,5=>10}],
362
- ['0',
363
- {1=>0,2=>0,3=>0,4=>0,5=>0}],
364
- ['10',
365
- {1=>10,2=>10,3=>10,4=>10,5=>10}],
366
- ['99',
367
- {1=>99,2=>99,3=>99,4=>99,5=>99}],
368
- ['8,9,10',
369
- {1=>[8,9,10],2=>[8,9,10],3=>[8,9,10],4=>[8,9,10],5=>[8,9,10]}],
370
- ['6,7,8,9',
371
- {1=>[6,7,8,9],2=>[6,7,8,9],3=>[6,7,8,9],4=>[6,7,8,9],5=>[6,7,8,9]}],
372
- ['[10]',
373
- {1=>10,2=>0,3=>0,4=>0,5=>0}],
374
- ['[8,8,5,5,8]',
375
- {1=>8,2=>8,3=>5,4=>5,5=>8}],
376
- ['[[8,9],[8,9],[4,5,6],[4,5,6],[8,9]]',
377
- {1=>[8,9],2=>[8,9],3=>[4,5,6],4=>[4,5,6],5=>[8,9]}],
378
- ['{1:8,2:8,3:5,4:5,5:8}',
379
- {1=>8,2=>8,3=>5,4=>5,5=>8}],
380
- ['{1:8,2:8,3:5,5:8}',
381
- {1=>8,2=>8,3=>5,4=>0,5=>8}],
382
- ['{0:99,1:8,2:8,3:5,5:8}',
383
- {1=>8,2=>8,3=>5,4=>99,5=>8}],
384
- ['{1:[8,9],2:[8,9],3:[4,5,6],4:[4,5,6],5:[8,9]}',
385
- {1=>[8,9],2=>[8,9],3=>[4,5,6],4=>[4,5,6],5=>[8,9]}],
386
- ['{1:[8,9],2:[8,9],3:[4,5,6],5:[8,9]}',
387
- {1=>[8,9],2=>[8,9],3=>[4,5,6],4=>0,5=>[8,9]}],
388
- ['{0:99,1:[8,9],2:[8,9],3:[4,5,6],5:[8,9]}',
389
- {1=>[8,9],2=>[8,9],3=>[4,5,6],4=>99,5=>[8,9]}],
390
- ['{0:[8,9],3:[4,5,6],4:[4,5,6]}',
391
- {1=>[8,9],2=>[8,9],3=>[4,5,6],4=>[4,5,6],5=>[8,9]}],
392
- ['{1:8,5:8}',
393
- {1=>8,2=>0,3=>0,4=>0,5=>8}],
394
- ['{1:8,2:8,3:5,-2:5,-1:8}',
395
- {1=>8,2=>8,3=>5,4=>5,5=>8}],
396
- ['{o:1,e:2}',
397
- {1=>1,2=>2,3=>1,4=>2,5=>1}],
398
- ['{o:1,0:9}',
399
- {1=>1,2=>9,3=>1,4=>9,5=>1}],
400
- ['{o:1,e:2,0:9}',
401
- {1=>1,2=>2,3=>1,4=>2,5=>1}],
402
- ['{o:8,e:6,-2:6,-1:4}',
403
- {1=>8,2=>6,3=>8,4=>6,5=>4}],
404
- ['{o:8,e:6,-2:6,-1:4,0:9}',
405
- {1=>8,2=>6,3=>8,4=>6,5=>4}],
406
- ['8-10',
407
- {1=>[8,9,10],2=>[8,9,10],3=>[8,9,10],4=>[8,9,10],5=>[8,9,10]}],
408
- ['6-9',
409
- {1=>[6,7,8,9],2=>[6,7,8,9],3=>[6,7,8,9],4=>[6,7,8,9],5=>[6,7,8,9]}],
410
- ['4-9',
411
- { 1=>[4,5,6,7,8,9],
412
- 2=>[4,5,6,7,8,9],
413
- 3=>[4,5,6,7,8,9],
414
- 4=>[4,5,6,7,8,9],
415
- 5=>[4,5,6,7,8,9]}],
416
- ['4,6,8-10,12',
417
- { 1=>[4,6,8,9,10,12],
418
- 2=>[4,6,8,9,10,12],
419
- 3=>[4,6,8,9,10,12],
420
- 4=>[4,6,8,9,10,12],
421
- 5=>[4,6,8,9,10,12]}],
422
- ['[4,6,8-10,12]',
423
- {1=>4,2=>6,3=>[8,9,10],4=>12,5=>0}],
424
- ['{e:"4,6,8-10,12"}',
425
- {1=>0,2=>[4,6,8,9,10,12],3=>0,4=>[4,6,8,9,10,12],5=>0}],
426
- ['{0:6,-1:6-10}',
427
- {1=>6,2=>6,3=>6,4=>6,5=>[6,7,8,9,10]}],
428
- ['{0:4-6,-1:6-10}',
429
- {1=>[4,5,6],2=>[4,5,6],3=>[4,5,6],4=>[4,5,6],5=>[6,7,8,9,10]}],
430
- ['{e:4-6,-1:6-10}',
431
- {1=>0,2=>[4,5,6],3=>0,4=>[4,5,6],5=>[6,7,8,9,10]}],
432
- ['[[8,9],[8,9],[4,5,6],[4,5,6],[8,9]]',
433
- {1=>[8,9],2=>[8,9],3=>[4,5,6],4=>[4,5,6],5=>[8,9]}],
434
- ['[[8-9],[8-9],[4-6],[4-6],[8-9]]',
435
- {1=>[8,9],2=>[8,9],3=>[4,5,6],4=>[4,5,6],5=>[8,9]}],
436
- ['[[8,9],[8,9],4-6,4-6,[8,9]]',
437
- {1=>[8,9],2=>[8,9],3=>[4,5,6],4=>[4,5,6],5=>[8,9]}],
438
- ['[8-9,8-9,4-6,4-6,8-9]',
439
- {1=>[8,9],2=>[8,9],3=>[4,5,6],4=>[4,5,6],5=>[8,9]}],
440
- ['{0:11,3m0:30}',
441
- {1=>11,2=>11,3=>30,4=>11,5=>11}],
442
- ['{0:11,3m0:30,3m1:31}',
443
- {1=>31,2=>11,3=>30,4=>31,5=>11}],
444
- [{0=>11,'3m0'=>30,'3m1'=>31},
445
- {1=>31,2=>11,3=>30,4=>31,5=>11}],
446
- [{0=>11,'3m0'=>[1,2,3,4],'3m1'=>31},
447
- {1=>31,2=>11,3=>[1,2,3,4],4=>31,5=>11}]
448
- ]
449
- weird_input = [
450
- ['40xxxx',
451
- {1=>40,2=>40,3=>40,4=>40,5=>40}],
452
- ['{3: 4 5}',
453
- {1=>0,2=>0,3=>4,4=>0,5=>0}],
454
- ['{}',
455
- {1=>0,2=>0,3=>0,4=>0,5=>0}],
456
- ['{xxxxx: 8}',
457
- {1=>0,2=>0,3=>0,4=>0,5=>0}],
458
- ['{xxxxx: 8000}',
459
- {1=>0,2=>0,3=>0,4=>0,5=>0}],
460
- ['{2m12: 9}',
461
- {1=>0,2=>0,3=>0,4=>0,5=>0}],
462
- ['{1m0: 9}',
463
- {1=>9,2=>9,3=>9,4=>9,5=>9}],
464
- ['{1m1: 9}',
465
- {1=>0,2=>0,3=>0,4=>0,5=>0}],
466
- ['{-1m0: 9}',
467
- {1=>9,2=>9,3=>9,4=>9,5=>9}],
468
- ['{-1m1: 9}',
469
- {1=>0,2=>0,3=>0,4=>0,5=>0}],
470
- ['{-1m1: -9}',
471
- {1=>0,2=>0,3=>0,4=>0,5=>0}],
472
- ['{10: 2}',
473
- {1=>0,2=>0,3=>0,4=>0,5=>0,10=>2}],
474
- ['{0:1, 0:2, 0:3, 0:4, 0:5, 0:6, 0:7, 0:8, 0:9}',
475
- {1=>9,2=>9,3=>9,4=>9,5=>9}],
476
- ['{1: -12}',
477
- {1=>12,2=>0,3=>0,4=>0,5=>0}],
478
- ['{-12: -12}',
479
- {1=>0,2=>0,3=>0,4=>0,5=>0}],
480
- ['1: 12}',
481
- {1=>1,2=>1,3=>1,4=>1,5=>1}],
482
- ['1: 12',
483
- {1=>1,2=>1,3=>1,4=>1,5=>1}],
484
- ['40 ',
485
- {1=>40,2=>40,3=>40,4=>40,5=>40}],
486
- [' 40',
487
- {1=>40,2=>40,3=>40,4=>40,5=>40}],
488
- ['{1m1: 9} ',
489
- {1=>0,2=>0,3=>0,4=>0,5=>0}],
490
- [' {1m1: 9}',
491
- {1=>0,2=>0,3=>0,4=>0,5=>0}],
492
- ['[1,2,3,4,[1,2,3,4,[1,2,3,4,[1,2,3,4,[1,2,3,4,5]]]]]',
493
- {1=>1,2=>2,3=>3,4=>4,5=>[1,2,3,4,5]}],
494
- ['[1,2,3,4,[1,2,3,4,[1,2,3,4,[1,2,3,4,999,[1,2,3,4,5]]]]]',
495
- {1=>1,2=>2,3=>3,4=>4,5=>[1,2,3,4,5,999]}],
496
- [[10],
497
- {1=>10,2=>0,3=>0,4=>0,5=>0}],
498
- [[8,8,5,5,8],
499
- {1=>8,2=>8,3=>5,4=>5,5=>8}],
500
- [[1,2,3,4,[1,2,3,4,[1,2,3,4,[1,2,3,4,999,[1,2,3,4,5]]]]],
501
- {1=>1,2=>2,3=>3,4=>4,5=>[1,2,3,4,5,999]}],
502
- [3.141592653,
503
- {1=>3,2=>3,3=>3,4=>3,5=>3}],
504
- [1.618033988,
505
- {1=>1,2=>1,3=>1,4=>1,5=>1}]
506
- ]
507
- error_input = [
508
- 'x',
509
- 'xxxx',
510
- 'xxxx40',
511
- 'xx40xx',
512
- '<40xxxx></40xxxx>',
513
- '{1: 12',
514
- '{xxxxx}',
515
- '{{xxxxx}}',
516
- '{xxxxx: xxxxx}',
517
- '{2: f}',
518
- '{3: }',
519
- '{3: 4: 5}',
520
- '{xxxxx: 8000, 0: xxxxx: 8000}',
521
- '{40}',
522
- '{[40]}',
523
- '{{40}}',
524
- '{{}}',
525
- :sausage,
526
- /^the/,
527
- Object,
528
- GC,
529
- TypeError.new('foo')
530
- ]
531
- describe "normal input" do
532
- normal_input.each do |pair|
533
- it "syllable: #{pair.first}" do
534
- rhyme = obj.tokenise_rhyme('aabba')
535
- out = obj.transform_input_syllable(pair.first, 'aabba')
536
- again = obj.transform_input_syllable(out, 'aabba')
537
- expect(out).to eq pair.last
538
- expect(again).to eq out
539
- expect(again).to eq pair.last
540
- end
541
- end
542
- end
543
- describe "weird (but technically fine) input" do
544
- weird_input.each do |pair|
545
- it "syllable: #{pair.first}" do
546
- rhyme = obj.tokenise_rhyme('aabba')
547
- out = obj.transform_input_syllable(pair.first, 'aabba')
548
- again = obj.transform_input_syllable(out, 'aabba')
549
- expect(out).to eq pair.last
550
- expect(again).to eq out
551
- expect(again).to eq pair.last
552
- end
553
- end
554
- end
555
- describe "error input" do
556
- error_input.each do |i|
557
- it "syllable: #{i}" do
558
- rhyme = obj.tokenise_rhyme('aabba')
559
- expect {
560
- obj.transform_input_syllable(i, 'aabba')
561
- }.to raise_error(Poefy::SyllableError)
562
- end
563
- end
564
- end
565
- end
566
- end
567
-
568
- ##############################################################################
569
-
570
- describe "private method #poetic_form_from_text" do
571
-
572
- # Singleton which includes the method.
573
- # Make the private methods public.
574
- let(:obj) do
575
- class Sing
576
- include Poefy::PoeticFormFromText
577
- include Poefy::StringManipulation
578
- public *private_instance_methods
579
- end.new
580
- end
581
-
582
- it "'80' should rhyme with 'weighty'" do
583
- lines = ["Lorem ipsum dolor weighty", "Lorem ipsum dolor 80"]
584
- form = obj.poetic_form_from_text(lines)
585
- expect(form[:rhyme].uniq.count).to be 1
586
- end
587
- it "'80' should not rhyme with 'shoe'" do
588
- lines = ["Lorem ipsum dolor shoe", "Lorem ipsum dolor 80"]
589
- form = obj.poetic_form_from_text(lines)
590
- expect(form[:rhyme].uniq.count).to_not be 1
591
- end
592
- it "'2' should rhyme with 'shoe'" do
593
- lines = ["Lorem ipsum dolor shoe", "Lorem ipsum dolor 2"]
594
- form = obj.poetic_form_from_text(lines)
595
- expect(form[:rhyme].uniq.count).to be 1
596
- end
597
- it "'2' should not rhyme with 'weighty'" do
598
- lines = ["Lorem ipsum dolor weighty", "Lorem ipsum dolor 2"]
599
- form = obj.poetic_form_from_text(lines)
600
- expect(form[:rhyme].uniq.count).to_not be 1
601
- end
602
- it "'wind' should rhyme with 'sinned'" do
603
- lines = ["A mighty wind", "A whitey sinned"]
604
- form = obj.poetic_form_from_text(lines)
605
- expect(form[:rhyme].uniq.count).to be 1
606
- end
607
- it "'wind' should rhyme with 'mind'" do
608
- lines = ["A mighty wind", "A flighty mind"]
609
- form = obj.poetic_form_from_text(lines)
610
- expect(form[:rhyme].uniq.count).to be 1
611
- end
612
- it "'wind' should not rhyme with 'drunk'" do
613
- lines = ["A mighty wind", "A fighty drunk"]
614
- form = obj.poetic_form_from_text(lines)
615
- expect(form[:rhyme].uniq.count).to_not be 1
616
- end
617
- end
618
-
619
- end
620
-
621
- ################################################################################
1
+ #!/usr/bin/env ruby
2
+ # Encoding: UTF-8
3
+
4
+ ################################################################################
5
+
6
+ describe Poefy::Poem, "-- Unit tests" do
7
+
8
+ describe "#transform_input_regex" do
9
+
10
+ # Singleton which includes the method.
11
+ # Make the private methods public.
12
+ let(:obj) do
13
+ class Sing
14
+ include Poefy::PoeticForms
15
+ include Poefy::StringManipulation
16
+ public *private_instance_methods
17
+ end.new
18
+ end
19
+
20
+ describe "using rhyme string 'aabba'" do
21
+ normal_input = [
22
+ [/^T/,
23
+ {
24
+ 1=>/^T/,
25
+ 2=>/^T/,
26
+ 3=>/^T/,
27
+ 4=>/^T/,
28
+ 5=>/^T/
29
+ }],
30
+ [/^T/i,
31
+ {
32
+ 1=>/^T/i,
33
+ 2=>/^T/i,
34
+ 3=>/^T/i,
35
+ 4=>/^T/i,
36
+ 5=>/^T/i
37
+ }],
38
+ ['rgegerg',
39
+ {
40
+ 1=>/rgegerg/,
41
+ 2=>/rgegerg/,
42
+ 3=>/rgegerg/,
43
+ 4=>/rgegerg/,
44
+ 5=>/rgegerg/
45
+ }],
46
+ ['^[A-Z]',
47
+ {
48
+ 1=>/^[A-Z]/,
49
+ 2=>/^[A-Z]/,
50
+ 3=>/^[A-Z]/,
51
+ 4=>/^[A-Z]/,
52
+ 5=>/^[A-Z]/
53
+ }],
54
+ ['[A-Z]',
55
+ {
56
+ 1=>/[A-Z]/,
57
+ 2=>/[A-Z]/,
58
+ 3=>/[A-Z]/,
59
+ 4=>/[A-Z]/,
60
+ 5=>/[A-Z]/
61
+ }],
62
+ ['^[^e]*$',
63
+ {
64
+ 1=>/^[^e]*$/,
65
+ 2=>/^[^e]*$/,
66
+ 3=>/^[^e]*$/,
67
+ 4=>/^[^e]*$/,
68
+ 5=>/^[^e]*$/
69
+ }],
70
+ [[/a/,/b/,/c/,/d/,/e/],
71
+ {
72
+ 1=>/a/,
73
+ 2=>/b/,
74
+ 3=>/c/,
75
+ 4=>/d/,
76
+ 5=>/e/
77
+ }],
78
+ [['a','b','c','d','e'],
79
+ {
80
+ 1=>/a/,
81
+ 2=>/b/,
82
+ 3=>/c/,
83
+ 4=>/d/,
84
+ 5=>/e/
85
+ }],
86
+ [['a',/b/,'c',/d/,/e/],
87
+ {
88
+ 1=>/a/,
89
+ 2=>/b/,
90
+ 3=>/c/,
91
+ 4=>/d/,
92
+ 5=>/e/
93
+ }],
94
+ [[/a/,/b/,/c/,/d/,/e/],
95
+ {
96
+ 1=>/a/,
97
+ 2=>/b/,
98
+ 3=>/c/,
99
+ 4=>/d/,
100
+ 5=>/e/
101
+ }],
102
+ [{1=>'a', 2=>'b', 3=>'c', 4=>'d', 5=>'e'},
103
+ {
104
+ 1=>/a/,
105
+ 2=>/b/,
106
+ 3=>/c/,
107
+ 4=>/d/,
108
+ 5=>/e/
109
+ }],
110
+ [{1=>/a/, 2=>/b/, 3=>/c/, 4=>/d/, 5=>/e/},
111
+ {
112
+ 1=>/a/,
113
+ 2=>/b/,
114
+ 3=>/c/,
115
+ 4=>/d/,
116
+ 5=>/e/
117
+ }],
118
+ [{1=>/a/, 2=>'b', 3=>'c', 4=>/d/, 5=>/e/},
119
+ {
120
+ 1=>/a/,
121
+ 2=>/b/,
122
+ 3=>/c/,
123
+ 4=>/d/,
124
+ 5=>/e/
125
+ }],
126
+ [{0=>/o/, 3=>'c', 4=>/d/},
127
+ {
128
+ 1=>/o/,
129
+ 2=>/o/,
130
+ 3=>/c/,
131
+ 4=>/d/,
132
+ 5=>/o/
133
+ }],
134
+ ["['(?=^[A-Z])(?=^[^eE]*$)', '^[^eE]*$', '^[^eE]*$', '^[^eE]*$', '^[^eE]*$']",
135
+ {
136
+ 1=>/['(?=^[A-Z])(?=^[^eE]*$)', '^[^eE]*$', '^[^eE]*$', '^[^eE]*$', '^[^eE]*$']/,
137
+ 2=>/['(?=^[A-Z])(?=^[^eE]*$)', '^[^eE]*$', '^[^eE]*$', '^[^eE]*$', '^[^eE]*$']/,
138
+ 3=>/['(?=^[A-Z])(?=^[^eE]*$)', '^[^eE]*$', '^[^eE]*$', '^[^eE]*$', '^[^eE]*$']/,
139
+ 4=>/['(?=^[A-Z])(?=^[^eE]*$)', '^[^eE]*$', '^[^eE]*$', '^[^eE]*$', '^[^eE]*$']/,
140
+ 5=>/['(?=^[A-Z])(?=^[^eE]*$)', '^[^eE]*$', '^[^eE]*$', '^[^eE]*$', '^[^eE]*$']/
141
+ }],
142
+ [['(?=^[A-Z])(?=^[^eE]*$)', '^[^eE]*$', '^[^eE]*$', '^[^eE]*$', '^[^eE]*$'],
143
+ {
144
+ 1=>/(?=^[A-Z])(?=^[^eE]*$)/,
145
+ 2=>/^[^eE]*$/,
146
+ 3=>/^[^eE]*$/,
147
+ 4=>/^[^eE]*$/,
148
+ 5=>/^[^eE]*$/
149
+ }],
150
+ ["{1: '(?=^[A-Z])(?=^[^eE]*$)', 2: '^[^eE]*$', 3: '^[^eE]*$', 4: '^[^eE]*$', 5: '^[^eE]*$'}",
151
+ {
152
+ 1=>/(?=^[A-Z])(?=^[^eE]*$)/,
153
+ 2=>/^[^eE]*$/,
154
+ 3=>/^[^eE]*$/,
155
+ 4=>/^[^eE]*$/,
156
+ 5=>/^[^eE]*$/
157
+ }],
158
+ [{1=>'(?=^[A-Z])(?=^[^eE]*$)', 2=>'^[^eE]*$', 3=>'^[^eE]*$', 4=>'^[^eE]*$', 5=>'^[^eE]*$'},
159
+ {
160
+ 1=>/(?=^[A-Z])(?=^[^eE]*$)/,
161
+ 2=>/^[^eE]*$/,
162
+ 3=>/^[^eE]*$/,
163
+ 4=>/^[^eE]*$/,
164
+ 5=>/^[^eE]*$/
165
+ }],
166
+ [{1=>/(?=^[A-Z])(?=^[^eE]*$)/, 2=>'^[^eE]*$', 3=>'^[^eE]*$', 4=>/^[^eE]*$/, 5=>'^[^eE]*$'},
167
+ {
168
+ 1=>/(?=^[A-Z])(?=^[^eE]*$)/,
169
+ 2=>/^[^eE]*$/,
170
+ 3=>/^[^eE]*$/,
171
+ 4=>/^[^eE]*$/,
172
+ 5=>/^[^eE]*$/
173
+ }],
174
+ ["{0: '^[^eE]*$', 1: '(?=^[A-Z])(?=^[^eE]*$)'}",
175
+ {
176
+ 1=>/(?=^[A-Z])(?=^[^eE]*$)/,
177
+ 2=>/^[^eE]*$/,
178
+ 3=>/^[^eE]*$/,
179
+ 4=>/^[^eE]*$/,
180
+ 5=>/^[^eE]*$/
181
+ }],
182
+ [{0=>'^[^eE]*$', 1=>'(?=^[A-Z])(?=^[^eE]*$)'},
183
+ {
184
+ 1=>/(?=^[A-Z])(?=^[^eE]*$)/,
185
+ 2=>/^[^eE]*$/,
186
+ 3=>/^[^eE]*$/,
187
+ 4=>/^[^eE]*$/,
188
+ 5=>/^[^eE]*$/
189
+ }],
190
+ ["{1: '(?=^[A-Z])(?=^[^eE]*$)', 2: '^[^eE]*$', 3: '^[^eE]*$', 5: '^[^eE]*$'}",
191
+ {
192
+ 1=>/(?=^[A-Z])(?=^[^eE]*$)/,
193
+ 2=>/^[^eE]*$/,
194
+ 3=>/^[^eE]*$/,
195
+ 4=>//,
196
+ 5=>/^[^eE]*$/
197
+ }],
198
+ ["{1: '(?=^[A-Z])(?=^[^eE]*$)', 4: '^[^eE]*$'}",
199
+ {
200
+ 1=>/(?=^[A-Z])(?=^[^eE]*$)/,
201
+ 2=>//,
202
+ 3=>//,
203
+ 4=>/^[^eE]*$/,
204
+ 5=>//
205
+ }],
206
+ ["{1: '(?=^[A-Z])(?=^[^eE]*$)', 2: '^[^eE]*$', 3: '^[^eE]*$', -1: '^[^eE]*$', -2: '^[^eE]*$'}",
207
+ {
208
+ 1=>/(?=^[A-Z])(?=^[^eE]*$)/,
209
+ 2=>/^[^eE]*$/,
210
+ 3=>/^[^eE]*$/,
211
+ 4=>/^[^eE]*$/,
212
+ 5=>/^[^eE]*$/
213
+ }],
214
+ ['{7: \'^\S+$\'}',
215
+ {
216
+ 1=>//,
217
+ 2=>//,
218
+ 3=>//,
219
+ 4=>//,
220
+ 5=>//,
221
+ 7=>/^\S+$/
222
+ }],
223
+ [{'3m1'=>/a/, 2=>'b', 0=>/c/},
224
+ {
225
+ 1=>/a/,
226
+ 2=>/b/,
227
+ 3=>/c/,
228
+ 4=>/a/,
229
+ 5=>/c/
230
+ }],
231
+ ]
232
+ weird_input = [
233
+ ['x',
234
+ { 1=>/x/,
235
+ 2=>/x/,
236
+ 3=>/x/,
237
+ 4=>/x/,
238
+ 5=>/x/
239
+ }],
240
+ ['xxxx',
241
+ { 1=>/xxxx/,
242
+ 2=>/xxxx/,
243
+ 3=>/xxxx/,
244
+ 4=>/xxxx/,
245
+ 5=>/xxxx/
246
+ }],
247
+ ['xxxx40',
248
+ { 1=>/xxxx40/,
249
+ 2=>/xxxx40/,
250
+ 3=>/xxxx40/,
251
+ 4=>/xxxx40/,
252
+ 5=>/xxxx40/
253
+ }],
254
+ ['xx40xx',
255
+ { 1=>/xx40xx/,
256
+ 2=>/xx40xx/,
257
+ 3=>/xx40xx/,
258
+ 4=>/xx40xx/,
259
+ 5=>/xx40xx/
260
+ }],
261
+ ['<40xxxx></40xxxx>',
262
+ { 1=>/<40xxxx><\/40xxxx>/,
263
+ 2=>/<40xxxx><\/40xxxx>/,
264
+ 3=>/<40xxxx><\/40xxxx>/,
265
+ 4=>/<40xxxx><\/40xxxx>/,
266
+ 5=>/<40xxxx><\/40xxxx>/
267
+ }],
268
+ ['{xxxxx: xxxxx}',
269
+ {1=>//,2=>//,3=>//,4=>//,5=>//}],
270
+ ['{2: f}',
271
+ {1=>//,2=>/f/,3=>//,4=>//,5=>//}],
272
+ [:foo,
273
+ {1=>/foo/,2=>/foo/,3=>/foo/,4=>/foo/,5=>/foo/}],
274
+ [{0=>:foo, 4=>:bar},
275
+ {1=>/foo/,2=>/foo/,3=>/foo/,4=>/bar/,5=>/foo/}],
276
+ [123,
277
+ {1=>/123/,2=>/123/,3=>/123/,4=>/123/,5=>/123/}],
278
+ [Object,
279
+ {1=>/Object/,2=>/Object/,3=>/Object/,4=>/Object/,5=>/Object/}],
280
+ [GC,
281
+ {1=>/GC/,2=>/GC/,3=>/GC/,4=>/GC/,5=>/GC/}],
282
+ [TypeError.new('foo'),
283
+ {1=>/foo/,2=>/foo/,3=>/foo/,4=>/foo/,5=>/foo/}],
284
+ ['{xxxxx}',
285
+ {1=>//,2=>//,3=>//,4=>//,5=>//}],
286
+ ['{{xxxxx}}',
287
+ {1=>//,2=>//,3=>//,4=>//,5=>//}],
288
+ ['{3: }',
289
+ {1=>//,2=>//,3=>//,4=>//,5=>//}],
290
+ ['{40}',
291
+ {1=>//,2=>//,3=>//,4=>//,40=>//,5=>//}],
292
+ ['{[40]}',
293
+ {1=>//,2=>//,3=>//,4=>//,5=>//}],
294
+ ['{{40}}',
295
+ {1=>//,2=>//,3=>//,4=>//,5=>//}],
296
+ ['{{}}',
297
+ {1=>//,2=>//,3=>//,4=>//,5=>//}],
298
+ ['{1: 12',
299
+ {1=>/{1: 12/,2=>/{1: 12/,3=>/{1: 12/,4=>/{1: 12/,5=>/{1: 12/}],
300
+ ]
301
+ error_input = [
302
+ "{1: /(?=^[A-Z])(?=^[^eE]*$)/, 4: /^[^eE]*$/}",
303
+ '{3: 4: 5}',
304
+ '{xxxxx: 8000, 0: xxxxx: 8000}',
305
+ ]
306
+ describe "normal input" do
307
+ normal_input.each do |pair|
308
+ it "regex: #{pair.first}" do
309
+ rhyme = obj.tokenise_rhyme('aabba')
310
+ out = obj.transform_input_regex(pair.first, 'aabba')
311
+ again = obj.transform_input_regex(out, 'aabba')
312
+ expect(out).to eq pair.last
313
+ expect(again).to eq out
314
+ expect(again).to eq pair.last
315
+ end
316
+ end
317
+ end
318
+ describe "weird (but technically fine) input" do
319
+ weird_input.each do |pair|
320
+ it "regex: #{pair.first}" do
321
+ rhyme = obj.tokenise_rhyme('aabba')
322
+ out = obj.transform_input_regex(pair.first, 'aabba')
323
+ again = obj.transform_input_regex(out, 'aabba')
324
+ expect(out).to eq pair.last
325
+ expect(again).to eq out
326
+ expect(again).to eq pair.last
327
+ end
328
+ end
329
+ end
330
+ describe "error input" do
331
+ error_input.each do |i|
332
+ it "regex: #{i}" do
333
+ rhyme = obj.tokenise_rhyme('aabba')
334
+ expect {
335
+ obj.transform_input_regex(i, 'aabba')
336
+ }.to raise_error(Poefy::RegexError)
337
+ end
338
+ end
339
+ end
340
+ end
341
+ end
342
+
343
+ ##############################################################################
344
+
345
+ describe "#transform_input_syllable" do
346
+
347
+ # Singleton which includes the method.
348
+ # Make the private methods public.
349
+ let(:obj) do
350
+ class Sing
351
+ include Poefy::PoeticForms
352
+ include Poefy::StringManipulation
353
+ public *private_instance_methods
354
+ end.new
355
+ end
356
+ describe "using rhyme string 'aabba'" do
357
+ normal_input = [
358
+ [0,
359
+ {1=>0,2=>0,3=>0,4=>0,5=>0}],
360
+ [10,
361
+ {1=>10,2=>10,3=>10,4=>10,5=>10}],
362
+ ['0',
363
+ {1=>0,2=>0,3=>0,4=>0,5=>0}],
364
+ ['10',
365
+ {1=>10,2=>10,3=>10,4=>10,5=>10}],
366
+ ['99',
367
+ {1=>99,2=>99,3=>99,4=>99,5=>99}],
368
+ ['8,9,10',
369
+ {1=>[8,9,10],2=>[8,9,10],3=>[8,9,10],4=>[8,9,10],5=>[8,9,10]}],
370
+ ['6,7,8,9',
371
+ {1=>[6,7,8,9],2=>[6,7,8,9],3=>[6,7,8,9],4=>[6,7,8,9],5=>[6,7,8,9]}],
372
+ ['[10]',
373
+ {1=>10,2=>0,3=>0,4=>0,5=>0}],
374
+ ['[8,8,5,5,8]',
375
+ {1=>8,2=>8,3=>5,4=>5,5=>8}],
376
+ ['[[8,9],[8,9],[4,5,6],[4,5,6],[8,9]]',
377
+ {1=>[8,9],2=>[8,9],3=>[4,5,6],4=>[4,5,6],5=>[8,9]}],
378
+ ['{1:8,2:8,3:5,4:5,5:8}',
379
+ {1=>8,2=>8,3=>5,4=>5,5=>8}],
380
+ ['{1:8,2:8,3:5,5:8}',
381
+ {1=>8,2=>8,3=>5,4=>0,5=>8}],
382
+ ['{0:99,1:8,2:8,3:5,5:8}',
383
+ {1=>8,2=>8,3=>5,4=>99,5=>8}],
384
+ ['{1:[8,9],2:[8,9],3:[4,5,6],4:[4,5,6],5:[8,9]}',
385
+ {1=>[8,9],2=>[8,9],3=>[4,5,6],4=>[4,5,6],5=>[8,9]}],
386
+ ['{1:[8,9],2:[8,9],3:[4,5,6],5:[8,9]}',
387
+ {1=>[8,9],2=>[8,9],3=>[4,5,6],4=>0,5=>[8,9]}],
388
+ ['{0:99,1:[8,9],2:[8,9],3:[4,5,6],5:[8,9]}',
389
+ {1=>[8,9],2=>[8,9],3=>[4,5,6],4=>99,5=>[8,9]}],
390
+ ['{0:[8,9],3:[4,5,6],4:[4,5,6]}',
391
+ {1=>[8,9],2=>[8,9],3=>[4,5,6],4=>[4,5,6],5=>[8,9]}],
392
+ ['{1:8,5:8}',
393
+ {1=>8,2=>0,3=>0,4=>0,5=>8}],
394
+ ['{1:8,2:8,3:5,-2:5,-1:8}',
395
+ {1=>8,2=>8,3=>5,4=>5,5=>8}],
396
+ ['{o:1,e:2}',
397
+ {1=>1,2=>2,3=>1,4=>2,5=>1}],
398
+ ['{o:1,0:9}',
399
+ {1=>1,2=>9,3=>1,4=>9,5=>1}],
400
+ ['{o:1,e:2,0:9}',
401
+ {1=>1,2=>2,3=>1,4=>2,5=>1}],
402
+ ['{o:8,e:6,-2:6,-1:4}',
403
+ {1=>8,2=>6,3=>8,4=>6,5=>4}],
404
+ ['{o:8,e:6,-2:6,-1:4,0:9}',
405
+ {1=>8,2=>6,3=>8,4=>6,5=>4}],
406
+ ['8-10',
407
+ {1=>[8,9,10],2=>[8,9,10],3=>[8,9,10],4=>[8,9,10],5=>[8,9,10]}],
408
+ ['6-9',
409
+ {1=>[6,7,8,9],2=>[6,7,8,9],3=>[6,7,8,9],4=>[6,7,8,9],5=>[6,7,8,9]}],
410
+ ['4-9',
411
+ { 1=>[4,5,6,7,8,9],
412
+ 2=>[4,5,6,7,8,9],
413
+ 3=>[4,5,6,7,8,9],
414
+ 4=>[4,5,6,7,8,9],
415
+ 5=>[4,5,6,7,8,9]}],
416
+ ['4,6,8-10,12',
417
+ { 1=>[4,6,8,9,10,12],
418
+ 2=>[4,6,8,9,10,12],
419
+ 3=>[4,6,8,9,10,12],
420
+ 4=>[4,6,8,9,10,12],
421
+ 5=>[4,6,8,9,10,12]}],
422
+ ['[4,6,8-10,12]',
423
+ {1=>4,2=>6,3=>[8,9,10],4=>12,5=>0}],
424
+ ['{e:"4,6,8-10,12"}',
425
+ {1=>0,2=>[4,6,8,9,10,12],3=>0,4=>[4,6,8,9,10,12],5=>0}],
426
+ ['{0:6,-1:6-10}',
427
+ {1=>6,2=>6,3=>6,4=>6,5=>[6,7,8,9,10]}],
428
+ ['{0:4-6,-1:6-10}',
429
+ {1=>[4,5,6],2=>[4,5,6],3=>[4,5,6],4=>[4,5,6],5=>[6,7,8,9,10]}],
430
+ ['{e:4-6,-1:6-10}',
431
+ {1=>0,2=>[4,5,6],3=>0,4=>[4,5,6],5=>[6,7,8,9,10]}],
432
+ ['[[8,9],[8,9],[4,5,6],[4,5,6],[8,9]]',
433
+ {1=>[8,9],2=>[8,9],3=>[4,5,6],4=>[4,5,6],5=>[8,9]}],
434
+ ['[[8-9],[8-9],[4-6],[4-6],[8-9]]',
435
+ {1=>[8,9],2=>[8,9],3=>[4,5,6],4=>[4,5,6],5=>[8,9]}],
436
+ ['[[8,9],[8,9],4-6,4-6,[8,9]]',
437
+ {1=>[8,9],2=>[8,9],3=>[4,5,6],4=>[4,5,6],5=>[8,9]}],
438
+ ['[8-9,8-9,4-6,4-6,8-9]',
439
+ {1=>[8,9],2=>[8,9],3=>[4,5,6],4=>[4,5,6],5=>[8,9]}],
440
+ ['{0:11,3m0:30}',
441
+ {1=>11,2=>11,3=>30,4=>11,5=>11}],
442
+ ['{0:11,3m0:30,3m1:31}',
443
+ {1=>31,2=>11,3=>30,4=>31,5=>11}],
444
+ [{0=>11,'3m0'=>30,'3m1'=>31},
445
+ {1=>31,2=>11,3=>30,4=>31,5=>11}],
446
+ [{0=>11,'3m0'=>[1,2,3,4],'3m1'=>31},
447
+ {1=>31,2=>11,3=>[1,2,3,4],4=>31,5=>11}]
448
+ ]
449
+ weird_input = [
450
+ ['40xxxx',
451
+ {1=>40,2=>40,3=>40,4=>40,5=>40}],
452
+ ['{3: 4 5}',
453
+ {1=>0,2=>0,3=>4,4=>0,5=>0}],
454
+ ['{}',
455
+ {1=>0,2=>0,3=>0,4=>0,5=>0}],
456
+ ['{xxxxx: 8}',
457
+ {1=>0,2=>0,3=>0,4=>0,5=>0}],
458
+ ['{xxxxx: 8000}',
459
+ {1=>0,2=>0,3=>0,4=>0,5=>0}],
460
+ ['{2m12: 9}',
461
+ {1=>0,2=>0,3=>0,4=>0,5=>0}],
462
+ ['{1m0: 9}',
463
+ {1=>9,2=>9,3=>9,4=>9,5=>9}],
464
+ ['{1m1: 9}',
465
+ {1=>0,2=>0,3=>0,4=>0,5=>0}],
466
+ ['{-1m0: 9}',
467
+ {1=>9,2=>9,3=>9,4=>9,5=>9}],
468
+ ['{-1m1: 9}',
469
+ {1=>0,2=>0,3=>0,4=>0,5=>0}],
470
+ ['{-1m1: -9}',
471
+ {1=>0,2=>0,3=>0,4=>0,5=>0}],
472
+ ['{10: 2}',
473
+ {1=>0,2=>0,3=>0,4=>0,5=>0,10=>2}],
474
+ ['{0:1, 0:2, 0:3, 0:4, 0:5, 0:6, 0:7, 0:8, 0:9}',
475
+ {1=>9,2=>9,3=>9,4=>9,5=>9}],
476
+ ['{1: -12}',
477
+ {1=>12,2=>0,3=>0,4=>0,5=>0}],
478
+ ['{-12: -12}',
479
+ {1=>0,2=>0,3=>0,4=>0,5=>0}],
480
+ ['1: 12}',
481
+ {1=>1,2=>1,3=>1,4=>1,5=>1}],
482
+ ['1: 12',
483
+ {1=>1,2=>1,3=>1,4=>1,5=>1}],
484
+ ['40 ',
485
+ {1=>40,2=>40,3=>40,4=>40,5=>40}],
486
+ [' 40',
487
+ {1=>40,2=>40,3=>40,4=>40,5=>40}],
488
+ ['{1m1: 9} ',
489
+ {1=>0,2=>0,3=>0,4=>0,5=>0}],
490
+ [' {1m1: 9}',
491
+ {1=>0,2=>0,3=>0,4=>0,5=>0}],
492
+ ['[1,2,3,4,[1,2,3,4,[1,2,3,4,[1,2,3,4,[1,2,3,4,5]]]]]',
493
+ {1=>1,2=>2,3=>3,4=>4,5=>[1,2,3,4,5]}],
494
+ ['[1,2,3,4,[1,2,3,4,[1,2,3,4,[1,2,3,4,999,[1,2,3,4,5]]]]]',
495
+ {1=>1,2=>2,3=>3,4=>4,5=>[1,2,3,4,5,999]}],
496
+ [[10],
497
+ {1=>10,2=>0,3=>0,4=>0,5=>0}],
498
+ [[8,8,5,5,8],
499
+ {1=>8,2=>8,3=>5,4=>5,5=>8}],
500
+ [[1,2,3,4,[1,2,3,4,[1,2,3,4,[1,2,3,4,999,[1,2,3,4,5]]]]],
501
+ {1=>1,2=>2,3=>3,4=>4,5=>[1,2,3,4,5,999]}],
502
+ [3.141592653,
503
+ {1=>3,2=>3,3=>3,4=>3,5=>3}],
504
+ [1.618033988,
505
+ {1=>1,2=>1,3=>1,4=>1,5=>1}]
506
+ ]
507
+ error_input = [
508
+ 'x',
509
+ 'xxxx',
510
+ 'xxxx40',
511
+ 'xx40xx',
512
+ '<40xxxx></40xxxx>',
513
+ '{1: 12',
514
+ '{xxxxx}',
515
+ '{{xxxxx}}',
516
+ '{xxxxx: xxxxx}',
517
+ '{2: f}',
518
+ '{3: }',
519
+ '{3: 4: 5}',
520
+ '{xxxxx: 8000, 0: xxxxx: 8000}',
521
+ '{40}',
522
+ '{[40]}',
523
+ '{{40}}',
524
+ '{{}}',
525
+ :sausage,
526
+ /^the/,
527
+ Object,
528
+ GC,
529
+ TypeError.new('foo')
530
+ ]
531
+ describe "normal input" do
532
+ normal_input.each do |pair|
533
+ it "syllable: #{pair.first}" do
534
+ rhyme = obj.tokenise_rhyme('aabba')
535
+ out = obj.transform_input_syllable(pair.first, 'aabba')
536
+ again = obj.transform_input_syllable(out, 'aabba')
537
+ expect(out).to eq pair.last
538
+ expect(again).to eq out
539
+ expect(again).to eq pair.last
540
+ end
541
+ end
542
+ end
543
+ describe "weird (but technically fine) input" do
544
+ weird_input.each do |pair|
545
+ it "syllable: #{pair.first}" do
546
+ rhyme = obj.tokenise_rhyme('aabba')
547
+ out = obj.transform_input_syllable(pair.first, 'aabba')
548
+ again = obj.transform_input_syllable(out, 'aabba')
549
+ expect(out).to eq pair.last
550
+ expect(again).to eq out
551
+ expect(again).to eq pair.last
552
+ end
553
+ end
554
+ end
555
+ describe "error input" do
556
+ error_input.each do |i|
557
+ it "syllable: #{i}" do
558
+ rhyme = obj.tokenise_rhyme('aabba')
559
+ expect {
560
+ obj.transform_input_syllable(i, 'aabba')
561
+ }.to raise_error(Poefy::SyllableError)
562
+ end
563
+ end
564
+ end
565
+ end
566
+ end
567
+
568
+ ##############################################################################
569
+
570
+ describe "private method #poetic_form_from_text" do
571
+
572
+ # Singleton which includes the method.
573
+ # Make the private methods public.
574
+ let(:obj) do
575
+ class Sing
576
+ include Poefy::PoeticFormFromText
577
+ include Poefy::StringManipulation
578
+ public *private_instance_methods
579
+ end.new
580
+ end
581
+
582
+ it "'80' should rhyme with 'weighty'" do
583
+ lines = ["Lorem ipsum dolor weighty", "Lorem ipsum dolor 80"]
584
+ form = obj.poetic_form_from_text(lines)
585
+ expect(form[:rhyme].uniq.count).to be 1
586
+ end
587
+ it "'80' should not rhyme with 'shoe'" do
588
+ lines = ["Lorem ipsum dolor shoe", "Lorem ipsum dolor 80"]
589
+ form = obj.poetic_form_from_text(lines)
590
+ expect(form[:rhyme].uniq.count).to_not be 1
591
+ end
592
+ it "'2' should rhyme with 'shoe'" do
593
+ lines = ["Lorem ipsum dolor shoe", "Lorem ipsum dolor 2"]
594
+ form = obj.poetic_form_from_text(lines)
595
+ expect(form[:rhyme].uniq.count).to be 1
596
+ end
597
+ it "'2' should not rhyme with 'weighty'" do
598
+ lines = ["Lorem ipsum dolor weighty", "Lorem ipsum dolor 2"]
599
+ form = obj.poetic_form_from_text(lines)
600
+ expect(form[:rhyme].uniq.count).to_not be 1
601
+ end
602
+ it "'wind' should rhyme with 'sinned'" do
603
+ lines = ["A mighty wind", "A whitey sinned"]
604
+ form = obj.poetic_form_from_text(lines)
605
+ expect(form[:rhyme].uniq.count).to be 1
606
+ end
607
+ it "'wind' should rhyme with 'mind'" do
608
+ lines = ["A mighty wind", "A flighty mind"]
609
+ form = obj.poetic_form_from_text(lines)
610
+ expect(form[:rhyme].uniq.count).to be 1
611
+ end
612
+ it "'wind' should not rhyme with 'drunk'" do
613
+ lines = ["A mighty wind", "A fighty drunk"]
614
+ form = obj.poetic_form_from_text(lines)
615
+ expect(form[:rhyme].uniq.count).to_not be 1
616
+ end
617
+ end
618
+
619
+ end
620
+
621
+ ################################################################################