summaryrefslogtreecommitdiff
path: root/test/api_test.rb
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2018-10-12 23:47:21 -0600
committerGitHub <noreply@github.com>2018-10-12 23:47:21 -0600
commit9d5f400ecefb82d8ace3ffe098ca2ebd33aabc06 (patch)
treed0dde568abef124fd46991d6b6329b4b61c8b0be /test/api_test.rb
parent88a8b16f937f1c5d5da1a12e196b21cf6461ad0e (diff)
resolves #2067 allow filter block passed to AbstractBlock#find_by to skip subtrees (PR #2902)
- interpret :skip return value of filter block to mean skip node and its descendants - interpret :skip_children return value of filter block to mean accept node, but skip its descendants
Diffstat (limited to 'test/api_test.rb')
-rw-r--r--test/api_test.rb50
1 files changed, 50 insertions, 0 deletions
diff --git a/test/api_test.rb b/test/api_test.rb
index c411a8fd..4daa3b20 100644
--- a/test/api_test.rb
+++ b/test/api_test.rb
@@ -576,6 +576,56 @@ content
assert_equal 'Section', result[0].title
end
+ test 'find_by should skip node and its children if block returns :skip' do
+ input = <<-EOS
+paragraph 1
+
+====
+paragraph 2
+
+term::
++
+paragraph 3
+====
+
+paragraph 4
+ EOS
+ doc = Asciidoctor.load input
+ result = doc.find_by do |candidate|
+ ctx = candidate.context
+ if ctx == :example
+ :skip
+ elsif ctx == :paragraph
+ true
+ end
+ end
+ refute_nil result
+ assert_equal 2, result.size
+ assert_equal :paragraph, result[0].context
+ assert_equal :paragraph, result[1].context
+ end
+
+ test 'find_by should accept node but skip its children if block returns :skip_children' do
+ input = <<-EOS
+====
+paragraph 2
+
+term::
++
+paragraph 3
+====
+ EOS
+ doc = Asciidoctor.load input
+ result = doc.find_by do |candidate|
+ if candidate.context == :example
+ :skip_children
+ end
+ end
+ refute_nil result
+ assert_equal 1, result.size
+ assert_equal :example, result[0].context
+ end
+
test 'find_by should stop looking for blocks when StopIteration is raised' do
input = <<-EOS
paragraph 1