Sha256: 7dd5f2098383de2fe6ac7457fe145a843b276fc59a6d2fbabaabfdaf07d19641

Contents?: true

Size: 1.01 KB

Versions: 10

Compression:

Stored size: 1.01 KB

Contents

module ATP
  module Processors
    # Assigns an ID to all test nodes that don't have one
    class AddIDs < Processor
      def run(node)
        @i = 0
        @existing_ids = []
        @add_ids = false
        # First collect all existing IDs, this is required to make sure
        # that a generated ID does not clash with an existing one
        process(node)
        # Now run again to fill in the blanks
        @add_ids = true
        process(node)
      end

      def on_test(node)
        if @add_ids
          node = node.ensure_node_present(:id)
          node.updated(nil, process_all(node))
        else
          if id = node.find(:id)
            @existing_ids << id.value
          end
          process_all(node)
        end
      end

      def on_id(node)
        if @add_ids
          unless node.value
            node.updated(nil, [next_id])
          end
        end
      end

      def next_id
        @i += 1
        @i += 1 while @existing_ids.include?("t#{@i}")
        "t#{@i}"
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
atp-0.8.0 lib/atp/processors/add_ids.rb
atp-0.7.0 lib/atp/processors/add_ids.rb
atp-0.6.0 lib/atp/processors/add_ids.rb
atp-0.5.4 lib/atp/processors/add_ids.rb
atp-0.5.3 lib/atp/processors/add_ids.rb
atp-0.5.0 lib/atp/processors/add_ids.rb
atp-0.4.3 lib/atp/processors/add_ids.rb
atp-0.4.2 lib/atp/processors/add_ids.rb
atp-0.4.1 lib/atp/processors/add_ids.rb
atp-0.4.0 lib/atp/processors/add_ids.rb