File: regexp_helper_spec.rb

package info (click to toggle)
ruby-org 0.9.1-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,476 kB
  • ctags: 213
  • sloc: ruby: 2,748; lisp: 50; makefile: 4
file content (63 lines) | stat: -rw-r--r-- 1,882 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
require 'spec_helper'

describe Orgmode::RegexpHelper do
  it "should recognize simple markup" do
    e = Orgmode::RegexpHelper.new
    total = 0
    e.match_all("/italic/") do |border, string|
      border.should eql("/")
      string.should eql("italic")
      total += 1
    end
    total.should eql(1)

    total = 0
    borders = %w[* / ~]
    strings = %w[bold italic verbatim]
    e.match_all("This string contains *bold*, /italic/, and ~verbatim~ text.")\
    do |border, str|
      border.should eql(borders[total])
      str.should eql(strings[total])
      total += 1
    end
    total.should eql(3)
  end

  it "should not get confused by links" do
    e = Orgmode::RegexpHelper.new
    total = 0
    # Make sure the slashes in these links aren't treated as italics
    e.match_all("[[http://www.bing.com/twitter]]") do |border, str|
      total += 1
    end
    total.should eql(0)
  end

  it "should correctly perform substitutions" do
    e = Orgmode::RegexpHelper.new
    map = {
      "*" => "strong",
      "/" => "i",
      "~" => "code"
    }
    n = e.rewrite_emphasis("This string contains *bold*, /italic/, and ~verbatim~ text.") do |border, str|
      "<#{map[border]}>#{str}</#{map[border]}>"
    end
    n = e.restore_code_snippets n

    n.should eql("This string contains <strong>bold</strong>, <i>italic</i>, and <code>verbatim</code> text.")
  end

  it "should allow link rewriting" do
    e = Orgmode::RegexpHelper.new
    str = e.rewrite_links("[[http://www.bing.com]]") do |link,text|
      text ||= link
      "\"#{text}\":#{link}"
    end
    str.should eql("\"http://www.bing.com\":http://www.bing.com")
    str = e.rewrite_links("<http://www.google.com>") do |link|
      "\"#{link}\":#{link}"
    end
    str.should eql("\"http://www.google.com\":http://www.google.com")
  end
end                             # describe Orgmode::RegexpHelper