breakout_parser 0.0.2-x86-mingw32 → 0.0.3-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
data/spec/parser_spec.rb CHANGED
@@ -2,7 +2,11 @@ require 'breakout_parser'
2
2
 
3
3
  describe 'BreakoutParser' do
4
4
  def self.hex_string s
5
- s.each_byte.to_a.map{ |c| "%02x" % c }.join
5
+ ## sexier, but not runs on ruby 1.8.6 patchlevel 383 i386-mingw32:
6
+ #s.each_byte.to_a.map{ |c| "%02x" % c }.join
7
+ r = ''
8
+ s.each_byte{ |c| r << "%02x" % c }
9
+ r
6
10
  end
7
11
  def hex_string s; self.class.hex_string(s); end
8
12
 
@@ -43,16 +47,16 @@ describe 'BreakoutParser' do
43
47
  parse("\r\n\t \t \n \r \n \t \t\n\r aaa").should == "aaa"
44
48
  end
45
49
 
46
- it "converts two or more \\n to single empty line" do
50
+ it "converts each newline to <br />" do
47
51
  parse("aaa\n\nbbb").should == "aaa<br /><br />bbb"
48
52
  parse("aaa\n \nbbb").should == "aaa<br /><br />bbb"
49
- parse("aaa\n\n\nbbb").should == "aaa<br /><br />bbb"
50
- parse("aaa\n \n \nbbb").should == "aaa<br /><br />bbb"
51
- parse("aaa\r\n \r\n \r\nbbb").should == "aaa<br /><br />bbb"
52
- parse("aaa\n \n\n \nbbb").should == "aaa<br /><br />bbb"
53
- parse("aaa\n \n\n\n \nbbb").should == "aaa<br /><br />bbb"
54
- parse("aaa\n\n\n\n\n\n\nbbb").should == "aaa<br /><br />bbb"
55
- parse("aaa\r\n\r\n\r\nbbb").should == "aaa<br /><br />bbb"
53
+ parse("aaa\n\n\nbbb").should == "aaa<br /><br /><br />bbb"
54
+ parse("aaa\n \n \nbbb").should == "aaa<br /><br /><br />bbb"
55
+ parse("aaa\r\n \r\n \r\nbbb").should == "aaa<br /><br /><br />bbb"
56
+ parse("aaa\n \n\n \nbbb").should == "aaa<br /><br /><br /><br />bbb"
57
+ parse("aaa\n \n\n\n \nbbb").should == "aaa" + "<br />"*5 + "bbb"
58
+ parse("aaa\n\n\n\n\n\n\nbbb").should == "aaa" + "<br />"*7 + "bbb"
59
+ parse("aaa\r\n\r\n\r\nbbb").should == "aaa" + "<br />"*3 + "bbb"
56
60
  end
57
61
 
58
62
  ###############################################################################
@@ -354,68 +358,123 @@ describe 'BreakoutParser' do
354
358
 
355
359
  ###############################################################################
356
360
 
357
- describe "<pre><code>..</code></pre>" do
358
- it "works" do
359
- s = <<-EOF
360
- for ( n = 0; n < max_size && \
361
- (c = getc( yyin )) != EOF && c != '\\n'; ++n ) \
362
- buf[n] = (char) c; \
363
-
364
- EOF
365
-
366
- parse("<pre><code>#{s.strip}</code></pre>").should ==
367
- "<pre><code>#{h(s.strip)}</code></pre>"
368
-
369
- s = <<-EOF
370
- while ( 1 < 2 ) do
371
- puts "<b>12345\\t54321</b>"
372
- // *bold* comment
373
- // _italic_ comment
374
- end
375
- ---
376
- * aaa
377
- * bbb
378
- * ccc
379
-
380
- EOF
381
- parse("<pre><code>#{s.strip}</code></pre>").should ==
382
- "<pre><code>#{h(s.strip)}</code></pre>"
383
- end
384
- it "not parses *bold*" do
385
- s = "<pre><code> *bold*</code></pre>"
386
- parse(s).should == s
387
- end
388
- it "not parses _italic_" do
389
- s = "<pre><code> _italic_</code></pre>"
390
- parse(s).should == s
391
- end
392
- it "not parses UL lists" do
393
- s = "<pre><code>\n * l1\n * l2\n * l3</code></pre>"
394
- parse(s).should == s.sub("<code>\n","<code>")
395
- end
396
- it "not parses OL lists" do
397
- s = "<pre><code>\n # l1\n # l2\n # l3</code></pre>"
398
- parse(s).should == s.sub("<code>\n","<code>")
399
- end
400
- it "not parses H1..H5" do
401
- 1.upto(5) do |i|
402
- s = "<pre><code>\nh#{i}. zzzzzzz\n</code></pre>"
403
- parse(s).should == "<pre><code>h#{i}. zzzzzzz</code></pre>"
361
+ [
362
+ %w'<pre><code> </code></pre>',
363
+ %w'<pre> </pre>'
364
+ ].each do |ot,ct|
365
+ # ot - opening tag
366
+ # ct - closing tag
367
+
368
+ describe "#{ot}..#{ct}" do
369
+ it "works" do
370
+ s = <<-EOF
371
+ for ( n = 0; n < max_size && \
372
+ (c = getc( yyin )) != EOF && c != '\\n'; ++n ) \
373
+ buf[n] = (char) c; \
374
+
375
+ EOF
376
+
377
+ parse("#{ot}#{s.strip}#{ct}").should ==
378
+ "#{ot}#{h(s.strip)}#{ct}"
379
+
380
+ s = <<-EOF
381
+ while ( 1 < 2 ) do
382
+ puts "<b>12345\\t54321</b>"
383
+ // *bold* comment
384
+ // _italic_ comment
385
+ end
386
+ ---
387
+ * aaa
388
+ * bbb
389
+ * ccc
390
+
391
+ EOF
392
+ parse("#{ot}#{s.strip}#{ct}").should ==
393
+ "#{ot}#{h(s.strip)}#{ct}"
394
+ end
395
+ it "not parses *bold*" do
396
+ s = "#{ot} *bold*#{ct}"
397
+ parse(s).should == s
398
+ end
399
+ it "not parses _italic_" do
400
+ s = "#{ot} _italic_#{ct}"
401
+ parse(s).should == s
402
+ end
403
+ it "not parses UL lists" do
404
+ s = "#{ot}\n * l1\n * l2\n * l3#{ct}"
405
+ parse(s).should == s.sub(">\n",">")
406
+ end
407
+ it "not parses OL lists" do
408
+ s = "#{ot}\n # l1\n # l2\n # l3#{ct}"
409
+ parse(s).should == s.sub(">\n",">")
410
+ end
411
+ it "not parses H1..H5" do
412
+ 1.upto(5) do |i|
413
+ s = "#{ot}\nh#{i}. zzzzzzz\n#{ct}"
414
+ parse(s).should == "#{ot}h#{i}. zzzzzzz#{ct}"
415
+ end
416
+ end
417
+ it "not parses raw text links" do
418
+ s = "#{ot}xxx http://www.ru yyy#{ct}"
419
+ parse(s).should == s
420
+ s = "#{ot}http://www.ru#{ct}"
421
+ parse(s).should == s
422
+ end
423
+ it "keeps newlines" do
424
+ s = "#{ot}aaa\nbbb#{ct}"
425
+ parse(s).should == s
426
+ s = "#{ot}aaa\n\nbbb\nccc#{ct}"
427
+ parse(s).should == s
428
+ end
429
+
430
+ it "w/o closing tags" do
431
+ s = "#{ot}aaa"
432
+ parse(s).should match(%r"#{ot}aaa\n?#{ct}")
433
+ end
434
+
435
+ it "in middle of text" do
436
+ s = "xxx #{ot}yyyy#{ct} jjj"
437
+ parse(s).should == s
438
+ end
439
+
440
+ it "with 2 instances" do
441
+ s = "xxx #{ot}yyyy#{ct} <jjj> #{ot}asdkjaslkd#{ct} END"
442
+ parse(s).should == s.sub('<jjj>','&lt;jjj&gt;')
443
+ end
444
+
445
+ it "works with unicode" do
446
+ s = "привет #{ot} жжж #{ct} пока!"
447
+ parse(s).should match(%r|привет ?#{ot} жжж#{ct} ?пока!|)
448
+
449
+ s = 'абвгдеёжзийклмнопрстуфхцчшщьыъэюя'
450
+ parse(s).should == s
451
+
452
+ s = 'АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЬЫЪЭЮЯ'
453
+ parse(s).should == s
454
+
455
+ s = '☸☹☺☻☼☽☾☿'
456
+ parse(s).should == s
457
+ end
458
+
459
+ it "should escape lone closing tags" do
460
+ s = "#{ct}"
461
+ parse(s).should == h(s)
462
+ end
463
+
464
+ it "should skip newlines and spaces at end" do
465
+ s = "#{ot} aaa bbb ccc \n\n\n \t\n\n\n\r\n\r\n \t #{ct}"
466
+ parse(s).should == "#{ot} aaa bbb ccc#{ct}"
467
+ end
468
+
469
+ it "escapes html chars" do
470
+ HTML_ESCAPE.each do |k,v|
471
+ parse("#{ot}#{k}#{ct}").should == "#{ot}#{v}#{ct}"
472
+ end
404
473
  end
405
474
  end
406
- it "not parses raw text links" do
407
- s = "<pre><code>xxx http://www.ru yyy</code></pre>"
408
- parse(s).should == s
409
- s = "<pre><code>http://www.ru</code></pre>"
410
- parse(s).should == s
411
- end
412
- it "keeps newlines" do
413
- s = "<pre><code>aaa\nbbb</code></pre>"
414
- parse(s).should == s
415
- s = "<pre><code>aaa\n\nbbb\nccc</code></pre>"
416
- parse(s).should == s
417
- end
475
+ end
418
476
 
477
+ describe "<pre><code>..</code></pre>" do
419
478
  it "with no spaces between <pre> and <code>" do
420
479
  s = "<pre><code>aaa</code></pre>"
421
480
  parse(s).should == s
@@ -429,50 +488,64 @@ describe 'BreakoutParser' do
429
488
  s = "<pre> <code> aaa bbb </code> </pre>"
430
489
  parse(s).should == "<pre><code> aaa bbb</code></pre>"
431
490
  end
491
+ end
432
492
 
433
- it "w/o closing tags" do
434
- s = "<pre><code>aaa"
435
- parse(s).should match(%r"<pre><code>aaa\n?</code></pre>")
436
- end
493
+ ###############################################################################
437
494
 
438
- it "in middle of text" do
439
- s = "xxx <pre><code>yyyy</code></pre> jjj"
495
+ describe "<code>..</code>" do
496
+ it "keeps <code> tags" do
497
+ s = "<code>aaa</code>"
440
498
  parse(s).should == s
441
499
  end
442
-
443
- it "with 2 instances" do
444
- s = "xxx <pre><code>yyyy</code></pre> <jjj> <pre><code>asdkjaslkd</code></pre> END"
445
- parse(s).should == s.sub('<jjj>','&lt;jjj&gt;')
500
+ it "strips heading & tailing whitespace" do
501
+ s = "<code> \r\n \t \t\r aaa \r\n\t \t\r </code>"
502
+ parse(s).should == s.tr(" \r\n\t","")
446
503
  end
447
-
448
- it "works with unicode" do
449
- s = "привет <pre><code> жжж </code></pre> пока!"
450
- parse(s).should match(%r|привет ?<pre><code> жжж</code></pre> ?пока!|)
451
-
452
- s = 'абвгдеёжзийклмнопрстуфхцчшщьыъэюя'
504
+ it "not parses *bold*" do
505
+ s = "<code>aaa *bbb* ccc</code>"
453
506
  parse(s).should == s
454
-
455
- s = 'АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЬЫЪЭЮЯ'
507
+ end
508
+ it "not parses _italic_" do
509
+ s = "<code>aaa _bbb_ ccc</code>"
456
510
  parse(s).should == s
457
-
458
- s = '☸☹☺☻☼☽☾☿'
511
+ end
512
+ it "not parses headers" do
513
+ s = "<code>aaa\nh1. bbb\nccc</code>"
459
514
  parse(s).should == s
460
515
  end
461
-
462
- it "should escape lone closing tags" do
463
- s = "</code></pre>"
464
- parse(s).should == h(s)
516
+ it "not parses <pre>" do
517
+ s = "<code>aaa <pre>bbb</pre> ccc</code>"
518
+ parse(s).should == "<code>aaa &lt;pre&gt;bbb&lt;/pre&gt; ccc</code>"
465
519
  end
466
-
467
- it "should skip newlines and spaces at end" do
468
- s = "<pre><code> aaa bbb ccc \n\n\n \t\n\n\n\r\n\r\n \t </code></pre>"
469
- parse(s).should == "<pre><code> aaa bbb ccc</code></pre>"
520
+ it "closes unclosed <code>" do
521
+ s = "aaa <code>bbb"
522
+ parse(s).should == "#{s}</code>"
470
523
  end
471
-
472
- it "escapes html chars" do
473
- HTML_ESCAPE.each do |k,v|
474
- parse("<pre><code>#{k}</code></pre>").should == "<pre><code>#{v}</code></pre>"
475
- end
524
+ it "escapes '&'" do
525
+ s = "<code>aaa & bbb</code>"
526
+ parse(s).should == s.sub('&','&amp;')
527
+ end
528
+ it "not parses links" do
529
+ s = "<code>aaa #1 #2 #3 http://www.ru [[wiki:jjj]] [[url:http://www.ru]] bbb</code>"
530
+ parse(s).should == s
531
+ end
532
+ it "works two times" do
533
+ s = "<code>aaa & bbb</code> xxx <code>jjj&hhh</code>"
534
+ parse(s).should == s.gsub('&','&amp;')
535
+ s = "<code> aaa </code>xxx<code> jjj </code>"
536
+ parse(s).should == s.gsub(' ','')
537
+ end
538
+ it "keeps code bold" do
539
+ s = "*aaa <code>bbb</code> ccc*"
540
+ parse(s).should == "<strong>aaa <code>bbb</code> ccc</strong>"
541
+ s = "*<code>aaa</code>*"
542
+ parse(s).should == "<strong><code>aaa</code></strong>"
543
+ end
544
+ it "keeps code italic" do
545
+ s = "_aaa <code>bbb</code> ccc_"
546
+ parse(s).should == "<em>aaa <code>bbb</code> ccc</em>"
547
+ s = "_<code>aaa</code>_"
548
+ parse(s).should == "<em><code>aaa</code></em>"
476
549
  end
477
550
  end
478
551
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: breakout_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: x86-mingw32
6
6
  authors:
7
7
  - Andrey "Zed" Zaikin
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-19 00:00:00 +05:00
12
+ date: 2010-01-20 00:00:00 +05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency