|
30 | 30 |
|
31 | 31 | include_examples "doesn't break line numbers"
|
32 | 32 |
|
33 |
| - [ |
34 |
| - %w[added added note], |
35 |
| - %w[coming changed note], |
36 |
| - %w[deprecated deleted warning], |
37 |
| - ].each do |(name, revisionflag, tag)| |
38 |
| - it "invokes the #{name} block macro when #{name}[version] starts a line" do |
39 |
| - actual = convert <<~ASCIIDOC |
40 |
| - == Example |
41 |
| - #{name}[some_version] |
42 |
| - ASCIIDOC |
43 |
| - expected = <<~DOCBOOK |
44 |
| - <chapter id="_example"> |
45 |
| - <title>Example</title> |
46 |
| - <#{tag} revisionflag="#{revisionflag}" revision="some_version"> |
47 |
| - <simpara></simpara> |
48 |
| - </#{tag}> |
49 |
| - </chapter> |
50 |
| - DOCBOOK |
51 |
| - expect(actual).to eq(expected.strip) |
52 |
| - end |
53 |
| - |
54 |
| - it "invokes the #{name} inline macro when #{name}[version] is otherwise on the line" do |
55 |
| - actual = convert <<~ASCIIDOC |
56 |
| - == Example |
57 |
| - words #{name}[some_version] |
58 |
| - ASCIIDOC |
59 |
| - expected = <<~DOCBOOK |
60 |
| - <chapter id="_example"> |
61 |
| - <title>Example</title> |
62 |
| - <simpara>words <phrase revisionflag="#{revisionflag}" revision="some_version"/> |
63 |
| - </simpara> |
64 |
| - </chapter> |
65 |
| - DOCBOOK |
66 |
| - expect(actual).to eq(expected.strip) |
67 |
| - end |
68 |
| - |
69 |
| - it "doesn't mind skipped #{name} block macros" do |
70 |
| - actual = convert <<~ASCIIDOC |
71 |
| - == Example |
| 33 | + context 'change admonitions' do |
| 34 | + shared_examples 'change admonition' do |
| 35 | + include_context 'convert without logs' |
| 36 | + |
| 37 | + shared_examples 'invokes the block macro' do |
| 38 | + let(:expected) do |
| 39 | + <<~DOCBOOK |
| 40 | + <#{tag} revisionflag="#{revisionflag}" revision="some_version"> |
| 41 | + <simpara></simpara> |
| 42 | + </#{tag}> |
| 43 | + DOCBOOK |
| 44 | + end |
| 45 | + it 'invokes the block macro' do |
| 46 | + expect(converted).to include(expected) |
| 47 | + end |
| 48 | + end |
| 49 | + context 'when the admonition is alone on a line' do |
| 50 | + let(:input) { "#{name}[some_version]" } |
| 51 | + include_examples 'invokes the block macro' |
| 52 | + end |
| 53 | + context 'when the admonition has spaces before it' do |
| 54 | + let(:input) { " #{name}[some_version]" } |
| 55 | + include_examples 'invokes the block macro' |
| 56 | + end |
| 57 | + context 'when the admonition has spaces after it' do |
| 58 | + let(:input) { "#{name}[some_version] " } |
| 59 | + include_examples 'invokes the block macro' |
| 60 | + end |
| 61 | + context 'when the admonition has a `]` in it' do |
| 62 | + let(:input) { "#{name}[some_version, link:link.html[Title]]" } |
| 63 | + include_examples 'invokes the block macro' |
| 64 | + let(:expected) do |
| 65 | + <<~DOCBOOK |
| 66 | + <#{tag} revisionflag="#{revisionflag}" revision="some_version"> |
| 67 | + <simpara><ulink url="link.html">Title</ulink></simpara> |
| 68 | + </#{tag}> |
| 69 | + DOCBOOK |
| 70 | + end |
| 71 | + end |
72 | 72 |
|
73 |
| - ifeval::["true" == "false"] |
74 |
| - #{name}[some_version] |
75 |
| - #endif::[] |
76 |
| - ASCIIDOC |
77 |
| - expected = <<~DOCBOOK |
78 |
| - <chapter id="_example"> |
79 |
| - <title>Example</title> |
| 73 | + shared_examples 'invokes the inline macro' do |
| 74 | + it 'invokes the inline macro' do |
| 75 | + expect(converted).to include( |
| 76 | + %(<phrase revisionflag="#{revisionflag}" revision="some_version"/>) |
| 77 | + ) |
| 78 | + end |
| 79 | + end |
| 80 | + context "when the admonition is surrounded by other text" do |
| 81 | + let(:input) { "words #{name}[some_version] words" } |
| 82 | + include_examples 'invokes the inline macro' |
| 83 | + end |
| 84 | + context "when the admonition has text before it" do |
| 85 | + let(:input) { "words #{name}[some_version]" } |
| 86 | + include_examples 'invokes the inline macro' |
| 87 | + end |
| 88 | + context "when the admonition has text after it" do |
| 89 | + let(:input) { "#{name}[some_version] words" } |
| 90 | + include_examples 'invokes the inline macro' |
| 91 | + end |
80 | 92 |
|
81 |
| - </chapter> |
82 |
| - DOCBOOK |
83 |
| - expect(actual).to eq(expected.strip) |
| 93 | + context 'when the admonition is skipped' do |
| 94 | + let(:input) do |
| 95 | + <<~ASCIIDOC |
| 96 | + words before skip |
| 97 | + ifeval::["true" == "false"] |
| 98 | + #{name}[some_version] |
| 99 | + endif::[] |
| 100 | + words after skip |
| 101 | + ASCIIDOC |
| 102 | + end |
| 103 | + it 'skips the admonition' do |
| 104 | + expect(converted).not_to include('revisionflag') |
| 105 | + end |
| 106 | + it 'properly converts the rest of the text' do |
| 107 | + expect(converted).to include('words before skip') |
| 108 | + expect(converted).to include('words after skip') |
| 109 | + end |
| 110 | + end |
| 111 | + end |
| 112 | + context 'for added' do |
| 113 | + include_context 'change admonition' |
| 114 | + let(:name) { 'added' } |
| 115 | + let(:revisionflag) { 'added' } |
| 116 | + let(:tag) { 'note' } |
| 117 | + end |
| 118 | + context 'for coming' do |
| 119 | + include_context 'change admonition' |
| 120 | + let(:name) { 'coming' } |
| 121 | + let(:revisionflag) { 'changed' } |
| 122 | + let(:tag) { 'note' } |
| 123 | + end |
| 124 | + context 'for added' do |
| 125 | + include_context 'change admonition' |
| 126 | + let(:name) { 'deprecated' } |
| 127 | + let(:revisionflag) { 'deleted' } |
| 128 | + let(:tag) { 'warning' } |
84 | 129 | end
|
85 | 130 | end
|
86 | 131 |
|
|
0 commit comments