asciidoctor 0.0.7 → 0.0.9

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.

Files changed (47) hide show
  1. data/Gemfile +2 -0
  2. data/README.asciidoc +35 -26
  3. data/Rakefile +9 -6
  4. data/asciidoctor.gemspec +27 -8
  5. data/bin/asciidoctor +1 -1
  6. data/lib/asciidoctor.rb +351 -63
  7. data/lib/asciidoctor/abstract_block.rb +218 -0
  8. data/lib/asciidoctor/abstract_node.rb +249 -0
  9. data/lib/asciidoctor/attribute_list.rb +211 -0
  10. data/lib/asciidoctor/backends/base_template.rb +99 -0
  11. data/lib/asciidoctor/backends/docbook45.rb +510 -0
  12. data/lib/asciidoctor/backends/html5.rb +585 -0
  13. data/lib/asciidoctor/block.rb +27 -254
  14. data/lib/asciidoctor/callouts.rb +117 -0
  15. data/lib/asciidoctor/debug.rb +7 -4
  16. data/lib/asciidoctor/document.rb +229 -77
  17. data/lib/asciidoctor/inline.rb +29 -0
  18. data/lib/asciidoctor/lexer.rb +1330 -502
  19. data/lib/asciidoctor/list_item.rb +33 -34
  20. data/lib/asciidoctor/reader.rb +305 -142
  21. data/lib/asciidoctor/renderer.rb +115 -19
  22. data/lib/asciidoctor/section.rb +100 -189
  23. data/lib/asciidoctor/substituters.rb +468 -0
  24. data/lib/asciidoctor/table.rb +499 -0
  25. data/lib/asciidoctor/version.rb +1 -1
  26. data/test/attributes_test.rb +301 -87
  27. data/test/blocks_test.rb +568 -0
  28. data/test/document_test.rb +221 -24
  29. data/test/fixtures/dot.gif +0 -0
  30. data/test/fixtures/encoding.asciidoc +1 -0
  31. data/test/fixtures/include-file.asciidoc +1 -0
  32. data/test/fixtures/tip.gif +0 -0
  33. data/test/headers_test.rb +411 -43
  34. data/test/lexer_test.rb +265 -45
  35. data/test/links_test.rb +144 -3
  36. data/test/lists_test.rb +2252 -74
  37. data/test/paragraphs_test.rb +21 -30
  38. data/test/preamble_test.rb +24 -0
  39. data/test/reader_test.rb +248 -12
  40. data/test/renderer_test.rb +22 -0
  41. data/test/substitutions_test.rb +414 -0
  42. data/test/tables_test.rb +484 -0
  43. data/test/test_helper.rb +70 -6
  44. data/test/text_test.rb +30 -6
  45. metadata +64 -10
  46. data/lib/asciidoctor/render_templates.rb +0 -317
  47. data/lib/asciidoctor/string.rb +0 -12
@@ -1,66 +1,286 @@
1
1
  require 'test_helper'
2
2
 
3
- class LexerTest < Test::Unit::TestCase
4
- # setup for test
5
- def setup
3
+ context "Lexer" do
4
+
5
+ test "test_is_section_title" do
6
+ assert Asciidoctor::Lexer.is_section_title?('AsciiDoc Home Page', '==================')
7
+ assert Asciidoctor::Lexer.is_section_title?('=== AsciiDoc Home Page')
8
+ end
9
+
10
+ test "collect unnamed attribute" do
11
+ attributes = {}
12
+ line = 'quote'
13
+ expected = {1 => 'quote'}
14
+ Asciidoctor::AttributeList.new(line).parse_into(attributes)
15
+ assert_equal expected, attributes
16
+ end
17
+
18
+ test "collect unnamed attribute double-quoted" do
19
+ attributes = {}
20
+ line = '"quote"'
21
+ expected = {1 => 'quote'}
22
+ Asciidoctor::AttributeList.new(line).parse_into(attributes)
23
+ assert_equal expected, attributes
24
+ end
25
+
26
+ test "collect unnamed attribute double-quoted containing escaped quote" do
27
+ attributes = {}
28
+ line = '"ba\"zaar"'
29
+ expected = {1 => 'ba"zaar'}
30
+ Asciidoctor::AttributeList.new(line).parse_into(attributes)
31
+ assert_equal expected, attributes
6
32
  end
7
33
 
8
- def test_is_section_heading
9
- assert Asciidoctor::Lexer.is_section_heading?("AsciiDoc Home Page", "==================")
10
- assert Asciidoctor::Lexer.is_section_heading?("=== AsciiDoc Home Page")
34
+ test "collect unnamed attribute single-quoted" do
35
+ attributes = {}
36
+ line = '\'quote\''
37
+ expected = {1 => 'quote'}
38
+ Asciidoctor::AttributeList.new(line).parse_into(attributes)
39
+ assert_equal expected, attributes
40
+ end
41
+
42
+ test "collect unnamed attribute single-quoted containing escaped quote" do
43
+ attributes = {}
44
+ line = '\'ba\\\'zaar\''
45
+ expected = {1 => 'ba\'zaar'}
46
+ Asciidoctor::AttributeList.new(line).parse_into(attributes)
47
+ assert_equal expected, attributes
11
48
  end
12
49
 
13
- def test_collect_unnamed_attributes
50
+ test "collect unnamed attribute with dangling delimiter" do
51
+ attributes = {}
52
+ line = 'quote , '
53
+ expected = {1 => 'quote'}
54
+ Asciidoctor::AttributeList.new(line).parse_into(attributes)
55
+ assert_equal expected, attributes
56
+ end
57
+
58
+ test "collect unnamed attributes" do
14
59
  attributes = {}
15
60
  line = "first, second one, third"
16
- Asciidoctor::Lexer.collect_attributes(line, attributes)
17
- assert_equal 3, attributes.length
18
- assert_equal 'first', attributes[0]
19
- assert_equal 'second one', attributes[1]
20
- assert_equal 'third', attributes[2]
61
+ expected = {1 => 'first', 2 => 'second one', 3 => 'third'}
62
+ Asciidoctor::AttributeList.new(line).parse_into(attributes)
63
+ assert_equal expected, attributes
21
64
  end
22
65
 
23
- def test_collect_named_attributes
66
+ test "collect named attribute" do
67
+ attributes = {}
68
+ line = 'foo=bar'
69
+ expected = {'foo' => 'bar'}
70
+ Asciidoctor::AttributeList.new(line).parse_into(attributes)
71
+ assert_equal expected, attributes
72
+ end
73
+
74
+ test "collect named attribute double-quoted" do
75
+ attributes = {}
76
+ line = 'foo="bar"'
77
+ expected = {'foo' => 'bar'}
78
+ Asciidoctor::AttributeList.new(line).parse_into(attributes)
79
+ assert_equal expected, attributes
80
+ end
81
+
82
+ test "collect named attribute single-quoted" do
83
+ attributes = {}
84
+ line = 'foo=\'bar\''
85
+ expected = {'foo' => 'bar'}
86
+ Asciidoctor::AttributeList.new(line).parse_into(attributes)
87
+ assert_equal expected, attributes
88
+ end
89
+
90
+ test "collect named attributes unquoted" do
91
+ attributes = {}
92
+ line = "first=value, second=two, third=3"
93
+ expected = {'first' => 'value', 'second' => 'two', 'third' => '3'}
94
+ Asciidoctor::AttributeList.new(line).parse_into(attributes)
95
+ assert_equal expected, attributes
96
+ end
97
+
98
+ test "collect named attributes quoted" do
24
99
  attributes = {}
25
100
  line = "first='value', second=\"value two\", third=three"
26
- Asciidoctor::Lexer.collect_attributes(line, attributes)
27
- assert_equal 3, attributes.length
28
- assert_equal 'value', attributes['first']
29
- assert_equal 'value two', attributes['second']
30
- assert_equal 'three', attributes['third']
101
+ expected = {'first' => 'value', 'second' => 'value two', 'third' => 'three'}
102
+ Asciidoctor::AttributeList.new(line).parse_into(attributes)
103
+ assert_equal expected, attributes
104
+ end
105
+
106
+ test "collect named attributes quoted containing non-semantic spaces" do
107
+ attributes = {}
108
+ line = " first = 'value', second =\"value two\" , third= three "
109
+ expected = {'first' => 'value', 'second' => 'value two', 'third' => 'three'}
110
+ Asciidoctor::AttributeList.new(line).parse_into(attributes)
111
+ assert_equal expected, attributes
112
+ end
113
+
114
+ test "collect mixed named and unnamed attributes" do
115
+ attributes = {}
116
+ line = "first, second=\"value two\", third=three, Sherlock Holmes"
117
+ expected = {1 => 'first', 'second' => 'value two', 'third' => 'three', 4 => 'Sherlock Holmes'}
118
+ Asciidoctor::AttributeList.new(line).parse_into(attributes)
119
+ assert_equal expected, attributes
31
120
  end
32
121
 
33
- def test_collect_mixed_named_and_unnamed_attributes
122
+ test "collect options attribute" do
34
123
  attributes = {}
35
- line = "first, second=\"value two\", third=three"
36
- Asciidoctor::Lexer.collect_attributes(line, attributes)
37
- assert_equal 3, attributes.length
38
- assert_equal 'first', attributes[0]
39
- assert_equal 'value two', attributes['second']
40
- assert_equal 'three', attributes['third']
124
+ line = "quote, options='opt1,opt2 , opt3'"
125
+ expected = {1 => 'quote', 'options' => 'opt1,opt2 , opt3', 'opt1-option' => nil, 'opt2-option' => nil, 'opt3-option' => nil}
126
+ Asciidoctor::AttributeList.new(line).parse_into(attributes)
127
+ assert_equal expected, attributes
41
128
  end
42
129
 
43
- def test_collect_and_rekey_unnamed_attributes
130
+ test "collect and rekey unnamed attributes" do
44
131
  attributes = {}
45
132
  line = "first, second one, third, fourth"
46
- Asciidoctor::Lexer.collect_attributes(line, attributes, ['a', 'b', 'c'])
47
- assert_equal 7, attributes.length
48
- assert_equal 'first', attributes['a']
49
- assert_equal 'second one', attributes['b']
50
- assert_equal 'third', attributes['c']
51
- assert_equal 'first', attributes[0]
52
- assert_equal 'second one', attributes[1]
53
- assert_equal 'third', attributes[2]
54
- assert_equal 'fourth', attributes[3]
55
- end
56
-
57
- def test_rekey_positional_attributes
58
- attributes = {0 => 'source', 1 => 'java'}
59
- Asciidoctor::Lexer.rekey_positional_attributes(attributes, ['style', 'language', 'linenums'])
60
- assert_equal 4, attributes.length
61
- assert_equal 'source', attributes[0]
62
- assert_equal 'java', attributes[1]
63
- assert_equal 'source', attributes['style']
64
- assert_equal 'java', attributes['language']
133
+ expected = {1 => 'first', 2 => 'second one', 3 => 'third', 4 => 'fourth', 'a' => 'first', 'b' => 'second one', 'c' => 'third'}
134
+ Asciidoctor::AttributeList.new(line).parse_into(attributes, ['a', 'b', 'c'])
135
+ assert_equal expected, attributes
65
136
  end
137
+
138
+ test "rekey positional attributes" do
139
+ attributes = {1 => 'source', 2 => 'java'}
140
+ expected = {1 => 'source', 2 => 'java', 'style' => 'source', 'language' => 'java'}
141
+ Asciidoctor::AttributeList.rekey(attributes, ['style', 'language', 'linenums'])
142
+ assert_equal expected, attributes
143
+ end
144
+
145
+ test "test_parse_author_first" do
146
+ metadata, = parse_header_metadata 'Stuart'
147
+ assert_equal 3, metadata.size
148
+ assert_equal 'Stuart', metadata['author']
149
+ assert_equal 'Stuart', metadata['firstname']
150
+ assert_equal 'S', metadata['authorinitials']
151
+ end
152
+
153
+ test "test_parse_author_first_last" do
154
+ metadata, = parse_header_metadata 'Yukihiro Matsumoto'
155
+ assert_equal 4, metadata.size
156
+ assert_equal 'Yukihiro Matsumoto', metadata['author']
157
+ assert_equal 'Yukihiro', metadata['firstname']
158
+ assert_equal 'Matsumoto', metadata['lastname']
159
+ assert_equal 'YM', metadata['authorinitials']
160
+ end
161
+
162
+ test "test_parse_author_first_middle_last" do
163
+ metadata, = parse_header_metadata 'David Heinemeier Hansson'
164
+ assert_equal 5, metadata.size
165
+ assert_equal 'David Heinemeier Hansson', metadata['author']
166
+ assert_equal 'David', metadata['firstname']
167
+ assert_equal 'Heinemeier', metadata['middlename']
168
+ assert_equal 'Hansson', metadata['lastname']
169
+ assert_equal 'DHH', metadata['authorinitials']
170
+ end
171
+
172
+ test "test_parse_author_first_middle_last_email" do
173
+ metadata, = parse_header_metadata 'David Heinemeier Hansson <rails@ruby-lang.org>'
174
+ assert_equal 6, metadata.size
175
+ assert_equal 'David Heinemeier Hansson', metadata['author']
176
+ assert_equal 'David', metadata['firstname']
177
+ assert_equal 'Heinemeier', metadata['middlename']
178
+ assert_equal 'Hansson', metadata['lastname']
179
+ assert_equal 'rails@ruby-lang.org', metadata['email']
180
+ assert_equal 'DHH', metadata['authorinitials']
181
+ end
182
+
183
+ test "test_parse_author_first_email" do
184
+ metadata, = parse_header_metadata 'Stuart <founder@asciidoc.org>'
185
+ assert_equal 4, metadata.size
186
+ assert_equal 'Stuart', metadata['author']
187
+ assert_equal 'Stuart', metadata['firstname']
188
+ assert_equal 'founder@asciidoc.org', metadata['email']
189
+ assert_equal 'S', metadata['authorinitials']
190
+ end
191
+
192
+ test "test_parse_author_first_last_email" do
193
+ metadata, = parse_header_metadata 'Stuart Rackham <founder@asciidoc.org>'
194
+ assert_equal 5, metadata.size
195
+ assert_equal 'Stuart Rackham', metadata['author']
196
+ assert_equal 'Stuart', metadata['firstname']
197
+ assert_equal 'Rackham', metadata['lastname']
198
+ assert_equal 'founder@asciidoc.org', metadata['email']
199
+ assert_equal 'SR', metadata['authorinitials']
200
+ end
201
+
202
+ test "test_parse_author_with_hyphen" do
203
+ metadata, = parse_header_metadata 'Tim Berners-Lee <founder@www.org>'
204
+ assert_equal 5, metadata.size
205
+ assert_equal 'Tim Berners-Lee', metadata['author']
206
+ assert_equal 'Tim', metadata['firstname']
207
+ assert_equal 'Berners-Lee', metadata['lastname']
208
+ assert_equal 'founder@www.org', metadata['email']
209
+ assert_equal 'TB', metadata['authorinitials']
210
+ end
211
+
212
+ test "test_parse_author_with_underscore" do
213
+ metadata, = parse_header_metadata 'Tim_E Fella'
214
+ assert_equal 4, metadata.size
215
+ assert_equal 'Tim E Fella', metadata['author']
216
+ assert_equal 'Tim E', metadata['firstname']
217
+ assert_equal 'Fella', metadata['lastname']
218
+ assert_equal 'TF', metadata['authorinitials']
219
+ end
220
+
221
+ test "test_parse_author_condenses_whitespace" do
222
+ metadata, = parse_header_metadata ' Stuart Rackham <founder@asciidoc.org>'
223
+ assert_equal 5, metadata.size
224
+ assert_equal 'Stuart Rackham', metadata['author']
225
+ assert_equal 'Stuart', metadata['firstname']
226
+ assert_equal 'Rackham', metadata['lastname']
227
+ assert_equal 'founder@asciidoc.org', metadata['email']
228
+ assert_equal 'SR', metadata['authorinitials']
229
+ end
230
+
231
+ test "test_parse_invalid_author_line_becomes_author" do
232
+ metadata, = parse_header_metadata ' Stuart Rackham, founder of AsciiDoc <founder@asciidoc.org>'
233
+ assert_equal 3, metadata.size
234
+ assert_equal 'Stuart Rackham, founder of AsciiDoc <founder@asciidoc.org>', metadata['author']
235
+ assert_equal 'Stuart Rackham, founder of AsciiDoc <founder@asciidoc.org>', metadata['firstname']
236
+ assert_equal 'S', metadata['authorinitials']
237
+ end
238
+
239
+ test "test_parse_rev_number_date_remark" do
240
+ metadata, = parse_header_metadata "Ryan Waldron\nv0.0.7, 2013-12-18: The first release you can stand on"
241
+ assert_equal 7, metadata.size
242
+ assert_equal '0.0.7', metadata['revnumber']
243
+ assert_equal '2013-12-18', metadata['revdate']
244
+ assert_equal 'The first release you can stand on', metadata['revremark']
245
+ end
246
+
247
+ test "test_parse_rev_date" do
248
+ metadata, = parse_header_metadata "Ryan Waldron\n2013-12-18"
249
+ assert_equal 5, metadata.size
250
+ assert_equal '2013-12-18', metadata['revdate']
251
+ end
252
+
253
+ test "test_parse_rev_date_remark" do
254
+ metadata, = parse_header_metadata "Ryan Waldron\n2013-12-18: The first release you can stand on"
255
+ assert_equal 6, metadata.size
256
+ assert_equal '2013-12-18', metadata['revdate']
257
+ assert_equal 'The first release you can stand on', metadata['revremark']
258
+ end
259
+
260
+ test "test_skip_line_comments_before_author" do
261
+ metadata, = parse_header_metadata "// Asciidoctor\n// release artist\nRyan Waldron"
262
+ assert_equal 4, metadata.size
263
+ assert_equal 'Ryan Waldron', metadata['author']
264
+ assert_equal 'Ryan', metadata['firstname']
265
+ assert_equal 'Waldron', metadata['lastname']
266
+ assert_equal 'RW', metadata['authorinitials']
267
+ end
268
+
269
+ test "test_skip_block_comment_before_author" do
270
+ metadata, = parse_header_metadata "////\nAsciidoctor\nrelease artist\n////\nRyan Waldron"
271
+ assert_equal 4, metadata.size
272
+ assert_equal 'Ryan Waldron', metadata['author']
273
+ assert_equal 'Ryan', metadata['firstname']
274
+ assert_equal 'Waldron', metadata['lastname']
275
+ assert_equal 'RW', metadata['authorinitials']
276
+ end
277
+
278
+ test "test_skip_block_comment_before_rev" do
279
+ metadata, = parse_header_metadata "Ryan Waldron\n////\nAsciidoctor\nrelease info\n////\nv0.0.7, 2013-12-18"
280
+ assert_equal 6, metadata.size
281
+ assert_equal 'Ryan Waldron', metadata['author']
282
+ assert_equal '0.0.7', metadata['revnumber']
283
+ assert_equal '2013-12-18', metadata['revdate']
284
+ end
285
+
66
286
  end
@@ -1,9 +1,150 @@
1
1
  require 'test_helper'
2
2
 
3
- context "Links" do
3
+ context 'Links' do
4
4
 
5
- test "absolute url with link prefix" do
6
- assert_xpath "//a[@href='http://asciidoc.org']", render_string("We're parsing link:http://asciidoc.org[AsciiDoc] markup")
5
+ test 'qualified url inline with text' do
6
+ assert_xpath "//a[@href='http://asciidoc.org'][text() = 'http://asciidoc.org']", render_string("The AsciiDoc project is located at http://asciidoc.org.")
7
+ end
8
+
9
+ test 'qualified url with label' do
10
+ assert_xpath "//a[@href='http://asciidoc.org'][text() = 'AsciiDoc']", render_string("We're parsing http://asciidoc.org[AsciiDoc] markup")
11
+ end
12
+
13
+ test 'qualified url with label containing escaped right square bracket' do
14
+ assert_xpath "//a[@href='http://asciidoc.org'][text() = '[Ascii]Doc']", render_string("We're parsing http://asciidoc.org[[Ascii\\]Doc] markup")
15
+ end
16
+
17
+ test 'qualified url with label using link macro' do
18
+ assert_xpath "//a[@href='http://asciidoc.org'][text() = 'AsciiDoc']", render_string("We're parsing link:http://asciidoc.org[AsciiDoc] markup")
19
+ end
20
+
21
+ test 'qualified url using macro syntax with multi-line label inline with text' do
22
+ assert_xpath %{//a[@href='http://asciidoc.org'][text() = 'AsciiDoc\nmarkup']}, render_string("We're parsing link:http://asciidoc.org[AsciiDoc\nmarkup]")
23
+ end
24
+
25
+ test 'qualified url surrounded by angled brackets' do
26
+ assert_xpath '//a[@href="http://asciidoc.org"][text()="http://asciidoc.org"]', render_string('<http://asciidoc.org> is the project page for AsciiDoc.'), 1
27
+ end
28
+
29
+ test 'qualified url surrounded by round brackets' do
30
+ assert_xpath '//a[@href="http://asciidoc.org"][text()="http://asciidoc.org"]', render_string('(http://asciidoc.org) is the project page for AsciiDoc.'), 1
31
+ end
32
+
33
+ test 'qualified url adjacent to text in square brackets' do
34
+ assert_xpath '//a[@href="http://asciidoc.org"][text()="AsciiDoc"]', render_string(']http://asciidoc.org[AsciiDoc] project page.'), 1
35
+ end
36
+
37
+ test 'qualified url adjacent to text in round brackets' do
38
+ assert_xpath '//a[@href="http://asciidoc.org"][text()="AsciiDoc"]', render_string(')http://asciidoc.org[AsciiDoc] project page.'), 1
39
+ end
40
+
41
+ test 'qualified url using invalid link macro should not create link' do
42
+ assert_xpath '//a', render_string('link:http://asciidoc.org is the project page for AsciiDoc.'), 0
43
+ end
44
+
45
+ test 'escaped inline qualified url should not create link' do
46
+ assert_xpath '//a', render_string('\http://asciidoc.org is the project page for AsciiDoc.'), 0
47
+ end
48
+
49
+ test 'escaped inline qualified url using macro syntax should not create link' do
50
+ assert_xpath '//a', render_string('\http://asciidoc.org[AsciiDoc] is the key to good docs.'), 0
51
+ end
52
+
53
+ test 'qualified url containing whitespace using macro syntax should not create link' do
54
+ assert_xpath '//a', render_string('I often need to refer to the chapter on link:http://asciidoc.org?q=attribute references[Attribute References].'), 0
55
+ end
56
+
57
+ test 'qualified url containing an encoded space using macro syntax should create a link' do
58
+ assert_xpath '//a', render_string('I often need to refer to the chapter on link:http://asciidoc.org?q=attribute%20references[Attribute References].'), 1
59
+ end
60
+
61
+ test 'inline ref' do
62
+ doc = document_from_string 'Here you can read about tigers.[[tigers]]'
63
+ output = doc.render
64
+ assert_equal '[tigers]', doc.references[:ids]['tigers']
65
+ assert_xpath '//a[@id = "tigers"]', output, 1
66
+ assert_xpath '//a[@id = "tigers"]/child::text()', output, 0
67
+ end
68
+
69
+ test 'inline ref with reftext' do
70
+ doc = document_from_string 'Here you can read about tigers.[[tigers,Tigers]]'
71
+ output = doc.render
72
+ assert_equal 'Tigers', doc.references[:ids]['tigers']
73
+ assert_xpath '//a[@id = "tigers"]', output, 1
74
+ assert_xpath '//a[@id = "tigers"]/child::text()', output, 0
75
+ end
76
+
77
+ test 'escaped inline ref' do
78
+ doc = document_from_string 'Here you can read about tigers.\[[tigers]]'
79
+ output = doc.render
80
+ assert !doc.references[:ids].has_key?('tigers')
81
+ assert_xpath '//a[@id = "tigers"]', output, 0
82
+ end
83
+
84
+ test 'xref using angled bracket syntax' do
85
+ doc = document_from_string '<<tigers>>'
86
+ doc.references[:ids]['tigers'] = '[tigers]'
87
+ assert_xpath '//a[@href="#tigers"][text() = "[tigers]"]', doc.render, 1
88
+ end
89
+
90
+ test 'xref using angled bracket syntax with label' do
91
+ assert_xpath '//a[@href="#tigers"][text() = "About Tigers"]', render_string('<<tigers,About Tigers>>'), 1
92
+ end
93
+
94
+ test 'xref using angled bracket syntax with quoted label' do
95
+ assert_xpath '//a[@href="#tigers"][text() = "About Tigers"]', render_string('<<tigers,"About Tigers">>'), 1
96
+ end
97
+
98
+ test 'xref using angled bracket syntax inline with text' do
99
+ assert_xpath '//a[@href="#tigers"][text() = "about tigers"]', render_string('Want to learn <<tigers,about tigers>>?'), 1
100
+ end
101
+
102
+ test 'xref using angled bracket syntax with multi-line label inline with text' do
103
+ assert_xpath %{//a[@href="#tigers"][text() = "about\ntigers"]}, render_string("Want to learn <<tigers,about\ntigers>>?"), 1
104
+ end
105
+
106
+ test 'xref using macro syntax' do
107
+ doc = document_from_string 'xref:tigers[]'
108
+ doc.references[:ids]['tigers'] = '[tigers]'
109
+ assert_xpath '//a[@href="#tigers"][text() = "[tigers]"]', doc.render, 1
110
+ end
111
+
112
+ test 'xref using macro syntax with label' do
113
+ assert_xpath '//a[@href="#tigers"][text() = "About Tigers"]', render_string('xref:tigers[About Tigers]'), 1
114
+ end
115
+
116
+ test 'xref using macro syntax inline with text' do
117
+ assert_xpath '//a[@href="#tigers"][text() = "about tigers"]', render_string('Want to learn xref:tigers[about tigers]?'), 1
118
+ end
119
+
120
+ test 'xref using macro syntax with multi-line label inline with text' do
121
+ assert_xpath %{//a[@href="#tigers"][text() = "about\ntigers"]}, render_string("Want to learn xref:tigers[about\ntigers]?"), 1
122
+ end
123
+
124
+ test 'xref using invalid macro syntax does not create link' do
125
+ doc = document_from_string 'xref:tigers'
126
+ doc.references[:ids]['tigers'] = '[tigers]'
127
+ assert_xpath '//a', doc.render, 0
128
+ end
129
+
130
+ test 'xref creates link for unknown reference' do
131
+ doc = document_from_string '<<tigers>>'
132
+ assert_xpath '//a[@href="#tigers"][text() = "[tigers]"]', doc.render, 1
133
+ end
134
+
135
+ test 'anchor creates reference' do
136
+ doc = document_from_string "[[tigers]]Tigers roam here."
137
+ assert_equal({'tigers' => '[tigers]'}, doc.references[:ids])
138
+ end
139
+
140
+ test 'anchor with label creates reference' do
141
+ doc = document_from_string "[[tigers,Tigers]]Tigers roam here."
142
+ assert_equal({'tigers' => 'Tigers'}, doc.references[:ids])
143
+ end
144
+
145
+ test 'anchor with quoted label creates reference' do
146
+ doc = document_from_string %([["tigers","Tigers roam here"]]Tigers roam here.)
147
+ assert_equal({'tigers' => "Tigers roam here"}, doc.references[:ids])
7
148
  end
8
149
 
9
150
  end