summaryrefslogtreecommitdiff
path: root/test/reader_test.rb
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2022-02-28 00:27:35 -0700
committerDan Allen <dan.j.allen@gmail.com>2022-10-14 21:26:49 -0600
commitcd1f810b13cde5d959abf0e46af64ae299d78c33 (patch)
tree567336f7baf44f899591c8862bb6b6a6b7710eb8 /test/reader_test.rb
parent58cac859ccf284a0802f26af2a60360300bed4a8 (diff)
add include role to link/URL macro that replaces include directive when include is not enabled
Diffstat (limited to 'test/reader_test.rb')
-rw-r--r--test/reader_test.rb35
1 files changed, 31 insertions, 4 deletions
diff --git a/test/reader_test.rb b/test/reader_test.rb
index 718ad4fa..9014fa1f 100644
--- a/test/reader_test.rb
+++ b/test/reader_test.rb
@@ -666,11 +666,38 @@ class ReaderTest < Minitest::Test
end
context 'Include Directive' do
- test 'include directive is disabled by default and becomes a link' do
+ test 'should replace include directive with link macro in default safe mode' do
input = 'include::include-file.adoc[]'
doc = Asciidoctor::Document.new input
reader = doc.reader
- assert_equal 'link:include-file.adoc[]', reader.read_line
+ assert_equal 'link:include-file.adoc[role=include]', reader.read_line
+ end
+
+ test 'should preserve attrlist when replacing include directive with link macro' do
+ input = 'include::include-file.adoc[leveloffset=+1]'
+ doc = Asciidoctor::Document.new input
+ reader = doc.reader
+ assert_equal 'link:include-file.adoc[role=include,leveloffset=+1]', reader.read_line
+ end
+
+ test 'should replace include directive with link macro if safe mode allows it, but allow-uri-read is not set' do
+ using_memory_logger do |logger|
+ input = 'include::https://example.org/dist/info.adoc[]'
+ doc = Asciidoctor::Document.new input, safe: :safe
+ reader = doc.reader
+ assert_equal 'link:https://example.org/dist/info.adoc[role=include]', reader.read_line
+ assert_message logger, :WARN, '<stdin>: line 1: cannot include contents of URI: https://example.org/dist/info.adoc (allow-uri-read attribute not enabled)', Hash
+ end
+ end
+
+ test 'should preserve attrlist when replacing remove include directive with link macro' do
+ using_memory_logger do |logger|
+ input = 'include::https://example.org/dist/info.adoc[leveloffset=+1]'
+ doc = Asciidoctor::Document.new input, safe: :safe
+ reader = doc.reader
+ assert_equal 'link:https://example.org/dist/info.adoc[role=include,leveloffset=+1]', reader.read_line
+ assert_message logger, :WARN, '<stdin>: line 1: cannot include contents of URI: https://example.org/dist/info.adoc (allow-uri-read attribute not enabled)', Hash
+ end
end
test 'include directive with remote target is converted to a link when allow-uri-read is not set' do
@@ -678,7 +705,7 @@ class ReaderTest < Minitest::Test
input = 'include::http://example.org/team.adoc[]'
doc = Asciidoctor::Document.new input, safe: :safe
reader = doc.reader
- assert_equal 'link:http://example.org/team.adoc[]', reader.read_line
+ assert_equal 'link:http://example.org/team.adoc[role=include]', reader.read_line
assert_message logger, :WARN, '<stdin>: line 1: cannot include contents of URI: http://example.org/team.adoc (allow-uri-read attribute not enabled)', Hash
end
end
@@ -688,7 +715,7 @@ class ReaderTest < Minitest::Test
input = 'include::http://example.org/team.adoc[]'
doc = Asciidoctor::Document.new input, safe: :secure
reader = doc.reader
- assert_equal 'link:http://example.org/team.adoc[]', reader.read_line
+ assert_equal 'link:http://example.org/team.adoc[role=include]', reader.read_line
assert_empty logger.messages
end
end