File: text_spec.rb

package info (click to toggle)
ruby-reverse-markdown 3.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 440 kB
  • sloc: ruby: 1,452; makefile: 4
file content (68 lines) | stat: -rw-r--r-- 1,912 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
64
65
66
67
68
require 'spec_helper'

describe ReverseMarkdown::Converters::Text do

  let(:converter) { ReverseMarkdown::Converters::Text.new }

  it 'treats newline within text as a single whitespace' do
    input = node_for("<p>foo\nbar</p>")
    result = converter.convert(input)
    expect(result).to eq 'foo bar'
  end

  it 'handles windows-style \r\n correctly' do
    input = node_for("<p>foo \r\n\r\n bar</p>")
    result = converter.convert(input)
    expect(result).to eq 'foo bar'
  end

  it 'removes leading newlines' do
    input = node_for("<p>\n\nfoo bar</p>")
    result = converter.convert(input)
    expect(result).to eq 'foo bar'
  end

  it 'removes trailing newlines' do
    input = node_for("<p>foo bar\n\n</p>")
    result = converter.convert(input)
    expect(result).to eq 'foo bar'
  end

  it 'keeps nbsps' do
    input = node_for("<p>foo\u00A0bar \u00A0</p>")
    result = converter.convert(input)
    expect(result).to eq "foo&nbsp;bar &nbsp;"
  end

  it 'keeps escaped HTML-ish characters' do
    input = node_for("<p>&lt;foo&gt;</p>")
    result = converter.convert(input)
    expect(result).to eq '\<foo\>'
  end

  context 'within backticks' do
    it "preserves single underscores" do
      input = node_for("<p>`foo_bar`</p>")
      result = converter.convert(input)
      expect(result).to eq '`foo_bar`'
    end

    it "preserves multiple underscores" do
      input = node_for("<p>`foo_bar __example__`</p>")
      result = converter.convert(input)
      expect(result).to eq '`foo_bar __example__`'
    end

    it "preserves single asterisks" do
      input = node_for("<p>`def foo *args`</p>")
      result = converter.convert(input)
      expect(result).to eq '`def foo *args`'
    end

    it "preserves multiple asterisks" do
      input = node_for("<p>`def foo 2***3`</p>")
      result = converter.convert(input)
      expect(result).to eq '`def foo 2***3`'
    end
  end
end