Sha256: 39ee40e9051a244faa3ba4d1d94dc13aaa50cab353ae4fbd0caaa3bc2747d281

Contents?: true

Size: 1.07 KB

Versions: 40

Compression:

Stored size: 1.07 KB

Contents

module OrigenTesters::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
      alias_method :on_group, :on_test

      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

40 entries across 40 versions & 1 rubygems

Version Path
origen_testers-0.52.8 lib/origen_testers/atp/processors/add_ids.rb
origen_testers-0.52.7 lib/origen_testers/atp/processors/add_ids.rb
origen_testers-0.52.6 lib/origen_testers/atp/processors/add_ids.rb
origen_testers-0.52.5 lib/origen_testers/atp/processors/add_ids.rb
origen_testers-0.52.4 lib/origen_testers/atp/processors/add_ids.rb
origen_testers-0.52.3 lib/origen_testers/atp/processors/add_ids.rb
origen_testers-0.52.1 lib/origen_testers/atp/processors/add_ids.rb
origen_testers-0.52.0 lib/origen_testers/atp/processors/add_ids.rb
origen_testers-0.51.5 lib/origen_testers/atp/processors/add_ids.rb
origen_testers-0.51.4 lib/origen_testers/atp/processors/add_ids.rb
origen_testers-0.51.3 lib/origen_testers/atp/processors/add_ids.rb
origen_testers-0.51.2 lib/origen_testers/atp/processors/add_ids.rb
origen_testers-0.51.1 lib/origen_testers/atp/processors/add_ids.rb
origen_testers-0.51.0 lib/origen_testers/atp/processors/add_ids.rb
origen_testers-0.50.0 lib/origen_testers/atp/processors/add_ids.rb
origen_testers-0.49.4 lib/origen_testers/atp/processors/add_ids.rb
origen_testers-0.49.3 lib/origen_testers/atp/processors/add_ids.rb
origen_testers-0.49.2 lib/origen_testers/atp/processors/add_ids.rb
origen_testers-0.49.1 lib/origen_testers/atp/processors/add_ids.rb
origen_testers-0.49.0 lib/origen_testers/atp/processors/add_ids.rb