defmodule Outlook.InternalTreeTestHelpers do

  @default_nid "xxxxxx"

  alias Outlook.InternalTree.{InternalNode,TranslationUnit}
  @doc "Set nids to default value to make test results predictable."
  def unify_nids_in_tunits([ %TranslationUnit{} = node | rest ]) do
    [
      %TranslationUnit{node |
        nid: @default_nid,
        content: String.replace(node.content, ~r/ nid=""/, "")
        }
      | unify_nids_in_tunits(rest) ]
  end

  def unify_nids_in_tunits([ %InternalNode{type: :element} = node | rest ]) do
    [ %InternalNode{node |
        content: unify_nids_in_tunits(node.content)
      }
    | unify_nids_in_tunits(rest) ]
  end

  def unify_nids_in_tunits([ %InternalNode{} = node | rest ]) do
    [ node | unify_nids_in_tunits(rest) ]
  end

  def unify_nids_in_tunits([]), do: []
end
