Sha256: 24a604764ee0f47c5e22c237acb789435a220afc5f34a19749131056e8e3657d

Contents?: true

Size: 1.29 KB

Versions: 5

Compression:

Stored size: 1.29 KB

Contents

module ATP
  module Processors
    # Removes most things from embedded on_pass/fail nodes and converts them to the equivalent
    # on_passed/failed condition at the same level as the parent node
    class OnPassFailRemover < Processor
      def run(node)
        process(node)
      end

      def on_test(node)
        on_pass = node.find(:on_pass)
        on_fail = node.find(:on_fail)
        if on_pass || on_fail
          id = node.find(:id)
          unless id
            fail 'Something has gone wrong, all nodes should have IDs by this point'
          end
          id = id.value
          nodes = [node]
          if on_fail && contains_anything_interesting?(on_fail)
            nodes << node.updated(:if_failed, [id] + on_fail.children)
            nodes[0] = nodes[0].remove(on_fail)
          end
          if on_pass && contains_anything_interesting?(on_pass)
            nodes << node.updated(:if_passed, [id] + on_pass.children)
            nodes[0] = nodes[0].remove(on_pass)
          end
          node.updated(:inline, nodes)
        else
          node.updated(nil, process_all(node.children))
        end
      end

      def contains_anything_interesting?(node)
        node.children.any? { |n| n.type != :set_result && n.type != :continue && n.type != :set_flag }
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
atp-1.1.3 lib/atp/processors/on_pass_fail_remover.rb
atp-1.1.2 lib/atp/processors/on_pass_fail_remover.rb
atp-1.1.1 lib/atp/processors/on_pass_fail_remover.rb
atp-1.1.0 lib/atp/processors/on_pass_fail_remover.rb
atp-1.0.0 lib/atp/processors/on_pass_fail_remover.rb