summaryrefslogtreecommitdiff
path: root/test/reader_test.rb
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2017-05-18 23:54:16 -0600
committerGitHub <noreply@github.com>2017-05-18 23:54:16 -0600
commit3114709d3ea712bf26b1209211e5644a4cf5c295 (patch)
treee622157bc5d3a5876c42676efd0fc3b46f1969d5 /test/reader_test.rb
parent9b68c2ed15fb340c7c5f320b5bc761c6ef9a7d9f (diff)
resolves #1516 add option to exclude tags when including file (PR #2196)
- in addition to including tags, add option to exclude tags using !name syntax - introduce wildcard for including all (*) or excluding all (!*) tags - introduce wildcard for selecting non-tagged lines (**) - don't select nested tags with wildcard if ancestor tag is excluded - warn if a mismatched or unexpected end tag is found - improve efficiency of detecting and processing tag directives - maintain a tag stack for handling nested tags - skip call to push_include if selected lines array is empty - ignore tag and tags attribute if empty (previously caused an infinite loop) - add tests for excluding tags
Diffstat (limited to 'test/reader_test.rb')
-rw-r--r--test/reader_test.rb159
1 files changed, 159 insertions, 0 deletions
diff --git a/test/reader_test.rb b/test/reader_test.rb
index 790b6980..47b5b64e 100644
--- a/test/reader_test.rb
+++ b/test/reader_test.rb
@@ -792,6 +792,137 @@ snippetB content)
assert_equal expect, output
end
+ test 'include directive skips lines marked with negated tags' do
+ input = <<-EOS
+----
+include::fixtures/tagged-class-enclosed.rb[tags=all;!bark]
+----
+ EOS
+
+ output = render_embedded_string input, :safe => :safe, :base_dir => DIRNAME
+ expected = %(class Dog
+ def initialize breed
+ @breed = breed
+ end
+end)
+ assert_includes output, expected
+ end
+
+ test 'include directive takes all lines without tag directives when value is double asterisk' do
+ input = <<-EOS
+----
+include::fixtures/tagged-class.rb[tags=**]
+----
+ EOS
+
+ output = render_embedded_string input, :safe => :safe, :base_dir => DIRNAME
+ expected = %(class Dog
+ def initialize breed
+ @breed = breed
+ end
+
+ def bark
+ if @breed == 'beagle'
+ 'woof woof woof woof woof'
+ else
+ 'woof woof'
+ end
+ end
+end)
+ assert_includes output, expected
+ end
+
+ test 'include directive takes all lines except negated tags when value contains double asterisk' do
+ input = <<-EOS
+----
+include::fixtures/tagged-class.rb[tags=**;!bark]
+----
+ EOS
+
+ output = render_embedded_string input, :safe => :safe, :base_dir => DIRNAME
+ expected = %(class Dog
+ def initialize breed
+ @breed = breed
+ end
+end)
+ assert_includes output, expected
+ end
+
+ test 'include directive selects lines for all tags when value of tags attribute is wildcard' do
+ input = <<-EOS
+----
+include::fixtures/tagged-class-enclosed.rb[tags=*]
+----
+ EOS
+
+ output = render_embedded_string input, :safe => :safe, :base_dir => DIRNAME
+ expected = %(class Dog
+ def initialize breed
+ @breed = breed
+ end
+
+ def bark
+ if @breed == 'beagle'
+ 'woof woof woof woof woof'
+ else
+ 'woof woof'
+ end
+ end
+end)
+ assert_includes output, expected
+ end
+
+ test 'include directive selects lines for all tags except exclusions when value of tags attribute is wildcard' do
+ input = <<-EOS
+----
+include::fixtures/tagged-class-enclosed.rb[tags=*;!init]
+----
+ EOS
+
+ output = render_embedded_string input, :safe => :safe, :base_dir => DIRNAME
+ expected = %(class Dog
+
+ def bark
+ if @breed == 'beagle'
+ 'woof woof woof woof woof'
+ else
+ 'woof woof'
+ end
+ end
+end)
+ assert_includes output, expected
+ end
+
+ test 'include directive skips lines all tagged lines when value of tags attribute is negated wildcard' do
+ input = <<-EOS
+----
+include::fixtures/tagged-class.rb[tags=!*]
+----
+ EOS
+
+ output = render_embedded_string input, :safe => :safe, :base_dir => DIRNAME
+ expected = %(class Dog
+end)
+ assert_includes output, expected
+ end
+
+ test 'include directive selects specified tagged lines and ignores the other tag directives' do
+ input = <<-EOS
+[indent=0]
+----
+include::fixtures/tagged-class.rb[tags=bark;!bark-other]
+----
+ EOS
+
+ output = render_embedded_string input, :safe => :safe, :base_dir => DIRNAME
+ expected = %(def bark
+ if @breed == 'beagle'
+ 'woof woof woof woof woof'
+ end
+end)
+ assert_includes output, expected
+ end
+
test 'should warn if tag is not found in include file' do
input = <<-EOS
include::fixtures/include-file.asciidoc[tag=snippetZ]
@@ -809,6 +940,34 @@ include::fixtures/include-file.asciidoc[tag=snippetZ]
end
end
+ test 'should warn if end tag in included file is mismatched' do
+ input = <<-EOS
+++++
+include::fixtures/mismatched-end-tag.adoc[tags=a;b]
+++++
+ EOS
+
+ result, warnings = redirect_streams do |out, err|
+ [(render_embedded_string input, :safe => :safe, :base_dir => DIRNAME), err.string]
+ end
+ assert_equal %(a\nb), result
+ refute_nil warnings
+ assert_match(/WARNING: .*end tag/, warnings)
+ end
+
+ test 'include directive ignores tags attribute when empty' do
+ ['tag', 'tags'].each do |attr_name|
+ input = <<-EOS
+++++
+include::fixtures/include-file.xml[#{attr_name}=]
+++++
+ EOS
+
+ output = render_embedded_string input, :safe => :safe, :base_dir => DIRNAME
+ assert_match(/(?:tag|end)::/, output, 2)
+ end
+ end
+
test 'lines attribute takes precedence over tags attribute in include directive' do
input = <<-EOS
include::fixtures/include-file.asciidoc[lines=1, tags=snippetA;snippetB]