summaryrefslogtreecommitdiff
path: root/test/sections_test.rb
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2019-02-19 02:10:40 -0700
committerGitHub <noreply@github.com>2019-02-19 02:10:40 -0700
commit67b2b50156b778e494f3517d25cd6a2d7d550737 (patch)
treed1a85b7d035ee161d5782a7b6ed74aefd2425610 /test/sections_test.rb
parentaa2216063413ffb75e0d130cff72f2bad69e1448 (diff)
resolves #3084 only store :refs, not :ids, in document catalog (PR #3079)
* remove the logic that registers entries in :ids table of the document catalog * don't attempt to compute the reftext when registering an xref (as this information is available from the referenced node and can be retrieved on demnd) * add a Document#resolve_id method to look up ID by reference text (reftext or title); cache the result of lookups once parsing is complete * always look for existing IDs using :refs table (when checking for a duplicate or whether a target exists) * leave the :ids table empty to avoid breaking existing programs and extensions * update tests * add test to verify :ids table is always empty
Diffstat (limited to 'test/sections_test.rb')
-rw-r--r--test/sections_test.rb71
1 files changed, 45 insertions, 26 deletions
diff --git a/test/sections_test.rb b/test/sections_test.rb
index 1575731c..9bbfe4b7 100644
--- a/test/sections_test.rb
+++ b/test/sections_test.rb
@@ -245,9 +245,11 @@ context 'Sections' do
EOS
doc = document_from_string input
- reftext = doc.catalog[:ids]['install']
- refute_nil reftext
- assert_equal 'Install Procedure', reftext
+ ref = doc.catalog[:refs]['install']
+ refute_nil ref
+ assert_equal 'Install Procedure', ref.reftext
+ #assert_equal 'install', doc.catalog[:reftexts]['Install Procedure']
+ assert_equal 'install', (doc.resolve_id 'Install Procedure')
end
test 'should use specified reftext when registering section reference' do
@@ -259,9 +261,11 @@ context 'Sections' do
EOS
doc = document_from_string input
- reftext = doc.catalog[:ids]['_install']
- refute_nil reftext
- assert_equal 'Install Procedure', reftext
+ ref = doc.catalog[:refs]['_install']
+ refute_nil ref
+ assert_equal 'Install Procedure', ref.reftext
+ #assert_equal '_install', doc.catalog[:reftexts]['Install Procedure']
+ assert_equal '_install', (doc.resolve_id 'Install Procedure')
end
test 'should substitute attributes when registering reftext for section' do
@@ -275,9 +279,11 @@ context 'Sections' do
EOS
doc = document_from_string input
- reftext = doc.catalog[:ids]['install']
- refute_nil reftext
- assert_equal 'install on Linux', reftext
+ ref = doc.catalog[:refs]['install']
+ refute_nil ref
+ assert_equal 'install on Linux', ref.reftext
+ #assert_equal 'install', doc.catalog[:reftexts]['install on Linux']
+ assert_equal 'install', (doc.resolve_id 'install on Linux')
end
test 'duplicate section id should not overwrite existing section id entry in references table' do
@@ -295,9 +301,12 @@ context 'Sections' do
using_memory_logger do |logger|
doc = document_from_string input
- reftext = doc.catalog[:ids]['install']
- refute_nil reftext
- assert_equal 'First Install', reftext
+ ref = doc.catalog[:refs]['install']
+ refute_nil ref
+ assert_nil ref.reftext
+ assert_equal 'First Install', ref.title
+ #assert_equal 'install', doc.catalog[:reftexts]['First Install']
+ assert_equal 'install', (doc.resolve_id 'First Install')
assert_message logger, :WARN, '<stdin>: line 7: id assigned to section already in use: install', Hash
end
end
@@ -316,9 +325,12 @@ context 'Sections' do
using_memory_logger do |logger|
doc = document_from_string input
- reftext = doc.catalog[:ids]['_do_not_repeat_yourself']
- refute_nil reftext
- assert_equal 'Do Not Repeat Yourself', reftext
+ ref = doc.catalog[:refs]['_do_not_repeat_yourself']
+ refute_nil ref
+ assert_nil ref.reftext
+ assert_equal 'Do Not Repeat Yourself', ref.title
+ #assert_equal '_do_not_repeat_yourself', doc.catalog[:reftexts]['Do Not Repeat Yourself']
+ assert_equal '_do_not_repeat_yourself', (doc.resolve_id 'Do Not Repeat Yourself')
assert_message logger, :WARN, '<stdin>: line 6: id assigned to section already in use: _do_not_repeat_yourself', Hash
assert_equal 2, (doc.convert.scan 'id="_do_not_repeat_yourself"').size
end
@@ -337,9 +349,12 @@ context 'Sections' do
using_memory_logger do |logger|
doc = document_from_string input
- reftext = doc.catalog[:ids]['install']
- refute_nil reftext
- assert_equal 'First Install', reftext
+ ref = doc.catalog[:refs]['install']
+ refute_nil ref
+ assert_nil ref.reftext
+ assert_equal 'First Install', ref.title
+ #assert_equal 'install', doc.catalog[:reftexts]['First Install']
+ assert_equal 'install', (doc.resolve_id 'First Install')
assert_message logger, :WARN, '<stdin>: line 7: id assigned to block already in use: install', Hash
end
end
@@ -1022,7 +1037,7 @@ context 'Sections' do
assert_kind_of Asciidoctor::Block, heading
assert_equal :floating_title, heading.context
assert_equal '_independent_heading', heading.id
- assert doc.catalog[:ids].has_key?('_independent_heading')
+ assert doc.catalog[:refs].key? '_independent_heading'
end
test 'should preprocess second line of setext discrete heading' do
@@ -1049,7 +1064,7 @@ context 'Sections' do
doc = document_from_string input
heading = doc.blocks.first
assert_equal 'unchained', heading.id
- assert doc.catalog[:ids].has_key?('unchained')
+ assert doc.catalog[:refs].key? 'unchained'
end
test 'should not include discrete heading in toc' do
@@ -1137,9 +1152,11 @@ context 'Sections' do
EOS
doc = document_from_string input
- reftext = doc.catalog[:ids]['install']
- refute_nil reftext
- assert_equal 'Install Procedure', reftext
+ ref = doc.catalog[:refs]['install']
+ refute_nil ref
+ assert_equal 'Install Procedure', ref.reftext
+ #assert_equal 'install', doc.catalog[:reftexts]['Install Procedure']
+ assert_equal 'install', (doc.resolve_id 'Install Procedure')
end
test 'should use specified reftext when registering discrete section reference' do
@@ -1152,9 +1169,11 @@ context 'Sections' do
EOS
doc = document_from_string input
- reftext = doc.catalog[:ids]['_install']
- refute_nil reftext
- assert_equal 'Install Procedure', reftext
+ ref = doc.catalog[:refs]['_install']
+ refute_nil ref
+ assert_equal 'Install Procedure', ref.reftext
+ #assert_equal '_install', doc.catalog[:reftexts]['Install Procedure']
+ assert_equal '_install', (doc.resolve_id 'Install Procedure')
end
test 'should not process inline anchor in discrete heading if explicit ID is assigned' do