asciidoctor 1.5.3 → 1.5.4
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of asciidoctor might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.adoc +67 -5
- data/CONTRIBUTING.adoc +171 -0
- data/LICENSE.adoc +1 -1
- data/README.adoc +62 -30
- data/bin/asciidoctor +3 -3
- data/bin/asciidoctor-safe +8 -5
- data/lib/asciidoctor.rb +10 -21
- data/lib/asciidoctor/abstract_block.rb +29 -11
- data/lib/asciidoctor/abstract_node.rb +11 -6
- data/lib/asciidoctor/callouts.rb +6 -10
- data/lib/asciidoctor/cli/options.rb +2 -2
- data/lib/asciidoctor/converter.rb +1 -1
- data/lib/asciidoctor/converter/docbook5.rb +46 -23
- data/lib/asciidoctor/converter/factory.rb +3 -3
- data/lib/asciidoctor/converter/html5.rb +27 -24
- data/lib/asciidoctor/converter/manpage.rb +72 -61
- data/lib/asciidoctor/converter/template.rb +5 -9
- data/lib/asciidoctor/document.rb +18 -18
- data/lib/asciidoctor/extensions.rb +5 -5
- data/lib/asciidoctor/helpers.rb +2 -2
- data/lib/asciidoctor/inline.rb +2 -2
- data/lib/asciidoctor/parser.rb +59 -59
- data/lib/asciidoctor/path_resolver.rb +23 -15
- data/lib/asciidoctor/reader.rb +34 -29
- data/lib/asciidoctor/section.rb +6 -8
- data/lib/asciidoctor/substitutors.rb +2 -2
- data/lib/asciidoctor/table.rb +46 -23
- data/lib/asciidoctor/version.rb +1 -1
- data/man/asciidoctor.1 +11 -11
- data/man/asciidoctor.adoc +2 -2
- data/test/attributes_test.rb +21 -37
- data/test/blocks_test.rb +41 -14
- data/test/converter_test.rb +4 -4
- data/test/document_test.rb +61 -8
- data/test/extensions_test.rb +2 -2
- data/test/invoker_test.rb +3 -3
- data/test/links_test.rb +13 -3
- data/test/lists_test.rb +114 -114
- data/test/manpage_test.rb +203 -0
- data/test/paragraphs_test.rb +3 -3
- data/test/parser_test.rb +4 -4
- data/test/preamble_test.rb +1 -1
- data/test/reader_test.rb +149 -109
- data/test/sections_test.rb +137 -27
- data/test/substitutions_test.rb +24 -16
- data/test/tables_test.rb +183 -31
- data/test/test_helper.rb +10 -22
- metadata +9 -6
- data/compat/asciidoc.conf +0 -395
- data/compat/font-awesome-3-compat.css +0 -397
@@ -0,0 +1,203 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
unless defined? ASCIIDOCTOR_PROJECT_DIR
|
3
|
+
$: << File.dirname(__FILE__); $:.uniq!
|
4
|
+
require 'test_helper'
|
5
|
+
end
|
6
|
+
|
7
|
+
SAMPLE_MANPAGE_HEADER = <<-EOS.chomp
|
8
|
+
= command (1)
|
9
|
+
Author Name
|
10
|
+
:doctype: manpage
|
11
|
+
:man manual: Command Manual
|
12
|
+
:man source: Command 1.2.3
|
13
|
+
|
14
|
+
== NAME
|
15
|
+
|
16
|
+
command - does stuff
|
17
|
+
|
18
|
+
== SYNOPSIS
|
19
|
+
|
20
|
+
*command* [_OPTION_]... _FILE_...
|
21
|
+
|
22
|
+
== DESCRIPTION
|
23
|
+
EOS
|
24
|
+
|
25
|
+
context 'Manpage' do
|
26
|
+
context 'Configuration' do
|
27
|
+
test 'should define default linkstyle' do
|
28
|
+
input = SAMPLE_MANPAGE_HEADER
|
29
|
+
output = Asciidoctor.convert input, :backend => :manpage, :header_footer => true
|
30
|
+
assert_match(/^\.LINKSTYLE blue R < >$/, output)
|
31
|
+
end
|
32
|
+
|
33
|
+
test 'should use linkstyle defined by man-linkstyle attribute' do
|
34
|
+
input = SAMPLE_MANPAGE_HEADER
|
35
|
+
output = Asciidoctor.convert input, :backend => :manpage, :header_footer => true,
|
36
|
+
:attributes => { 'man-linkstyle' => 'cyan B \[fo] \[fc]' }
|
37
|
+
assert_match(/^\.LINKSTYLE cyan B \\\[fo\] \\\[fc\]$/, output)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'Manify' do
|
42
|
+
test 'should escape lone period' do
|
43
|
+
input = %(#{SAMPLE_MANPAGE_HEADER}
|
44
|
+
|
45
|
+
.)
|
46
|
+
output = Asciidoctor.convert input, :backend => :manpage
|
47
|
+
assert_equal '\&.', output.lines.entries.last.chomp
|
48
|
+
end
|
49
|
+
|
50
|
+
test 'should escape raw macro' do
|
51
|
+
input = %(#{SAMPLE_MANPAGE_HEADER}
|
52
|
+
|
53
|
+
AAA this line of text should be show
|
54
|
+
.if 1 .nx
|
55
|
+
BBB this line and the one above it should be visible)
|
56
|
+
|
57
|
+
output = Asciidoctor.convert input, :backend => :manpage
|
58
|
+
assert_equal '\&.if 1 .nx', output.lines.entries[-2].chomp
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'Backslash' do
|
63
|
+
test 'should not escape spaces for empty manual or source fields' do
|
64
|
+
input = SAMPLE_MANPAGE_HEADER.lines.select {|l| !l.start_with?(':man ') }
|
65
|
+
output = Asciidoctor.convert input, :backend => :manpage, :header_footer => true
|
66
|
+
assert_match ' Manual: \ \&', output
|
67
|
+
assert_match ' Source: \ \&', output
|
68
|
+
assert_match(/^\.TH "COMMAND" .* "\\ \\&" "\\ \\&"$/, output)
|
69
|
+
end
|
70
|
+
|
71
|
+
test 'should preserve backslashes in escape sequences' do
|
72
|
+
input = %(#{SAMPLE_MANPAGE_HEADER}
|
73
|
+
|
74
|
+
"`hello`" '`goodbye`' *strong* _weak_ `even`)
|
75
|
+
output = Asciidoctor.convert input, :backend => :manpage
|
76
|
+
assert_equal '\(lqhello\(rq \(oqgoodbye\(cq \fBstrong\fP \fIweak\fP \f[CR]even\fP', output.lines.entries.last.chomp
|
77
|
+
end
|
78
|
+
|
79
|
+
test 'should escape backslashes in content' do
|
80
|
+
input = %(#{SAMPLE_MANPAGE_HEADER}
|
81
|
+
|
82
|
+
\\.foo \\ bar\\
|
83
|
+
baz)
|
84
|
+
output = Asciidoctor.convert input, :backend => :manpage
|
85
|
+
assert_equal '\(rs.foo \(rs bar\(rs', output.lines.entries[-2].chomp
|
86
|
+
end
|
87
|
+
|
88
|
+
test 'should escape literal escape sequence' do
|
89
|
+
input = %(#{SAMPLE_MANPAGE_HEADER}
|
90
|
+
|
91
|
+
\\fB makes text bold)
|
92
|
+
output = Asciidoctor.convert input, :backend => :manpage
|
93
|
+
assert_match '\(rsfB makes text bold', output
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
context 'URL macro' do
|
98
|
+
test 'should not leave blank line before URL macro' do
|
99
|
+
input = %(#{SAMPLE_MANPAGE_HEADER}
|
100
|
+
First paragraph.
|
101
|
+
|
102
|
+
http://asciidoc.org[AsciiDoc])
|
103
|
+
output = Asciidoctor.convert input, :backend => :manpage
|
104
|
+
assert_equal '.sp
|
105
|
+
First paragraph.
|
106
|
+
.sp
|
107
|
+
.URL "http://asciidoc.org" "AsciiDoc" ""', output.lines.entries[-4..-1].join
|
108
|
+
end
|
109
|
+
|
110
|
+
test 'should not swallow content following URL' do
|
111
|
+
input = %(#{SAMPLE_MANPAGE_HEADER}
|
112
|
+
|
113
|
+
http://asciidoc.org[AsciiDoc] can be used to create man pages.)
|
114
|
+
output = Asciidoctor.convert input, :backend => :manpage
|
115
|
+
assert_equal '.URL "http://asciidoc.org" "AsciiDoc" " "
|
116
|
+
can be used to create man pages.', output.lines.entries[-2..-1].join
|
117
|
+
end
|
118
|
+
|
119
|
+
test 'should pass adjacent character as final argument of URL macro' do
|
120
|
+
input = %(#{SAMPLE_MANPAGE_HEADER}
|
121
|
+
|
122
|
+
This is http://asciidoc.org[AsciiDoc].)
|
123
|
+
output = Asciidoctor.convert input, :backend => :manpage
|
124
|
+
assert_equal 'This is \c
|
125
|
+
.URL "http://asciidoc.org" "AsciiDoc" "."', output.lines.entries[-2..-1].join
|
126
|
+
end
|
127
|
+
|
128
|
+
test 'should pass adjacent character as final argument of URL macro and move trailing content to next line' do
|
129
|
+
input = %(#{SAMPLE_MANPAGE_HEADER}
|
130
|
+
|
131
|
+
This is http://asciidoc.org[AsciiDoc], which can be used to write content.)
|
132
|
+
output = Asciidoctor.convert input, :backend => :manpage
|
133
|
+
assert_equal 'This is \c
|
134
|
+
.URL "http://asciidoc.org" "AsciiDoc" ","
|
135
|
+
which can be used to write content.', output.lines.entries[-3..-1].join
|
136
|
+
end
|
137
|
+
|
138
|
+
test 'should not leave blank lines between URLs on contiguous lines of input' do
|
139
|
+
input = %(#{SAMPLE_MANPAGE_HEADER}
|
140
|
+
|
141
|
+
The corresponding implementations are
|
142
|
+
http://clisp.sf.net[CLISP],
|
143
|
+
http://ccl.clozure.com[Clozure CL],
|
144
|
+
http://cmucl.org[CMUCL],
|
145
|
+
http://ecls.sf.net[ECL],
|
146
|
+
and http://sbcl.sf.net[SBCL].)
|
147
|
+
output = Asciidoctor.convert input, :backend => :manpage
|
148
|
+
assert_equal '.sp
|
149
|
+
The corresponding implementations are
|
150
|
+
.URL "http://clisp.sf.net" "CLISP" ","
|
151
|
+
.URL "http://ccl.clozure.com" "Clozure CL" ","
|
152
|
+
.URL "http://cmucl.org" "CMUCL" ","
|
153
|
+
.URL "http://ecls.sf.net" "ECL" ","
|
154
|
+
and \c
|
155
|
+
.URL "http://sbcl.sf.net" "SBCL" "."', output.lines.entries[-8..-1].join
|
156
|
+
end
|
157
|
+
|
158
|
+
test 'should not leave blank lines between URLs on same line of input' do
|
159
|
+
input = %(#{SAMPLE_MANPAGE_HEADER}
|
160
|
+
|
161
|
+
The corresponding implementations are http://clisp.sf.net[CLISP], http://ccl.clozure.com[Clozure CL], http://cmucl.org[CMUCL], http://ecls.sf.net[ECL], and http://sbcl.sf.net[SBCL].)
|
162
|
+
output = Asciidoctor.convert input, :backend => :manpage
|
163
|
+
assert_equal '.sp
|
164
|
+
The corresponding implementations are \c
|
165
|
+
.URL "http://clisp.sf.net" "CLISP" ","
|
166
|
+
.URL "http://ccl.clozure.com" "Clozure CL" ","
|
167
|
+
.URL "http://cmucl.org" "CMUCL" ","
|
168
|
+
.URL "http://ecls.sf.net" "ECL" ","
|
169
|
+
and
|
170
|
+
.URL "http://sbcl.sf.net" "SBCL" "."', output.lines.entries[-8..-1].join
|
171
|
+
end
|
172
|
+
|
173
|
+
test 'should not insert space between link and non-whitespace characters surrounding it' do
|
174
|
+
input = %(#{SAMPLE_MANPAGE_HEADER}
|
175
|
+
|
176
|
+
Please search |link:http://discuss.asciidoctor.org[the forums]| before asking.)
|
177
|
+
output = Asciidoctor.convert input, :backend => :manpage
|
178
|
+
assert_equal '.sp
|
179
|
+
Please search |\c
|
180
|
+
.URL "http://discuss.asciidoctor.org" "the forums" "|"
|
181
|
+
before asking.', output.lines.entries[-4..-1].join
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
context 'Callout List' do
|
186
|
+
test 'should generate callout list using proper formatting commands' do
|
187
|
+
input = %(#{SAMPLE_MANPAGE_HEADER}
|
188
|
+
|
189
|
+
----
|
190
|
+
$ gem install asciidoctor # <1>
|
191
|
+
----
|
192
|
+
<1> Installs the asciidoctor gem from RubyGems.org)
|
193
|
+
output = Asciidoctor.convert input, :backend => :manpage
|
194
|
+
assert output.end_with? '.TS
|
195
|
+
tab(:);
|
196
|
+
r lw(\n(.lu*75u/100u).
|
197
|
+
\fB(1)\fP\h\'-2n\':T{
|
198
|
+
Installs the asciidoctor gem from RubyGems.org
|
199
|
+
T}
|
200
|
+
.TE'
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
data/test/paragraphs_test.rb
CHANGED
@@ -26,7 +26,7 @@ Paragraph.
|
|
26
26
|
Winning.
|
27
27
|
EOS
|
28
28
|
output = render_embedded_string input
|
29
|
-
|
29
|
+
|
30
30
|
assert_css 'p', output, 2
|
31
31
|
assert_xpath '(//p)[1]/preceding-sibling::*[@class = "title"]', output, 1
|
32
32
|
assert_xpath '(//p)[1]/preceding-sibling::*[@class = "title"][text() = "Titled"]', output, 1
|
@@ -60,7 +60,7 @@ paragraph
|
|
60
60
|
. wrapped line
|
61
61
|
EOS
|
62
62
|
|
63
|
-
output = render_embedded_string input
|
63
|
+
output = render_embedded_string input
|
64
64
|
assert_css 'p', output, 1
|
65
65
|
assert_xpath %(//p[text()="paragraph\n. wrapped line"]), output, 1
|
66
66
|
end
|
@@ -71,7 +71,7 @@ paragraph
|
|
71
71
|
.wrapped line
|
72
72
|
EOS
|
73
73
|
|
74
|
-
output = render_embedded_string input
|
74
|
+
output = render_embedded_string input
|
75
75
|
assert_css 'p', output, 1
|
76
76
|
assert_xpath %(//p[text()="paragraph\n.wrapped line"]), output, 1
|
77
77
|
end
|
data/test/parser_test.rb
CHANGED
@@ -118,7 +118,7 @@ context "Parser" do
|
|
118
118
|
line = 'height=100,caption="",link="images/octocat.png"'
|
119
119
|
expected = {'height' => '100', 'caption' => '', 'link' => 'images/octocat.png'}
|
120
120
|
Asciidoctor::AttributeList.new(line).parse_into(attributes)
|
121
|
-
assert_equal expected, attributes
|
121
|
+
assert_equal expected, attributes
|
122
122
|
end
|
123
123
|
|
124
124
|
test "collect named attribute single-quoted" do
|
@@ -134,7 +134,7 @@ context "Parser" do
|
|
134
134
|
line = "height=100,caption='',link='images/octocat.png'"
|
135
135
|
expected = {'height' => '100', 'caption' => '', 'link' => 'images/octocat.png'}
|
136
136
|
Asciidoctor::AttributeList.new(line).parse_into(attributes)
|
137
|
-
assert_equal expected, attributes
|
137
|
+
assert_equal expected, attributes
|
138
138
|
end
|
139
139
|
|
140
140
|
test "collect named attributes unquoted" do
|
@@ -688,9 +688,9 @@ devtmpfs 3.9G 0 3.9G 0% /dev
|
|
688
688
|
test 'preserve block indent if indent is -1' do
|
689
689
|
input = <<-EOS
|
690
690
|
def names
|
691
|
-
|
691
|
+
|
692
692
|
@name.split ' '
|
693
|
-
|
693
|
+
|
694
694
|
end
|
695
695
|
EOS
|
696
696
|
|
data/test/preamble_test.rb
CHANGED
@@ -144,7 +144,7 @@ The axe came swinging.
|
|
144
144
|
EOS
|
145
145
|
|
146
146
|
d = document_from_string(input)
|
147
|
-
assert_equal 'book', d.doctype
|
147
|
+
assert_equal 'book', d.doctype
|
148
148
|
output = d.render
|
149
149
|
assert_xpath '//h1', output, 3
|
150
150
|
assert_xpath %{//*[@id="preamble"]//p[text() = "Back then#{expand_entity 8230}#{expand_entity 8203}"]}, output, 1
|
data/test/reader_test.rb
CHANGED
@@ -223,7 +223,7 @@ third line
|
|
223
223
|
test 'source_lines should return copy of original data Array' do
|
224
224
|
reader = Asciidoctor::Reader.new SAMPLE_DATA
|
225
225
|
reader.read_lines
|
226
|
-
assert_equal SAMPLE_DATA, reader.source_lines
|
226
|
+
assert_equal SAMPLE_DATA, reader.source_lines
|
227
227
|
end
|
228
228
|
|
229
229
|
test 'source should return original data Array joined as String' do
|
@@ -494,12 +494,12 @@ include::include-file.asciidoc[]
|
|
494
494
|
reader = doc.reader
|
495
495
|
assert_equal 'link:include-file.asciidoc[]', reader.read_line
|
496
496
|
end
|
497
|
-
|
497
|
+
|
498
498
|
test 'include directive is enabled when safe mode is less than SECURE' do
|
499
499
|
input = <<-EOS
|
500
500
|
include::fixtures/include-file.asciidoc[]
|
501
501
|
EOS
|
502
|
-
|
502
|
+
|
503
503
|
doc = document_from_string input, :safe => :safe, :header_footer => false, :base_dir => DIRNAME
|
504
504
|
output = doc.render
|
505
505
|
assert_match(/included content/, output)
|
@@ -509,7 +509,7 @@ include::fixtures/include-file.asciidoc[]
|
|
509
509
|
input = <<-EOS
|
510
510
|
include::fixtures/include file.asciidoc[]
|
511
511
|
EOS
|
512
|
-
|
512
|
+
|
513
513
|
include_file = File.join DIRNAME, 'fixtures', 'include-file.asciidoc'
|
514
514
|
include_file_with_sp = File.join DIRNAME, 'fixtures', 'include file.asciidoc'
|
515
515
|
begin
|
@@ -526,7 +526,7 @@ include::fixtures/include file.asciidoc[]
|
|
526
526
|
input = <<-EOS
|
527
527
|
include::fixtures/include{sp}file.asciidoc[]
|
528
528
|
EOS
|
529
|
-
|
529
|
+
|
530
530
|
include_file = File.join DIRNAME, 'fixtures', 'include-file.asciidoc'
|
531
531
|
include_file_with_sp = File.join DIRNAME, 'fixtures', 'include file.asciidoc'
|
532
532
|
begin
|
@@ -599,21 +599,45 @@ include::fixtures/parent-include.adoc[]
|
|
599
599
|
assert_equal fixtures_dir, reader.dir
|
600
600
|
assert_equal 'fixtures/parent-include.adoc', reader.path
|
601
601
|
end
|
602
|
-
|
603
|
-
test 'missing file referenced by include directive
|
602
|
+
|
603
|
+
test 'missing file referenced by include directive is replaced by warning' do
|
604
604
|
input = <<-EOS
|
605
605
|
include::fixtures/no-such-file.adoc[]
|
606
|
+
|
607
|
+
trailing content
|
606
608
|
EOS
|
607
|
-
|
609
|
+
|
608
610
|
begin
|
609
611
|
doc = document_from_string input, :safe => :safe, :base_dir => DIRNAME
|
610
|
-
assert_equal
|
612
|
+
assert_equal 2, doc.blocks.size
|
611
613
|
assert_equal ['Unresolved directive in <stdin> - include::fixtures/no-such-file.adoc[]'], doc.blocks[0].lines
|
614
|
+
assert_equal ['trailing content'], doc.blocks[1].lines
|
612
615
|
rescue
|
613
616
|
flunk 'include directive should not raise exception on missing file'
|
614
617
|
end
|
615
618
|
end
|
616
619
|
|
620
|
+
test 'unreadable file referenced by include directive is replaced by warning' do
|
621
|
+
include_file = File.join DIRNAME, 'fixtures', 'chapter-a.adoc'
|
622
|
+
FileUtils.chmod 0000, include_file
|
623
|
+
input = <<-EOS
|
624
|
+
include::fixtures/chapter-a.adoc[]
|
625
|
+
|
626
|
+
trailing content
|
627
|
+
EOS
|
628
|
+
|
629
|
+
begin
|
630
|
+
doc = document_from_string input, :safe => :safe, :base_dir => DIRNAME
|
631
|
+
assert_equal 2, doc.blocks.size
|
632
|
+
assert_equal ['Unresolved directive in <stdin> - include::fixtures/chapter-a.adoc[]'], doc.blocks[0].lines
|
633
|
+
assert_equal ['trailing content'], doc.blocks[1].lines
|
634
|
+
rescue
|
635
|
+
flunk 'include directive should not raise exception on missing file'
|
636
|
+
ensure
|
637
|
+
FileUtils.chmod 0644, include_file
|
638
|
+
end
|
639
|
+
end unless windows?
|
640
|
+
|
617
641
|
# IMPORTANT this test needs to be run on Windows to verify proper behavior in Windows
|
618
642
|
test 'can resolve include directive with absolute path' do
|
619
643
|
include_path = ::File.join DIRNAME, 'fixtures', 'chapter-a.adoc'
|
@@ -626,7 +650,7 @@ include::#{include_path}[]
|
|
626
650
|
result = document_from_string input, :safe => :unsafe, :base_dir => ::Dir.tmpdir
|
627
651
|
assert_equal 'Chapter A', result.doctitle
|
628
652
|
end
|
629
|
-
|
653
|
+
|
630
654
|
test 'include directive can retrieve data from uri' do
|
631
655
|
#url = 'http://echo.jsontest.com/name/asciidoctor'
|
632
656
|
url = %(http://#{resolve_localhost}:9876/name/asciidoctor)
|
@@ -643,7 +667,7 @@ include::#{url}[]
|
|
643
667
|
refute_nil output
|
644
668
|
assert_match(expect, output)
|
645
669
|
end
|
646
|
-
|
670
|
+
|
647
671
|
test 'inaccessible uri referenced by include directive does not crash processor' do
|
648
672
|
url = %(http://#{resolve_localhost}:9876/no_such_file)
|
649
673
|
input = <<-EOS
|
@@ -662,12 +686,12 @@ include::#{url}[]
|
|
662
686
|
refute_nil output
|
663
687
|
assert_match(/Unresolved directive/, output)
|
664
688
|
end
|
665
|
-
|
689
|
+
|
666
690
|
test 'include directive supports line selection' do
|
667
691
|
input = <<-EOS
|
668
692
|
include::fixtures/include-file.asciidoc[lines=1;3..4;6..-1]
|
669
693
|
EOS
|
670
|
-
|
694
|
+
|
671
695
|
output = render_string input, :safe => :safe, :header_footer => false, :base_dir => DIRNAME
|
672
696
|
assert_match(/first line/, output)
|
673
697
|
refute_match(/second line/, output)
|
@@ -679,12 +703,12 @@ include::fixtures/include-file.asciidoc[lines=1;3..4;6..-1]
|
|
679
703
|
assert_match(/eighth line/, output)
|
680
704
|
assert_match(/last line of included content/, output)
|
681
705
|
end
|
682
|
-
|
706
|
+
|
683
707
|
test 'include directive supports line selection using quoted attribute value' do
|
684
708
|
input = <<-EOS
|
685
709
|
include::fixtures/include-file.asciidoc[lines="1, 3..4 , 6 .. -1"]
|
686
710
|
EOS
|
687
|
-
|
711
|
+
|
688
712
|
output = render_string input, :safe => :safe, :header_footer => false, :base_dir => DIRNAME
|
689
713
|
assert_match(/first line/, output)
|
690
714
|
refute_match(/second line/, output)
|
@@ -696,24 +720,24 @@ include::fixtures/include-file.asciidoc[lines="1, 3..4 , 6 .. -1"]
|
|
696
720
|
assert_match(/eighth line/, output)
|
697
721
|
assert_match(/last line of included content/, output)
|
698
722
|
end
|
699
|
-
|
723
|
+
|
700
724
|
test 'include directive supports tagged selection' do
|
701
725
|
input = <<-EOS
|
702
726
|
include::fixtures/include-file.asciidoc[tag=snippetA]
|
703
727
|
EOS
|
704
|
-
|
728
|
+
|
705
729
|
output = render_string input, :safe => :safe, :header_footer => false, :base_dir => DIRNAME
|
706
730
|
assert_match(/snippetA content/, output)
|
707
731
|
refute_match(/snippetB content/, output)
|
708
732
|
refute_match(/non-tagged content/, output)
|
709
733
|
refute_match(/included content/, output)
|
710
734
|
end
|
711
|
-
|
735
|
+
|
712
736
|
test 'include directive supports multiple tagged selection' do
|
713
737
|
input = <<-EOS
|
714
738
|
include::fixtures/include-file.asciidoc[tags=snippetA;snippetB]
|
715
739
|
EOS
|
716
|
-
|
740
|
+
|
717
741
|
output = render_string input, :safe => :safe, :header_footer => false, :base_dir => DIRNAME
|
718
742
|
assert_match(/snippetA content/, output)
|
719
743
|
assert_match(/snippetB content/, output)
|
@@ -728,7 +752,7 @@ include::fixtures/include-file.asciidoc[tags=snippetA;snippetB]
|
|
728
752
|
include::fixtures/include-file.xml[tag=snippet]
|
729
753
|
----
|
730
754
|
EOS
|
731
|
-
|
755
|
+
|
732
756
|
output = render_string input, :safe => :safe, :header_footer => false, :base_dir => DIRNAME
|
733
757
|
assert_match('<snippet>content</snippet>', output)
|
734
758
|
refute_match('root', output)
|
@@ -754,7 +778,7 @@ snippetB content)
|
|
754
778
|
input = <<-EOS
|
755
779
|
include::fixtures/include-file.asciidoc[tag=snippetZ]
|
756
780
|
EOS
|
757
|
-
|
781
|
+
|
758
782
|
old_stderr = $stderr
|
759
783
|
$stderr = StringIO.new
|
760
784
|
begin
|
@@ -766,18 +790,18 @@ include::fixtures/include-file.asciidoc[tag=snippetZ]
|
|
766
790
|
$stderr = old_stderr
|
767
791
|
end
|
768
792
|
end
|
769
|
-
|
793
|
+
|
770
794
|
test 'lines attribute takes precedence over tags attribute in include directive' do
|
771
795
|
input = <<-EOS
|
772
796
|
include::fixtures/include-file.asciidoc[lines=1, tags=snippetA;snippetB]
|
773
797
|
EOS
|
774
|
-
|
798
|
+
|
775
799
|
output = render_string input, :safe => :safe, :header_footer => false, :base_dir => DIRNAME
|
776
800
|
assert_match(/first line of included content/, output)
|
777
801
|
refute_match(/snippetA content/, output)
|
778
802
|
refute_match(/snippetB content/, output)
|
779
803
|
end
|
780
|
-
|
804
|
+
|
781
805
|
test 'indent of included file can be reset to size of indent attribute' do
|
782
806
|
input = <<-EOS
|
783
807
|
[source, xml]
|
@@ -785,7 +809,7 @@ include::fixtures/include-file.asciidoc[lines=1, tags=snippetA;snippetB]
|
|
785
809
|
include::fixtures/basic-docinfo.xml[lines=2..3, indent=0]
|
786
810
|
----
|
787
811
|
EOS
|
788
|
-
|
812
|
+
|
789
813
|
output = render_string input, :safe => :safe, :header_footer => false, :base_dir => DIRNAME
|
790
814
|
result = xmlnodes_at_xpath('//pre', output, 1).text
|
791
815
|
assert_equal "<year>2013</year>\n<holder>Acme™, Inc.</holder>", result
|
@@ -795,20 +819,20 @@ include::fixtures/basic-docinfo.xml[lines=2..3, indent=0]
|
|
795
819
|
input = <<-EOS
|
796
820
|
include::fixtures/include-file.asciidoc[]
|
797
821
|
EOS
|
798
|
-
|
822
|
+
|
799
823
|
include_processor = Class.new {
|
800
824
|
def initialize document
|
801
825
|
end
|
802
|
-
|
826
|
+
|
803
827
|
def handles? target
|
804
828
|
false
|
805
829
|
end
|
806
|
-
|
830
|
+
|
807
831
|
def process reader, target, attributes
|
808
832
|
raise 'TestIncludeHandler should not have been invoked'
|
809
833
|
end
|
810
834
|
}
|
811
|
-
|
835
|
+
|
812
836
|
document = empty_safe_document :base_dir => DIRNAME
|
813
837
|
reader = Asciidoctor::PreprocessorReader.new document, input
|
814
838
|
reader.instance_variable_set '@include_processors', [include_processor.new(document)]
|
@@ -839,7 +863,7 @@ content
|
|
839
863
|
document = Asciidoctor.load input, :safe => :safe, :base_dir => DIRNAME, :parse => false
|
840
864
|
assert_equal expected, document.reader.read_lines
|
841
865
|
end
|
842
|
-
|
866
|
+
|
843
867
|
test 'attributes are substituted in target of include directive' do
|
844
868
|
input = <<-EOS
|
845
869
|
:fixturesdir: fixtures
|
@@ -847,17 +871,17 @@ content
|
|
847
871
|
|
848
872
|
include::{fixturesdir}/include-file.{ext}[]
|
849
873
|
EOS
|
850
|
-
|
874
|
+
|
851
875
|
doc = document_from_string input, :safe => :safe, :base_dir => DIRNAME
|
852
876
|
output = doc.render
|
853
877
|
assert_match(/included content/, output)
|
854
878
|
end
|
855
|
-
|
879
|
+
|
856
880
|
test 'line is skipped by default if target of include directive resolves to empty' do
|
857
881
|
input = <<-EOS
|
858
882
|
include::{foodir}/include-file.asciidoc[]
|
859
883
|
EOS
|
860
|
-
|
884
|
+
|
861
885
|
doc = empty_safe_document :base_dir => DIRNAME
|
862
886
|
reader = Asciidoctor::PreprocessorReader.new doc, input
|
863
887
|
assert_equal 'Unresolved directive in <stdin> - include::{foodir}/include-file.asciidoc[]', reader.read_line
|
@@ -867,23 +891,23 @@ include::{foodir}/include-file.asciidoc[]
|
|
867
891
|
input = <<-EOS
|
868
892
|
include::{foodir}/include-file.asciidoc[]
|
869
893
|
EOS
|
870
|
-
|
894
|
+
|
871
895
|
doc = empty_safe_document :base_dir => DIRNAME, :attributes => {'attribute-missing' => 'drop'}
|
872
896
|
reader = Asciidoctor::PreprocessorReader.new doc, input
|
873
897
|
assert_nil reader.read_line
|
874
898
|
end
|
875
|
-
|
899
|
+
|
876
900
|
test 'line following dropped include is not dropped' do
|
877
901
|
input = <<-EOS
|
878
902
|
include::{foodir}/include-file.asciidoc[]
|
879
903
|
yo
|
880
904
|
EOS
|
881
|
-
|
905
|
+
|
882
906
|
doc = empty_safe_document :base_dir => DIRNAME, :attributes => {'attribute-missing' => 'drop'}
|
883
907
|
reader = Asciidoctor::PreprocessorReader.new doc, input
|
884
908
|
assert_equal 'yo', reader.read_line
|
885
909
|
end
|
886
|
-
|
910
|
+
|
887
911
|
test 'escaped include directive is left unprocessed' do
|
888
912
|
input = <<-EOS
|
889
913
|
\\include::fixtures/include-file.asciidoc[]
|
@@ -898,7 +922,7 @@ yo
|
|
898
922
|
assert_equal 'include::fixtures/include-file.asciidoc[]', reader.read_line
|
899
923
|
assert_equal '\\escape preserved here', reader.read_line
|
900
924
|
end
|
901
|
-
|
925
|
+
|
902
926
|
test 'include directive not at start of line is ignored' do
|
903
927
|
input = <<-EOS
|
904
928
|
include::include-file.asciidoc[]
|
@@ -909,7 +933,7 @@ yo
|
|
909
933
|
assert_equal :literal, para.context
|
910
934
|
assert_equal 'include::include-file.asciidoc[]', para.source
|
911
935
|
end
|
912
|
-
|
936
|
+
|
913
937
|
test 'include directive is disabled when max-include-depth attribute is 0' do
|
914
938
|
input = <<-EOS
|
915
939
|
include::include-file.asciidoc[]
|
@@ -918,11 +942,11 @@ include::include-file.asciidoc[]
|
|
918
942
|
assert_equal 1, para.lines.size
|
919
943
|
assert_equal 'include::include-file.asciidoc[]', para.source
|
920
944
|
end
|
921
|
-
|
945
|
+
|
922
946
|
test 'max-include-depth cannot be set by document' do
|
923
947
|
input = <<-EOS
|
924
948
|
:max-include-depth: 1
|
925
|
-
|
949
|
+
|
926
950
|
include::include-file.asciidoc[]
|
927
951
|
EOS
|
928
952
|
para = block_from_string input, :safe => :safe, :attributes => { 'max-include-depth' => 0 }
|
@@ -994,7 +1018,7 @@ ifdef::asciidoctor[]
|
|
994
1018
|
Asciidoctor!
|
995
1019
|
endif::asciidoctor[]
|
996
1020
|
EOS
|
997
|
-
|
1021
|
+
|
998
1022
|
doc = Asciidoctor::Document.new input
|
999
1023
|
reader = doc.reader
|
1000
1024
|
assert_nil reader.process_line(reader.lines.first)
|
@@ -1006,14 +1030,14 @@ ifdef::asciidoctor[]
|
|
1006
1030
|
Asciidoctor!
|
1007
1031
|
endif::asciidoctor[]
|
1008
1032
|
EOS
|
1009
|
-
|
1033
|
+
|
1010
1034
|
doc = Asciidoctor::Document.new input
|
1011
1035
|
reader = doc.reader
|
1012
1036
|
assert_equal 1, reader.lineno
|
1013
1037
|
assert_equal 'Asciidoctor!', reader.peek_line
|
1014
1038
|
assert_equal 2, reader.lineno
|
1015
1039
|
end
|
1016
|
-
|
1040
|
+
|
1017
1041
|
test 'process_line returns line if cursor not advanced' do
|
1018
1042
|
input = <<-EOS
|
1019
1043
|
content
|
@@ -1021,7 +1045,7 @@ ifdef::asciidoctor[]
|
|
1021
1045
|
Asciidoctor!
|
1022
1046
|
endif::asciidoctor[]
|
1023
1047
|
EOS
|
1024
|
-
|
1048
|
+
|
1025
1049
|
doc = Asciidoctor::Document.new input
|
1026
1050
|
reader = doc.reader
|
1027
1051
|
refute_nil reader.process_line(reader.lines.first)
|
@@ -1034,35 +1058,35 @@ ifdef::asciidoctor[]
|
|
1034
1058
|
Asciidoctor!
|
1035
1059
|
endif::asciidoctor[]
|
1036
1060
|
EOS
|
1037
|
-
|
1061
|
+
|
1038
1062
|
doc = Asciidoctor::Document.new input
|
1039
1063
|
reader = doc.reader
|
1040
1064
|
assert_equal 1, reader.lineno
|
1041
1065
|
assert_equal 'content', reader.peek_line
|
1042
1066
|
assert_equal 1, reader.lineno
|
1043
1067
|
end
|
1044
|
-
|
1068
|
+
|
1045
1069
|
test 'peek_line returns nil if cursor advances past end of source' do
|
1046
1070
|
input = <<-EOS
|
1047
1071
|
ifdef::foobar[]
|
1048
1072
|
swallowed content
|
1049
1073
|
endif::foobar[]
|
1050
1074
|
EOS
|
1051
|
-
|
1075
|
+
|
1052
1076
|
doc = Asciidoctor::Document.new input
|
1053
1077
|
reader = doc.reader
|
1054
1078
|
assert_equal 1, reader.lineno
|
1055
1079
|
assert_nil reader.peek_line
|
1056
1080
|
assert_equal 4, reader.lineno
|
1057
1081
|
end
|
1058
|
-
|
1082
|
+
|
1059
1083
|
test 'ifdef with defined attribute includes content' do
|
1060
1084
|
input = <<-EOS
|
1061
1085
|
ifdef::holygrail[]
|
1062
1086
|
There is a holy grail!
|
1063
1087
|
endif::holygrail[]
|
1064
1088
|
EOS
|
1065
|
-
|
1089
|
+
|
1066
1090
|
doc = Asciidoctor::Document.new input, :attributes => { 'holygrail' => '' }
|
1067
1091
|
reader = doc.reader
|
1068
1092
|
lines = []
|
@@ -1071,14 +1095,14 @@ endif::holygrail[]
|
|
1071
1095
|
end
|
1072
1096
|
assert_equal 'There is a holy grail!', (lines * ::Asciidoctor::EOL)
|
1073
1097
|
end
|
1074
|
-
|
1098
|
+
|
1075
1099
|
test 'ifdef with defined attribute includes text in brackets' do
|
1076
1100
|
input = <<-EOS
|
1077
1101
|
On our quest we go...
|
1078
1102
|
ifdef::holygrail[There is a holy grail!]
|
1079
1103
|
There was much rejoicing.
|
1080
1104
|
EOS
|
1081
|
-
|
1105
|
+
|
1082
1106
|
doc = Asciidoctor::Document.new input, :attributes => { 'holygrail' => '' }
|
1083
1107
|
reader = doc.reader
|
1084
1108
|
lines = []
|
@@ -1099,14 +1123,14 @@ endif::showScript[]
|
|
1099
1123
|
result = doc.reader.read
|
1100
1124
|
assert_equal 'The script is shown!', result
|
1101
1125
|
end
|
1102
|
-
|
1126
|
+
|
1103
1127
|
test 'ifndef with defined attribute does not include text in brackets' do
|
1104
1128
|
input = <<-EOS
|
1105
1129
|
On our quest we go...
|
1106
1130
|
ifndef::hardships[There is a holy grail!]
|
1107
1131
|
There was no rejoicing.
|
1108
1132
|
EOS
|
1109
|
-
|
1133
|
+
|
1110
1134
|
doc = Asciidoctor::Document.new input, :attributes => { 'hardships' => '' }
|
1111
1135
|
reader = doc.reader
|
1112
1136
|
lines = []
|
@@ -1115,7 +1139,7 @@ There was no rejoicing.
|
|
1115
1139
|
end
|
1116
1140
|
assert_equal "On our quest we go...\nThere was no rejoicing.", (lines * ::Asciidoctor::EOL)
|
1117
1141
|
end
|
1118
|
-
|
1142
|
+
|
1119
1143
|
test 'include with non-matching nested exclude' do
|
1120
1144
|
input = <<-EOS
|
1121
1145
|
ifdef::grail[]
|
@@ -1126,7 +1150,7 @@ endif::swallow[]
|
|
1126
1150
|
grail
|
1127
1151
|
endif::grail[]
|
1128
1152
|
EOS
|
1129
|
-
|
1153
|
+
|
1130
1154
|
doc = Asciidoctor::Document.new input, :attributes => { 'grail' => '' }
|
1131
1155
|
reader = doc.reader
|
1132
1156
|
lines = []
|
@@ -1135,7 +1159,7 @@ endif::grail[]
|
|
1135
1159
|
end
|
1136
1160
|
assert_equal "holy\ngrail", (lines * ::Asciidoctor::EOL)
|
1137
1161
|
end
|
1138
|
-
|
1162
|
+
|
1139
1163
|
test 'nested excludes with same condition' do
|
1140
1164
|
input = <<-EOS
|
1141
1165
|
ifndef::grail[]
|
@@ -1144,7 +1168,7 @@ not here
|
|
1144
1168
|
endif::grail[]
|
1145
1169
|
endif::grail[]
|
1146
1170
|
EOS
|
1147
|
-
|
1171
|
+
|
1148
1172
|
doc = Asciidoctor::Document.new input, :attributes => { 'grail' => '' }
|
1149
1173
|
reader = doc.reader
|
1150
1174
|
lines = []
|
@@ -1153,7 +1177,7 @@ endif::grail[]
|
|
1153
1177
|
end
|
1154
1178
|
assert_equal '', (lines * ::Asciidoctor::EOL)
|
1155
1179
|
end
|
1156
|
-
|
1180
|
+
|
1157
1181
|
test 'include with nested exclude of inverted condition' do
|
1158
1182
|
input = <<-EOS
|
1159
1183
|
ifdef::grail[]
|
@@ -1164,7 +1188,7 @@ endif::grail[]
|
|
1164
1188
|
grail
|
1165
1189
|
endif::grail[]
|
1166
1190
|
EOS
|
1167
|
-
|
1191
|
+
|
1168
1192
|
doc = Asciidoctor::Document.new input, :attributes => { 'grail' => '' }
|
1169
1193
|
reader = doc.reader
|
1170
1194
|
lines = []
|
@@ -1173,7 +1197,7 @@ endif::grail[]
|
|
1173
1197
|
end
|
1174
1198
|
assert_equal "holy\ngrail", (lines * ::Asciidoctor::EOL)
|
1175
1199
|
end
|
1176
|
-
|
1200
|
+
|
1177
1201
|
test 'exclude with matching nested exclude' do
|
1178
1202
|
input = <<-EOS
|
1179
1203
|
poof
|
@@ -1186,7 +1210,7 @@ here
|
|
1186
1210
|
endif::swallow[]
|
1187
1211
|
gone
|
1188
1212
|
EOS
|
1189
|
-
|
1213
|
+
|
1190
1214
|
doc = Asciidoctor::Document.new input, :attributes => { 'grail' => '' }
|
1191
1215
|
reader = doc.reader
|
1192
1216
|
lines = []
|
@@ -1195,7 +1219,7 @@ gone
|
|
1195
1219
|
end
|
1196
1220
|
assert_equal "poof\ngone", (lines * ::Asciidoctor::EOL)
|
1197
1221
|
end
|
1198
|
-
|
1222
|
+
|
1199
1223
|
test 'exclude with nested include using shorthand end' do
|
1200
1224
|
input = <<-EOS
|
1201
1225
|
poof
|
@@ -1208,7 +1232,7 @@ in here
|
|
1208
1232
|
endif::[]
|
1209
1233
|
gone
|
1210
1234
|
EOS
|
1211
|
-
|
1235
|
+
|
1212
1236
|
doc = Asciidoctor::Document.new input, :attributes => { 'grail' => '' }
|
1213
1237
|
reader = doc.reader
|
1214
1238
|
lines = []
|
@@ -1217,14 +1241,14 @@ gone
|
|
1217
1241
|
end
|
1218
1242
|
assert_equal "poof\ngone", (lines * ::Asciidoctor::EOL)
|
1219
1243
|
end
|
1220
|
-
|
1244
|
+
|
1221
1245
|
test 'ifdef with one alternative attribute set includes content' do
|
1222
1246
|
input = <<-EOS
|
1223
1247
|
ifdef::holygrail,swallow[]
|
1224
1248
|
Our quest is complete!
|
1225
1249
|
endif::holygrail,swallow[]
|
1226
1250
|
EOS
|
1227
|
-
|
1251
|
+
|
1228
1252
|
doc = Asciidoctor::Document.new input, :attributes => { 'swallow' => '' }
|
1229
1253
|
reader = doc.reader
|
1230
1254
|
lines = []
|
@@ -1233,14 +1257,14 @@ endif::holygrail,swallow[]
|
|
1233
1257
|
end
|
1234
1258
|
assert_equal 'Our quest is complete!', (lines * ::Asciidoctor::EOL)
|
1235
1259
|
end
|
1236
|
-
|
1260
|
+
|
1237
1261
|
test 'ifdef with no alternative attributes set does not include content' do
|
1238
1262
|
input = <<-EOS
|
1239
1263
|
ifdef::holygrail,swallow[]
|
1240
1264
|
Our quest is complete!
|
1241
1265
|
endif::holygrail,swallow[]
|
1242
1266
|
EOS
|
1243
|
-
|
1267
|
+
|
1244
1268
|
doc = Asciidoctor::Document.new input
|
1245
1269
|
reader = doc.reader
|
1246
1270
|
lines = []
|
@@ -1249,14 +1273,14 @@ endif::holygrail,swallow[]
|
|
1249
1273
|
end
|
1250
1274
|
assert_equal '', (lines * ::Asciidoctor::EOL)
|
1251
1275
|
end
|
1252
|
-
|
1276
|
+
|
1253
1277
|
test 'ifdef with all required attributes set includes content' do
|
1254
1278
|
input = <<-EOS
|
1255
1279
|
ifdef::holygrail+swallow[]
|
1256
1280
|
Our quest is complete!
|
1257
1281
|
endif::holygrail+swallow[]
|
1258
1282
|
EOS
|
1259
|
-
|
1283
|
+
|
1260
1284
|
doc = Asciidoctor::Document.new input, :attributes => { 'holygrail' => '', 'swallow' => '' }
|
1261
1285
|
reader = doc.reader
|
1262
1286
|
lines = []
|
@@ -1265,14 +1289,14 @@ endif::holygrail+swallow[]
|
|
1265
1289
|
end
|
1266
1290
|
assert_equal 'Our quest is complete!', (lines * ::Asciidoctor::EOL)
|
1267
1291
|
end
|
1268
|
-
|
1292
|
+
|
1269
1293
|
test 'ifdef with missing required attributes does not include content' do
|
1270
1294
|
input = <<-EOS
|
1271
1295
|
ifdef::holygrail+swallow[]
|
1272
1296
|
Our quest is complete!
|
1273
1297
|
endif::holygrail+swallow[]
|
1274
1298
|
EOS
|
1275
|
-
|
1299
|
+
|
1276
1300
|
doc = Asciidoctor::Document.new input, :attributes => { 'holygrail' => '' }
|
1277
1301
|
reader = doc.reader
|
1278
1302
|
lines = []
|
@@ -1281,14 +1305,14 @@ endif::holygrail+swallow[]
|
|
1281
1305
|
end
|
1282
1306
|
assert_equal '', (lines * ::Asciidoctor::EOL)
|
1283
1307
|
end
|
1284
|
-
|
1308
|
+
|
1285
1309
|
test 'ifndef with undefined attribute includes block' do
|
1286
1310
|
input = <<-EOS
|
1287
1311
|
ifndef::holygrail[]
|
1288
1312
|
Our quest continues to find the holy grail!
|
1289
1313
|
endif::holygrail[]
|
1290
1314
|
EOS
|
1291
|
-
|
1315
|
+
|
1292
1316
|
doc = Asciidoctor::Document.new input
|
1293
1317
|
reader = doc.reader
|
1294
1318
|
lines = []
|
@@ -1297,14 +1321,14 @@ endif::holygrail[]
|
|
1297
1321
|
end
|
1298
1322
|
assert_equal 'Our quest continues to find the holy grail!', (lines * ::Asciidoctor::EOL)
|
1299
1323
|
end
|
1300
|
-
|
1324
|
+
|
1301
1325
|
test 'ifndef with one alternative attribute set includes content' do
|
1302
1326
|
input = <<-EOS
|
1303
1327
|
ifndef::holygrail,swallow[]
|
1304
1328
|
Our quest is complete!
|
1305
1329
|
endif::holygrail,swallow[]
|
1306
1330
|
EOS
|
1307
|
-
|
1331
|
+
|
1308
1332
|
doc = Asciidoctor::Document.new input, :attributes => { 'swallow' => '' }
|
1309
1333
|
reader = doc.reader
|
1310
1334
|
lines = []
|
@@ -1313,14 +1337,14 @@ endif::holygrail,swallow[]
|
|
1313
1337
|
end
|
1314
1338
|
assert_equal 'Our quest is complete!', (lines * ::Asciidoctor::EOL)
|
1315
1339
|
end
|
1316
|
-
|
1340
|
+
|
1317
1341
|
test 'ifndef with no alternative attributes set includes content' do
|
1318
1342
|
input = <<-EOS
|
1319
1343
|
ifndef::holygrail,swallow[]
|
1320
1344
|
Our quest is complete!
|
1321
1345
|
endif::holygrail,swallow[]
|
1322
1346
|
EOS
|
1323
|
-
|
1347
|
+
|
1324
1348
|
doc = Asciidoctor::Document.new input
|
1325
1349
|
reader = doc.reader
|
1326
1350
|
lines = []
|
@@ -1329,14 +1353,14 @@ endif::holygrail,swallow[]
|
|
1329
1353
|
end
|
1330
1354
|
assert_equal 'Our quest is complete!', (lines * ::Asciidoctor::EOL)
|
1331
1355
|
end
|
1332
|
-
|
1356
|
+
|
1333
1357
|
test 'ifndef with any required attributes set does not include content' do
|
1334
1358
|
input = <<-EOS
|
1335
1359
|
ifndef::holygrail+swallow[]
|
1336
1360
|
Our quest is complete!
|
1337
1361
|
endif::holygrail+swallow[]
|
1338
1362
|
EOS
|
1339
|
-
|
1363
|
+
|
1340
1364
|
doc = Asciidoctor::Document.new input, :attributes => { 'swallow' => '' }
|
1341
1365
|
reader = doc.reader
|
1342
1366
|
lines = []
|
@@ -1345,14 +1369,14 @@ endif::holygrail+swallow[]
|
|
1345
1369
|
end
|
1346
1370
|
assert_equal '', (lines * ::Asciidoctor::EOL)
|
1347
1371
|
end
|
1348
|
-
|
1372
|
+
|
1349
1373
|
test 'ifndef with no required attributes set includes content' do
|
1350
1374
|
input = <<-EOS
|
1351
1375
|
ifndef::holygrail+swallow[]
|
1352
1376
|
Our quest is complete!
|
1353
1377
|
endif::holygrail+swallow[]
|
1354
1378
|
EOS
|
1355
|
-
|
1379
|
+
|
1356
1380
|
doc = Asciidoctor::Document.new input
|
1357
1381
|
reader = doc.reader
|
1358
1382
|
lines = []
|
@@ -1361,14 +1385,14 @@ endif::holygrail+swallow[]
|
|
1361
1385
|
end
|
1362
1386
|
assert_equal 'Our quest is complete!', (lines * ::Asciidoctor::EOL)
|
1363
1387
|
end
|
1364
|
-
|
1388
|
+
|
1365
1389
|
test 'escaped ifdef is unescaped and ignored' do
|
1366
1390
|
input = <<-EOS
|
1367
1391
|
\\ifdef::holygrail[]
|
1368
1392
|
content
|
1369
1393
|
\\endif::holygrail[]
|
1370
1394
|
EOS
|
1371
|
-
|
1395
|
+
|
1372
1396
|
doc = Asciidoctor::Document.new input
|
1373
1397
|
reader = doc.reader
|
1374
1398
|
lines = []
|
@@ -1378,7 +1402,7 @@ content
|
|
1378
1402
|
assert_equal "ifdef::holygrail[]\ncontent\nendif::holygrail[]", (lines * ::Asciidoctor::EOL)
|
1379
1403
|
end
|
1380
1404
|
|
1381
|
-
test 'ifeval comparing missing attribute to nil
|
1405
|
+
test 'ifeval comparing missing attribute to nil includes content' do
|
1382
1406
|
input = <<-EOS
|
1383
1407
|
ifeval::['{foo}' == '']
|
1384
1408
|
No foo for you!
|
@@ -1393,14 +1417,30 @@ endif::[]
|
|
1393
1417
|
end
|
1394
1418
|
assert_equal 'No foo for you!', (lines * ::Asciidoctor::EOL)
|
1395
1419
|
end
|
1396
|
-
|
1397
|
-
test 'ifeval comparing
|
1420
|
+
|
1421
|
+
test 'ifeval comparing missing attribute to 0 drops content' do
|
1422
|
+
input = <<-EOS
|
1423
|
+
ifeval::[{leveloffset} == 0]
|
1424
|
+
I didn't make the cut!
|
1425
|
+
endif::[]
|
1426
|
+
EOS
|
1427
|
+
|
1428
|
+
doc = Asciidoctor::Document.new input
|
1429
|
+
reader = doc.reader
|
1430
|
+
lines = []
|
1431
|
+
while reader.has_more_lines?
|
1432
|
+
lines << reader.read_line
|
1433
|
+
end
|
1434
|
+
assert_equal '', (lines * ::Asciidoctor::EOL)
|
1435
|
+
end
|
1436
|
+
|
1437
|
+
test 'ifeval comparing double-quoted attribute to matching string includes content' do
|
1398
1438
|
input = <<-EOS
|
1399
1439
|
ifeval::["{gem}" == "asciidoctor"]
|
1400
1440
|
Asciidoctor it is!
|
1401
1441
|
endif::[]
|
1402
1442
|
EOS
|
1403
|
-
|
1443
|
+
|
1404
1444
|
doc = Asciidoctor::Document.new input, :attributes => { 'gem' => 'asciidoctor' }
|
1405
1445
|
reader = doc.reader
|
1406
1446
|
lines = []
|
@@ -1409,14 +1449,14 @@ endif::[]
|
|
1409
1449
|
end
|
1410
1450
|
assert_equal 'Asciidoctor it is!', (lines * ::Asciidoctor::EOL)
|
1411
1451
|
end
|
1412
|
-
|
1413
|
-
test 'ifeval comparing single-quoted attribute to matching string
|
1452
|
+
|
1453
|
+
test 'ifeval comparing single-quoted attribute to matching string includes content' do
|
1414
1454
|
input = <<-EOS
|
1415
1455
|
ifeval::['{gem}' == 'asciidoctor']
|
1416
1456
|
Asciidoctor it is!
|
1417
1457
|
endif::[]
|
1418
1458
|
EOS
|
1419
|
-
|
1459
|
+
|
1420
1460
|
doc = Asciidoctor::Document.new input, :attributes => { 'gem' => 'asciidoctor' }
|
1421
1461
|
reader = doc.reader
|
1422
1462
|
lines = []
|
@@ -1425,14 +1465,14 @@ endif::[]
|
|
1425
1465
|
end
|
1426
1466
|
assert_equal 'Asciidoctor it is!', (lines * ::Asciidoctor::EOL)
|
1427
1467
|
end
|
1428
|
-
|
1429
|
-
test 'ifeval comparing quoted attribute to non-matching string
|
1468
|
+
|
1469
|
+
test 'ifeval comparing quoted attribute to non-matching string drops content' do
|
1430
1470
|
input = <<-EOS
|
1431
1471
|
ifeval::['{gem}' == 'asciidoctor']
|
1432
1472
|
Asciidoctor it is!
|
1433
1473
|
endif::[]
|
1434
1474
|
EOS
|
1435
|
-
|
1475
|
+
|
1436
1476
|
doc = Asciidoctor::Document.new input, :attributes => { 'gem' => 'tilt' }
|
1437
1477
|
reader = doc.reader
|
1438
1478
|
lines = []
|
@@ -1441,14 +1481,14 @@ endif::[]
|
|
1441
1481
|
end
|
1442
1482
|
assert_equal '', (lines * ::Asciidoctor::EOL)
|
1443
1483
|
end
|
1444
|
-
|
1445
|
-
test 'ifeval comparing attribute to lower version number
|
1484
|
+
|
1485
|
+
test 'ifeval comparing attribute to lower version number includes content' do
|
1446
1486
|
input = <<-EOS
|
1447
1487
|
ifeval::['{asciidoctor-version}' >= '0.1.0']
|
1448
1488
|
That version will do!
|
1449
1489
|
endif::[]
|
1450
1490
|
EOS
|
1451
|
-
|
1491
|
+
|
1452
1492
|
doc = Asciidoctor::Document.new input
|
1453
1493
|
reader = doc.reader
|
1454
1494
|
lines = []
|
@@ -1457,14 +1497,14 @@ endif::[]
|
|
1457
1497
|
end
|
1458
1498
|
assert_equal 'That version will do!', (lines * ::Asciidoctor::EOL)
|
1459
1499
|
end
|
1460
|
-
|
1461
|
-
test 'ifeval comparing attribute to self
|
1500
|
+
|
1501
|
+
test 'ifeval comparing attribute to self includes content' do
|
1462
1502
|
input = <<-EOS
|
1463
1503
|
ifeval::['{asciidoctor-version}' == '{asciidoctor-version}']
|
1464
1504
|
Of course it's the same!
|
1465
1505
|
endif::[]
|
1466
1506
|
EOS
|
1467
|
-
|
1507
|
+
|
1468
1508
|
doc = Asciidoctor::Document.new input
|
1469
1509
|
reader = doc.reader
|
1470
1510
|
lines = []
|
@@ -1473,14 +1513,14 @@ endif::[]
|
|
1473
1513
|
end
|
1474
1514
|
assert_equal 'Of course it\'s the same!', (lines * ::Asciidoctor::EOL)
|
1475
1515
|
end
|
1476
|
-
|
1516
|
+
|
1477
1517
|
test 'ifeval arguments can be transposed' do
|
1478
1518
|
input = <<-EOS
|
1479
1519
|
ifeval::['0.1.0' <= '{asciidoctor-version}']
|
1480
1520
|
That version will do!
|
1481
1521
|
endif::[]
|
1482
1522
|
EOS
|
1483
|
-
|
1523
|
+
|
1484
1524
|
doc = Asciidoctor::Document.new input
|
1485
1525
|
reader = doc.reader
|
1486
1526
|
lines = []
|
@@ -1489,14 +1529,14 @@ endif::[]
|
|
1489
1529
|
end
|
1490
1530
|
assert_equal 'That version will do!', (lines * ::Asciidoctor::EOL)
|
1491
1531
|
end
|
1492
|
-
|
1493
|
-
test 'ifeval matching numeric equality
|
1532
|
+
|
1533
|
+
test 'ifeval matching numeric equality includes content' do
|
1494
1534
|
input = <<-EOS
|
1495
1535
|
ifeval::[{rings} == 1]
|
1496
1536
|
One ring to rule them all!
|
1497
1537
|
endif::[]
|
1498
1538
|
EOS
|
1499
|
-
|
1539
|
+
|
1500
1540
|
doc = Asciidoctor::Document.new input, :attributes => { 'rings' => '1' }
|
1501
1541
|
reader = doc.reader
|
1502
1542
|
lines = []
|
@@ -1506,13 +1546,13 @@ endif::[]
|
|
1506
1546
|
assert_equal 'One ring to rule them all!', (lines * ::Asciidoctor::EOL)
|
1507
1547
|
end
|
1508
1548
|
|
1509
|
-
test 'ifeval matching numeric inequality
|
1549
|
+
test 'ifeval matching numeric inequality includes content' do
|
1510
1550
|
input = <<-EOS
|
1511
1551
|
ifeval::[{rings} != 0]
|
1512
1552
|
One ring to rule them all!
|
1513
1553
|
endif::[]
|
1514
1554
|
EOS
|
1515
|
-
|
1555
|
+
|
1516
1556
|
doc = Asciidoctor::Document.new input, :attributes => { 'rings' => '1' }
|
1517
1557
|
reader = doc.reader
|
1518
1558
|
lines = []
|
@@ -1521,13 +1561,13 @@ endif::[]
|
|
1521
1561
|
end
|
1522
1562
|
assert_equal 'One ring to rule them all!', (lines * ::Asciidoctor::EOL)
|
1523
1563
|
end
|
1524
|
-
|
1564
|
+
|
1525
1565
|
test 'ifdef with no target is ignored' do
|
1526
1566
|
input = <<-EOS
|
1527
1567
|
ifdef::[]
|
1528
1568
|
content
|
1529
1569
|
EOS
|
1530
|
-
|
1570
|
+
|
1531
1571
|
doc = Asciidoctor::Document.new input
|
1532
1572
|
reader = doc.reader
|
1533
1573
|
lines = []
|