Skip to content

Commit 305bd71

Browse files
committed
resolves #4230 don't warn if a negated tag is not found in include file (PR #4233)
1 parent 9acb683 commit 305bd71

File tree

3 files changed

+61
-4
lines changed

3 files changed

+61
-4
lines changed

CHANGELOG.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Improvements::
4444
* Sort levels in help for `--failure-level` option in ascending order
4545
* Invert FR translations for caution & warning admonition labels (#4212) (*cyChop*)
4646
* Add tests for open-uri-cached integration that is activated by the `cache-uri` attribute
47+
* Don't warn if negated tag is not found in include file (#4230)
4748

4849
Documentation::
4950

lib/asciidoctor/reader.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,7 +1125,7 @@ def preprocess_include_directive target, attrlist
11251125
push_include inc_lines, inc_path, relpath, inc_offset, parsed_attrs
11261126
end
11271127
elsif inc_tags
1128-
inc_lines, inc_offset, inc_lineno, tag_stack, tags_used, active_tag = [], nil, 0, [], ::Set.new, nil
1128+
inc_lines, inc_offset, inc_lineno, tag_stack, tags_selected, active_tag = [], nil, 0, [], ::Set.new, nil
11291129
if inc_tags.key? '**'
11301130
select = base_select = inc_tags.delete '**'
11311131
if inc_tags.key? '*'
@@ -1164,9 +1164,9 @@ def preprocess_include_directive target, attrlist
11641164
end
11651165
end
11661166
elsif inc_tags.key? this_tag
1167-
tags_used << this_tag
1167+
tags_selected << this_tag if (select = inc_tags[this_tag])
11681168
# QUESTION should we prevent tag from being selected when enclosing tag is excluded?
1169-
tag_stack << [(active_tag = this_tag), (select = inc_tags[this_tag]), inc_lineno]
1169+
tag_stack << [(active_tag = this_tag), select, inc_lineno]
11701170
elsif !wildcard.nil?
11711171
select = active_tag && !select ? false : wildcard
11721172
tag_stack << [(active_tag = this_tag), select, inc_lineno]
@@ -1187,7 +1187,7 @@ def preprocess_include_directive target, attrlist
11871187
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)
11881188
end
11891189
end
1190-
unless (missing_tags = inc_tags.keys - tags_used.to_a).empty?
1190+
unless (missing_tags = inc_tags.keep_if {|_, v| v }.keys - tags_selected.to_a).empty?
11911191
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
11921192
end
11931193
shift

test/reader_test.rb

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1658,6 +1658,34 @@ def bark
16581658
end
16591659
end
16601660

1661+
test 'should not warn if specified negated tag is not found in include file' do
1662+
input = <<~'EOS'
1663+
----
1664+
include::fixtures/tagged-class-enclosed.rb[tag=!no-such-tag]
1665+
----
1666+
EOS
1667+
expected = <<~EOS.chop
1668+
class Dog
1669+
def initialize breed
1670+
@breed = breed
1671+
end
1672+
1673+
def bark
1674+
if @breed == 'beagle'
1675+
'woof woof woof woof woof'
1676+
else
1677+
'woof woof'
1678+
end
1679+
end
1680+
end
1681+
EOS
1682+
using_memory_logger do |logger|
1683+
output = convert_string_to_embedded input, safe: :safe, base_dir: DIRNAME
1684+
assert_includes output, %(<pre>#{expected}</pre>)
1685+
assert_empty logger.messages
1686+
end
1687+
end
1688+
16611689
test 'should warn if specified tags are not found in include file' do
16621690
input = <<~'EOS'
16631691
++++
@@ -1672,6 +1700,34 @@ def bark
16721700
end
16731701
end
16741702

1703+
test 'should not warn if specified negated tags are not found in include file' do
1704+
input = <<~'EOS'
1705+
----
1706+
include::fixtures/tagged-class-enclosed.rb[tags=all;!no-such-tag;!unknown-tag]
1707+
----
1708+
EOS
1709+
expected = <<~EOS.chop
1710+
class Dog
1711+
def initialize breed
1712+
@breed = breed
1713+
end
1714+
1715+
def bark
1716+
if @breed == 'beagle'
1717+
'woof woof woof woof woof'
1718+
else
1719+
'woof woof'
1720+
end
1721+
end
1722+
end
1723+
EOS
1724+
using_memory_logger do |logger|
1725+
output = convert_string_to_embedded input, safe: :safe, base_dir: DIRNAME
1726+
assert_includes output, %(<pre>#{expected}</pre>)
1727+
assert_empty logger.messages
1728+
end
1729+
end
1730+
16751731
test 'should warn if specified tag in include file is not closed' do
16761732
input = <<~'EOS'
16771733
++++

0 commit comments

Comments
 (0)