slaw 2.2.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,7 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  require 'slaw'
4
+ require 'slaw/grammars/za/act_nodes'
4
5
 
5
6
  describe Slaw::ActGenerator do
6
7
  subject { Slaw::ActGenerator.new('za') }
@@ -27,15 +28,20 @@ describe Slaw::ActGenerator do
27
28
  b.doc.root.to_xml(encoding: 'UTF-8')
28
29
  end
29
30
 
31
+ before(:each) do
32
+ Slaw::Grammars::ZA::Act::Crossheading.counters.clear
33
+ Slaw::Grammars::ZA::Act::BlockElements.counters.clear
34
+ end
35
+
30
36
  #-------------------------------------------------------------------------------
31
37
  # Remarks
32
38
 
33
39
  describe 'remark' do
34
40
  it 'should handle a plain remark' do
35
- node = parse :block_paragraphs, <<EOS
41
+ node = parse :generic_container, <<EOS
36
42
  [[Section 2 amended by Act 23 of 2004]]
37
43
  EOS
38
- to_xml(node, "").should == '<paragraph id="paragraph-0">
44
+ to_xml(node, "").should == '<paragraph id="paragraph0">
39
45
  <content>
40
46
  <p>
41
47
  <remark status="editorial">[Section 2 amended by Act 23 of 2004]</remark>
@@ -45,10 +51,10 @@ EOS
45
51
  end
46
52
 
47
53
  it 'should handle an inline remark at the end of a sentence' do
48
- node = parse :block_paragraphs, <<EOS
54
+ node = parse :generic_container, <<EOS
49
55
  This statement has an inline remark. [[Section 2 amended by Act 23 of 2004]]
50
56
  EOS
51
- to_xml(node, "").should == '<paragraph id="paragraph-0">
57
+ to_xml(node, "").should == '<paragraph id="paragraph0">
52
58
  <content>
53
59
  <p>This statement has an inline remark. <remark status="editorial">[Section 2 amended by Act 23 of 2004]</remark></p>
54
60
  </content>
@@ -68,10 +74,10 @@ EOS
68
74
  end
69
75
 
70
76
  it 'should handle many inline remarks' do
71
- node = parse :block_paragraphs, <<EOS
77
+ node = parse :generic_container, <<EOS
72
78
  This statement has an inline remark. [[Section 2 amended by Act 23 of 2004]]. And now some more. [[Another remark]] [[and another]]
73
79
  EOS
74
- to_xml(node, "").should == '<paragraph id="paragraph-0">
80
+ to_xml(node, "").should == '<paragraph id="paragraph0">
75
81
  <content>
76
82
  <p>This statement has an inline remark. <remark status="editorial">[Section 2 amended by Act 23 of 2004]</remark>. And now some more. <remark status="editorial">[Another remark]</remark> <remark status="editorial">[and another]</remark></p>
77
83
  </content>
@@ -88,7 +94,7 @@ EOS
88
94
  to_xml(node).should == '<section id="section-1">
89
95
  <num>1.</num>
90
96
  <heading>Section title</heading>
91
- <paragraph id="section-1.paragraph-0">
97
+ <paragraph id="section-1.paragraph0">
92
98
  <content>
93
99
  <p>Some text is a long line.</p>
94
100
  <p>
@@ -110,7 +116,7 @@ EOS
110
116
  to_xml(node).should == '<section id="section-1">
111
117
  <num>1.</num>
112
118
  <heading>Section title</heading>
113
- <paragraph id="section-1.paragraph-0">
119
+ <paragraph id="section-1.paragraph0">
114
120
  <content>
115
121
  <p>Some text is a long line.</p>
116
122
  </content>
@@ -172,7 +178,7 @@ EOS
172
178
  <hcontainer id="schedule1" name="schedule">
173
179
  <heading>Schedule 1</heading>
174
180
  <subheading>A Title</subheading>
175
- <paragraph id="schedule1.paragraph-0">
181
+ <paragraph id="schedule1.paragraph0">
176
182
  <content>
177
183
  <p>
178
184
  <remark status="editorial">[Schedule 1 added by Act 23 of 2004]</remark>
@@ -185,6 +191,17 @@ EOS
185
191
  </doc>
186
192
  </component>'
187
193
  end
194
+
195
+ it 'should handle other inline content' do
196
+ node = parse :generic_container, <<EOS
197
+ Remark [[with **bold** and //italics// and [a ref](/a/b)]].
198
+ EOS
199
+ to_xml(node, "").should == '<paragraph id="paragraph0">
200
+ <content>
201
+ <p>Remark <remark status="editorial">[with <b>bold</b> and <i>italics</i> and <ref href="/a/b">a ref</ref>]</remark>.</p>
202
+ </content>
203
+ </paragraph>'
204
+ end
188
205
  end
189
206
 
190
207
  #-------------------------------------------------------------------------------
@@ -192,10 +209,10 @@ EOS
192
209
 
193
210
  describe 'ref' do
194
211
  it 'should handle a plain ref' do
195
- node = parse :block_paragraphs, <<EOS
212
+ node = parse :generic_container, <<EOS
196
213
  Hello [there](/za/act/123) friend.
197
214
  EOS
198
- to_xml(node, "").should == '<paragraph id="paragraph-0">
215
+ to_xml(node, "").should == '<paragraph id="paragraph0">
199
216
  <content>
200
217
  <p>Hello <ref href="/za/act/123">there</ref> friend.</p>
201
218
  </content>
@@ -203,10 +220,10 @@ EOS
203
220
  end
204
221
 
205
222
  it 'should work many on a line' do
206
- node = parse :block_paragraphs, <<EOS
223
+ node = parse :generic_container, <<EOS
207
224
  Hello [there](/za/act/123) friend [and](http://foo.bar.com/with space) you too.
208
225
  EOS
209
- to_xml(node, "").should == '<paragraph id="paragraph-0">
226
+ to_xml(node, "").should == '<paragraph id="paragraph0">
210
227
  <content>
211
228
  <p>Hello <ref href="/za/act/123">there</ref> friend <ref href="http://foo.bar.com/with space">and</ref> you too.</p>
212
229
  </content>
@@ -214,10 +231,10 @@ EOS
214
231
  end
215
232
 
216
233
  it 'should handle brackets' do
217
- node = parse :block_paragraphs, <<EOS
234
+ node = parse :generic_container, <<EOS
218
235
  Hello ([there](/za/act/123)).
219
236
  EOS
220
- to_xml(node, "").should == '<paragraph id="paragraph-0">
237
+ to_xml(node, "").should == '<paragraph id="paragraph0">
221
238
  <content>
222
239
  <p>Hello (<ref href="/za/act/123">there</ref>).</p>
223
240
  </content>
@@ -225,10 +242,10 @@ EOS
225
242
  end
226
243
 
227
244
  it 'should handle many clauses on a line' do
228
- node = parse :block_paragraphs, <<EOS
245
+ node = parse :generic_container, <<EOS
229
246
  Hello [there](/za/act/123)[[remark one]] my[friend](/za) [[remark 2]][end](/foo).
230
247
  EOS
231
- to_xml(node, "").should == '<paragraph id="paragraph-0">
248
+ to_xml(node, "").should == '<paragraph id="paragraph0">
232
249
  <content>
233
250
  <p>Hello <ref href="/za/act/123">there</ref><remark status="editorial">[remark one]</remark> my<ref href="/za">friend</ref> <remark status="editorial">[remark 2]</remark><ref href="/foo">end</ref>.</p>
234
251
  </content>
@@ -236,12 +253,12 @@ EOS
236
253
  end
237
254
 
238
255
  it 'text should not cross end of line' do
239
- node = parse :block_paragraphs, <<EOS
256
+ node = parse :generic_container, <<EOS
240
257
  Hello [there
241
258
 
242
259
  my](/za/act/123) friend.
243
260
  EOS
244
- to_xml(node, "").should == '<paragraph id="paragraph-0">
261
+ to_xml(node, "").should == '<paragraph id="paragraph0">
245
262
  <content>
246
263
  <p>Hello [there</p>
247
264
  <p>my](/za/act/123) friend.</p>
@@ -250,11 +267,11 @@ EOS
250
267
  end
251
268
 
252
269
  it 'href should not cross end of line' do
253
- node = parse :block_paragraphs, <<EOS
270
+ node = parse :generic_container, <<EOS
254
271
  Hello [there](/za/act
255
272
  /123) friend.
256
273
  EOS
257
- to_xml(node, "").should == '<paragraph id="paragraph-0">
274
+ to_xml(node, "").should == '<paragraph id="paragraph0">
258
275
  <content>
259
276
  <p>Hello [there](/za/act</p>
260
277
  <p>/123) friend.</p>
@@ -263,13 +280,13 @@ EOS
263
280
  end
264
281
 
265
282
  it 'href should handle refs in a list' do
266
- node = parse :block_paragraphs, <<EOS
283
+ node = parse :generic_container, <<EOS
267
284
  2.18.1 a traffic officer appointed in terms of section 3 of the Road Traffic [Act, No. 29 of 1989](/za/act/1989/29) or section 3A of the National Road Traffic [Act No. 93 of 1996](/za/act/1996/93) as the case may be;
268
285
  EOS
269
- to_xml(node, "").should == '<paragraph id="paragraph-0">
286
+ to_xml(node, "").should == '<paragraph id="paragraph0">
270
287
  <content>
271
- <blockList id="paragraph-0.list0">
272
- <item id="paragraph-0.list0.2.18.1">
288
+ <blockList id="paragraph0.list0">
289
+ <item id="paragraph0.list0.2.18.1">
273
290
  <num>2.18.1</num>
274
291
  <p>a traffic officer appointed in terms of section 3 of the Road Traffic <ref href="/za/act/1989/29">Act, No. 29 of 1989</ref> or section 3A of the National Road Traffic <ref href="/za/act/1996/93">Act No. 93 of 1996</ref> as the case may be;</p>
275
292
  </item>
@@ -279,12 +296,12 @@ EOS
279
296
  end
280
297
 
281
298
  it 'should handle a link in an inline remark' do
282
- node = parse :block_paragraphs, <<EOS
299
+ node = parse :generic_container, <<EOS
283
300
  This statement has [[a [link in](/foo/bar) a remark]]
284
301
  This statement has [[[a link in](/foo/bar) a remark]]
285
302
  This statement has [[a [link in a remark](/foo/bar)]]
286
303
  EOS
287
- to_xml(node, "").should == '<paragraph id="paragraph-0">
304
+ to_xml(node, "").should == '<paragraph id="paragraph0">
288
305
  <content>
289
306
  <p>This statement has <remark status="editorial">[a <ref href="/foo/bar">link in</ref> a remark]</remark></p>
290
307
  <p>This statement has <remark status="editorial">[<ref href="/foo/bar">a link in</ref> a remark]</remark></p>
@@ -299,10 +316,10 @@ EOS
299
316
 
300
317
  describe 'images' do
301
318
  it 'should handle a simple image' do
302
- node = parse :block_paragraphs, <<EOS
319
+ node = parse :generic_container, <<EOS
303
320
  Hello ![title](media/foo.png) friend.
304
321
  EOS
305
- to_xml(node, "").should == '<paragraph id="paragraph-0">
322
+ to_xml(node, "").should == '<paragraph id="paragraph0">
306
323
  <content>
307
324
  <p>Hello <img src="media/foo.png" alt="title"/> friend.</p>
308
325
  </content>
@@ -310,10 +327,10 @@ EOS
310
327
  end
311
328
 
312
329
  it 'should work many on a line' do
313
- node = parse :block_paragraphs, <<EOS
330
+ node = parse :generic_container, <<EOS
314
331
  Hello ![title](media/foo.png) friend and ![](media/bar.png) a second.
315
332
  EOS
316
- to_xml(node, "").should == '<paragraph id="paragraph-0">
333
+ to_xml(node, "").should == '<paragraph id="paragraph0">
317
334
  <content>
318
335
  <p>Hello <img src="media/foo.png" alt="title"/> friend and <img src="media/bar.png"/> a second.</p>
319
336
  </content>
@@ -340,4 +357,127 @@ EOS
340
357
  end
341
358
  end
342
359
 
360
+ #-------------------------------------------------------------------------------
361
+ # italics and bold
362
+
363
+ describe 'bold' do
364
+ it 'should handle simple bold' do
365
+ node = parse :generic_container, <<EOS
366
+ Hello **something bold** foo
367
+ EOS
368
+ to_xml(node, "").should == '<paragraph id="paragraph0">
369
+ <content>
370
+ <p>Hello <b>something bold</b> foo</p>
371
+ </content>
372
+ </paragraph>'
373
+ end
374
+
375
+ it 'should handle complex bold' do
376
+ node = parse :generic_container, <<EOS
377
+ A [**link**](/a/b) with bold
378
+ This is **bold with [a link](/a/b)** end
379
+ This is **bold //italics [a link](/a/b)//** end
380
+ A **[link**](/a/b)**
381
+ A **[link**](/a/b)
382
+ EOS
383
+ to_xml(node, "").should == '<paragraph id="paragraph0">
384
+ <content>
385
+ <p>A <ref href="/a/b"><b>link</b></ref> with bold</p>
386
+ <p>This is <b>bold with <ref href="/a/b">a link</ref></b> end</p>
387
+ <p>This is <b>bold <i>italics <ref href="/a/b">a link</ref></i></b> end</p>
388
+ <p>A <b>[link</b>](/a/b)**</p>
389
+ <p>A **<ref href="/a/b">link**</ref></p>
390
+ </content>
391
+ </paragraph>'
392
+ end
393
+
394
+ it 'should not mistake bold' do
395
+ node = parse :generic_container, <<EOS
396
+ Hello **something
397
+ New line**
398
+ **New line
399
+ ****
400
+ **
401
+ *
402
+ * * foo **
403
+ * * foo * *
404
+ ** foo * *
405
+ EOS
406
+ to_xml(node, "").should == '<paragraph id="paragraph0">
407
+ <content>
408
+ <p>Hello **something</p>
409
+ <p>New line**</p>
410
+ <p>**New line</p>
411
+ <p>****</p>
412
+ <p>**</p>
413
+ <p>*</p>
414
+ <p>* * foo **</p>
415
+ <p>* * foo * *</p>
416
+ <p>** foo * *</p>
417
+ </content>
418
+ </paragraph>'
419
+ end
420
+ end
421
+
422
+ describe 'italics' do
423
+ it 'should handle simple italics' do
424
+ node = parse :generic_container, <<EOS
425
+ Hello //something italics// foo
426
+ EOS
427
+ to_xml(node, "").should == '<paragraph id="paragraph0">
428
+ <content>
429
+ <p>Hello <i>something italics</i> foo</p>
430
+ </content>
431
+ </paragraph>'
432
+ end
433
+
434
+ it 'should handle complex italics' do
435
+ node = parse :generic_container, <<EOS
436
+ A [//link//](/a/b) with italics
437
+ This is //italics with [a link](/a/b)// end
438
+ A //italics**bold//**
439
+ A **bold//italics**//
440
+ A //[link//](/a/b)//
441
+ A //[link//](/a/b)
442
+ EOS
443
+ to_xml(node, "").should == '<paragraph id="paragraph0">
444
+ <content>
445
+ <p>A <ref href="/a/b"><i>link</i></ref> with italics</p>
446
+ <p>This is <i>italics with <ref href="/a/b">a link</ref></i> end</p>
447
+ <p>A //italics<b>bold//</b></p>
448
+ <p>A **bold<i>italics**</i></p>
449
+ <p>A <i>[link</i>](/a/b)//</p>
450
+ <p>A //<ref href="/a/b">link//</ref></p>
451
+ </content>
452
+ </paragraph>'
453
+ end
454
+
455
+ it 'should not mistake italics' do
456
+ node = parse :generic_container, <<EOS
457
+ Hello //something
458
+ New line//
459
+ //New line
460
+ ////
461
+ //
462
+ /
463
+ / / foo //
464
+ / / foo / /
465
+ // foo / /
466
+ EOS
467
+ to_xml(node, "").should == '<paragraph id="paragraph0">
468
+ <content>
469
+ <p>Hello //something</p>
470
+ <p>New line//</p>
471
+ <p>//New line</p>
472
+ <p>////</p>
473
+ <p>//</p>
474
+ <p>/</p>
475
+ <p>/ / foo //</p>
476
+ <p>/ / foo / /</p>
477
+ <p>// foo / /</p>
478
+ </content>
479
+ </paragraph>'
480
+ end
481
+ end
482
+
343
483
  end
@@ -1,6 +1,7 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  require 'slaw'
4
+ require 'slaw/grammars/za/act_nodes'
4
5
 
5
6
  describe Slaw::ActGenerator do
6
7
  subject { Slaw::ActGenerator.new('za') }
@@ -27,6 +28,11 @@ describe Slaw::ActGenerator do
27
28
  b.doc.root.to_xml(encoding: 'UTF-8')
28
29
  end
29
30
 
31
+ before(:each) do
32
+ Slaw::Grammars::ZA::Act::Crossheading.counters.clear
33
+ Slaw::Grammars::ZA::Act::BlockElements.counters.clear
34
+ end
35
+
30
36
  #-------------------------------------------------------------------------------
31
37
  # schedules
32
38
 
@@ -71,7 +77,7 @@ EOS
71
77
  <mainBody>
72
78
  <hcontainer id="schedule" name="schedule">
73
79
  <heading>Schedule</heading>
74
- <paragraph id="schedule.paragraph-0">
80
+ <paragraph id="schedule.paragraph0">
75
81
  <content>
76
82
  <p>Subject to approval in terms of this By-Law, the erection:</p>
77
83
  </content>
@@ -180,7 +186,7 @@ EOS
180
186
  <hcontainer id="schedule3" name="schedule">
181
187
  <heading>Schedule 3</heading>
182
188
  <subheading>Another Title</subheading>
183
- <paragraph id="schedule3.paragraph-0">
189
+ <paragraph id="schedule3.paragraph0">
184
190
  <content>
185
191
  <p>Baz</p>
186
192
  <p>Boom</p>
@@ -238,7 +244,7 @@ EOS
238
244
  <hcontainer id="schedule1" name="schedule">
239
245
  <heading>First Schedule</heading>
240
246
  <subheading>Schedule Heading</subheading>
241
- <paragraph id="schedule1.paragraph-0">
247
+ <paragraph id="schedule1.paragraph0">
242
248
  <content>
243
249
  <p>Subject to approval in terms of this By-Law, the erection:</p>
244
250
  </content>
@@ -299,7 +305,7 @@ EOS
299
305
  <hcontainer id="schedule1" name="schedule">
300
306
  <heading>First Schedule</heading>
301
307
  <subheading>Schedule Heading</subheading>
302
- <paragraph id="schedule1.paragraph-0">
308
+ <paragraph id="schedule1.paragraph0">
303
309
  <content>
304
310
  <p>Subject to approval in terms of this By-Law, the erection:</p>
305
311
  </content>
@@ -358,7 +364,7 @@ EOS
358
364
  <mainBody>
359
365
  <hcontainer id="firstschedule" name="schedule">
360
366
  <heading>First Schedule</heading>
361
- <paragraph id="firstschedule.paragraph-0">
367
+ <paragraph id="firstschedule.paragraph0">
362
368
  <content>
363
369
  <p>Subject to approval in terms of this By-Law, the erection:</p>
364
370
  </content>
@@ -419,7 +425,7 @@ EOS
419
425
  <mainBody>
420
426
  <hcontainer id="schedule1" name="schedule">
421
427
  <heading>Schedule 1</heading>
422
- <paragraph id="schedule1.paragraph-0">
428
+ <paragraph id="schedule1.paragraph0">
423
429
  <content>
424
430
  <p>Other than as is set out hereinbelow, no signs other than locality bound signs, temporary signs including loose portable sign, estate agents signs, newspaper headline posters and posters (the erection of which must comply with the appropriate schedules pertinent thereto) shall be erected on Municipal owned land.</p>
425
431
  </content>
@@ -493,7 +499,7 @@ EOS
493
499
  <part id="part-I">
494
500
  <num>I</num>
495
501
  <heading>Form of authentication statement</heading>
496
- <paragraph id="part-I.paragraph-0">
502
+ <paragraph id="part-I.paragraph0">
497
503
  <content>
498
504
  <p>This printed impression has been carefully compared by me with the bill which was passed by Parliament and found by me to be a true copy of the bill.</p>
499
505
  </content>
@@ -502,7 +508,7 @@ EOS
502
508
  <part id="part-II">
503
509
  <num>II</num>
504
510
  <heading>Form of statement of the President’s assent.</heading>
505
- <paragraph id="part-II.paragraph-0">
511
+ <paragraph id="part-II.paragraph0">
506
512
  <content>
507
513
  <p>I signify my assent to the bill and a whole bunch of other stuff.</p>
508
514
  </content>
@@ -567,7 +573,7 @@ EOS
567
573
  <mainBody>
568
574
  <hcontainer id="schedule" name="schedule">
569
575
  <heading>Schedule</heading>
570
- <paragraph id="schedule.paragraph-0">
576
+ <paragraph id="schedule.paragraph0">
571
577
  <content>
572
578
  <p>Subject to approval in terms of this By-Law.</p>
573
579
  <p>Schedule another</p>
@@ -620,7 +626,7 @@ EOS
620
626
  <hcontainer id="firstschedule" name="schedule">
621
627
  <heading>First Schedule <remark status="editorial">[remark]</remark></heading>
622
628
  <subheading>Subheading <remark status="editorial">[another]</remark></subheading>
623
- <paragraph id="firstschedule.paragraph-0">
629
+ <paragraph id="firstschedule.paragraph0">
624
630
  <content>
625
631
  <p>Subject to approval in terms of this By-Law.</p>
626
632
  </content>