Skip to content

Commit

Permalink
resolves #4230 don't warn if a negated tag is not found in include fi…
Browse files Browse the repository at this point in the history
…le (PR #4233)
  • Loading branch information
mojavelinux committed Jan 5, 2022
1 parent 9acb683 commit 305bd71
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Improvements::
* Sort levels in help for `--failure-level` option in ascending order
* Invert FR translations for caution & warning admonition labels (#4212) (*cyChop*)
* Add tests for open-uri-cached integration that is activated by the `cache-uri` attribute
* Don't warn if negated tag is not found in include file (#4230)

Documentation::

Expand Down
8 changes: 4 additions & 4 deletions lib/asciidoctor/reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,7 @@ def preprocess_include_directive target, attrlist
push_include inc_lines, inc_path, relpath, inc_offset, parsed_attrs
end
elsif inc_tags
inc_lines, inc_offset, inc_lineno, tag_stack, tags_used, active_tag = [], nil, 0, [], ::Set.new, nil
inc_lines, inc_offset, inc_lineno, tag_stack, tags_selected, active_tag = [], nil, 0, [], ::Set.new, nil
if inc_tags.key? '**'
select = base_select = inc_tags.delete '**'
if inc_tags.key? '*'
Expand Down Expand Up @@ -1164,9 +1164,9 @@ def preprocess_include_directive target, attrlist
end
end
elsif inc_tags.key? this_tag
tags_used << this_tag
tags_selected << this_tag if (select = inc_tags[this_tag])
# QUESTION should we prevent tag from being selected when enclosing tag is excluded?
tag_stack << [(active_tag = this_tag), (select = inc_tags[this_tag]), inc_lineno]
tag_stack << [(active_tag = this_tag), select, inc_lineno]
elsif !wildcard.nil?
select = active_tag && !select ? false : wildcard
tag_stack << [(active_tag = this_tag), select, inc_lineno]
Expand All @@ -1187,7 +1187,7 @@ def preprocess_include_directive target, attrlist
logger.warn message_with_context %(detected unclosed tag '#{tag_name}' starting at line #{tag_lineno} of include #{target_type}: #{inc_path}), source_location: cursor, include_location: (create_include_cursor inc_path, expanded_target, tag_lineno)
end
end
unless (missing_tags = inc_tags.keys - tags_used.to_a).empty?
unless (missing_tags = inc_tags.keep_if {|_, v| v }.keys - tags_selected.to_a).empty?
logger.warn message_with_context %(tag#{missing_tags.size > 1 ? 's' : ''} '#{missing_tags.join ', '}' not found in include #{target_type}: #{inc_path}), source_location: cursor
end
shift
Expand Down
56 changes: 56 additions & 0 deletions test/reader_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1658,6 +1658,34 @@ def bark
end
end

test 'should not warn if specified negated tag is not found in include file' do
input = <<~'EOS'
----
include::fixtures/tagged-class-enclosed.rb[tag=!no-such-tag]
----
EOS
expected = <<~EOS.chop
class Dog
def initialize breed
@breed = breed
end
def bark
if @breed == 'beagle'
'woof woof woof woof woof'
else
'woof woof'
end
end
end
EOS
using_memory_logger do |logger|
output = convert_string_to_embedded input, safe: :safe, base_dir: DIRNAME
assert_includes output, %(<pre>#{expected}</pre>)
assert_empty logger.messages
end
end

test 'should warn if specified tags are not found in include file' do
input = <<~'EOS'
++++
Expand All @@ -1672,6 +1700,34 @@ def bark
end
end

test 'should not warn if specified negated tags are not found in include file' do
input = <<~'EOS'
----
include::fixtures/tagged-class-enclosed.rb[tags=all;!no-such-tag;!unknown-tag]
----
EOS
expected = <<~EOS.chop
class Dog
def initialize breed
@breed = breed
end
def bark
if @breed == 'beagle'
'woof woof woof woof woof'
else
'woof woof'
end
end
end
EOS
using_memory_logger do |logger|
output = convert_string_to_embedded input, safe: :safe, base_dir: DIRNAME
assert_includes output, %(<pre>#{expected}</pre>)
assert_empty logger.messages
end
end

test 'should warn if specified tag in include file is not closed' do
input = <<~'EOS'
++++
Expand Down

0 comments on commit 305bd71

Please sign in to comment.