summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2013-08-21 20:34:53 -0600
committerDan Allen <dan.j.allen@gmail.com>2013-08-21 20:40:12 -0600
commit14fcb5e8667e4dd227597dc61fb32bdbfff9812d (patch)
tree29ca6486592192680dc727dc7f23b5237ef6e4b1
parenta389b27c4a55ced78713248ee801cb2c72943059 (diff)
add test for depth set on include in nested file
-rw-r--r--asciidoctor.gemspec2
-rw-r--r--lib/asciidoctor/lexer.rb4
-rw-r--r--test/fixtures/child-include.adoc2
-rw-r--r--test/fixtures/grandchild-include.adoc3
-rw-r--r--test/fixtures/parent-include-restricted.adoc5
-rw-r--r--test/reader_test.rb29
6 files changed, 44 insertions, 1 deletions
diff --git a/asciidoctor.gemspec b/asciidoctor.gemspec
index 92772d4f..d322f90a 100644
--- a/asciidoctor.gemspec
+++ b/asciidoctor.gemspec
@@ -95,6 +95,7 @@ EOS
test/fixtures/basic-docinfo.html
test/fixtures/basic-docinfo.xml
test/fixtures/basic.asciidoc
+ test/fixtures/child-include.adoc
test/fixtures/custom-backends/haml/docbook45/block_paragraph.xml.haml
test/fixtures/custom-backends/haml/html5-tweaks/block_paragraph.html.haml
test/fixtures/custom-backends/haml/html5/block_paragraph.html.haml
@@ -110,6 +111,7 @@ EOS
test/fixtures/encoding.asciidoc
test/fixtures/include-file.asciidoc
test/fixtures/list_elements.asciidoc
+ test/fixtures/parent-include.adoc
test/fixtures/sample.asciidoc
test/fixtures/stylesheets/custom.css
test/fixtures/tip.gif
diff --git a/lib/asciidoctor/lexer.rb b/lib/asciidoctor/lexer.rb
index 48e8e035..d25ba6b0 100644
--- a/lib/asciidoctor/lexer.rb
+++ b/lib/asciidoctor/lexer.rb
@@ -1153,7 +1153,7 @@ class Lexer
if continuation == :inactive
continuation = :active
has_text = true
- buffer[-1] = "\n" unless within_nested_list
+ buffer[-1] = ::Asciidoctor::EOL unless within_nested_list
end
# dealing with adjacent list continuations (which is really a syntax error)
@@ -2327,6 +2327,8 @@ class Lexer
# # => end
#
# returns the Array of String lines with block offset removed
+ #--
+ # FIXME refactor gsub matchers into compiled regex
def self.reset_block_indent!(lines, indent = 0)
return if indent.nil? || lines.empty?
diff --git a/test/fixtures/child-include.adoc b/test/fixtures/child-include.adoc
index d47011d3..77c18c1d 100644
--- a/test/fixtures/child-include.adoc
+++ b/test/fixtures/child-include.adoc
@@ -1,3 +1,5 @@
first line of child
+include::grandchild-include.adoc[]
+
last line of child
diff --git a/test/fixtures/grandchild-include.adoc b/test/fixtures/grandchild-include.adoc
new file mode 100644
index 00000000..31016999
--- /dev/null
+++ b/test/fixtures/grandchild-include.adoc
@@ -0,0 +1,3 @@
+first line of grandchild
+
+last line of grandchild
diff --git a/test/fixtures/parent-include-restricted.adoc b/test/fixtures/parent-include-restricted.adoc
new file mode 100644
index 00000000..a3cf2a26
--- /dev/null
+++ b/test/fixtures/parent-include-restricted.adoc
@@ -0,0 +1,5 @@
+first line of parent
+
+include::child-include.adoc[depth=1]
+
+last line of parent
diff --git a/test/reader_test.rb b/test/reader_test.rb
index e5c1a155..7e195b3f 100644
--- a/test/reader_test.rb
+++ b/test/reader_test.rb
@@ -434,6 +434,7 @@ include::fixtures/parent-include.adoc[]
fixtures_dir = File.join DIRNAME, 'fixtures'
parent_include_docfile = File.join fixtures_dir, 'parent-include.adoc'
child_include_docfile = File.join fixtures_dir, 'child-include.adoc'
+ grandchild_include_docfile = File.join fixtures_dir, 'grandchild-include.adoc'
doc = empty_safe_document :base_dir => DIRNAME
reader = Asciidoctor::PreprocessorReader.new doc, input, pseudo_docfile
@@ -460,6 +461,19 @@ include::fixtures/parent-include.adoc[]
reader.skip_blank_lines
+ assert_equal "first line of grandchild\n", reader.read_line
+
+ assert_equal 'fixtures/grandchild-include.adoc: line 1', reader.prev_line_info
+ assert_equal grandchild_include_docfile, reader.file
+ assert_equal fixtures_dir, reader.dir
+ assert_equal 'fixtures/grandchild-include.adoc', reader.path
+
+ reader.skip_blank_lines
+
+ assert_equal "last line of grandchild\n", reader.read_line
+
+ reader.skip_blank_lines
+
assert_equal "last line of child\n", reader.read_line
reader.skip_blank_lines
@@ -706,6 +720,21 @@ include::fixtures/parent-include.adoc[depth=1]
assert lines.include?("include::child-include.adoc[]\n")
end
+ test 'include macro should be disabled if max include depth set in nested context has been exceeded' do
+ input = <<-EOS
+include::fixtures/parent-include-restricted.adoc[depth=3]
+ EOS
+
+ pseudo_docfile = File.join DIRNAME, 'include-master.adoc'
+
+ doc = empty_safe_document :base_dir => DIRNAME
+ reader = Asciidoctor::PreprocessorReader.new doc, input, Asciidoctor::Reader::Cursor.new(pseudo_docfile)
+
+ lines = reader.readlines
+ assert lines.include?("first line of child\n")
+ assert lines.include?("include::grandchild-include.adoc[]\n")
+ end
+
test 'read_lines_until should not process lines if process option is false' do
lines = <<-EOS.each_line.to_a
////