summaryrefslogtreecommitdiff
path: root/test/sections_test.rb
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2021-09-01 01:53:53 -0600
committerDan Allen <dan.j.allen@gmail.com>2021-09-01 01:53:53 -0600
commit67f41d033bc0deb2435e82b0d498c45c32902c4e (patch)
tree891888c1c7860c13b3c3a1baca55e4eae0948337 /test/sections_test.rb
parentf405e335f70de857538070795c63d5e0eb8ad304 (diff)
add test to verify title of section with explicit ID and attribute references is eagerly substituted
Diffstat (limited to 'test/sections_test.rb')
-rw-r--r--test/sections_test.rb45
1 files changed, 45 insertions, 0 deletions
diff --git a/test/sections_test.rb b/test/sections_test.rb
index e55b1cea..6b699675 100644
--- a/test/sections_test.rb
+++ b/test/sections_test.rb
@@ -195,6 +195,51 @@ context 'Sections' do
assert_equal 'Section One <a id="one"></a>', sec.title
end
+ test 'should apply substititons to title with attribute references when registering section with auto-generated ID' do
+ input = <<~'EOS'
+ = Document Title
+ :foo: bar
+
+ See <<_section_baz>>.
+
+ :foo: baz
+
+ == Section {foo}
+
+ That's all, folks!
+ EOS
+
+ doc = document_from_string input
+ ref = doc.catalog[:refs]['_section_baz']
+ refute_nil ref
+ output = doc.convert standalone: false
+ assert_xpath '//a[@href="#_section_baz"][text()="Section baz"]', output, 1
+ assert_xpath '//h2[@id="_section_baz"][text()="Section baz"]', output, 1
+ end
+
+ test 'should apply substititons to title with attribute references when registering section with explicit ID' do
+ input = <<~'EOS'
+ = Document Title
+ :foo: bar
+
+ See <<explicit>>.
+
+ :foo: baz
+
+ [#explicit]
+ == Section {foo}
+
+ That's all, folks!
+ EOS
+
+ doc = document_from_string input
+ ref = doc.catalog[:refs]['explicit']
+ refute_nil ref
+ output = doc.convert standalone: false
+ assert_xpath '//a[@href="#explicit"][text()="Section baz"]', output, 1
+ assert_xpath '//h2[@id="explicit"][text()="Section baz"]', output, 1
+ end
+
test 'title substitutions are applied before generating id' do
sec = block_from_string "== Section{sp}One\n"
assert_equal '_section_one', sec.id