# `Juggernaut.Schemata.Unit`
[🔗](https://github.com/holsee/juggernaut/blob/v0.4.0/lib/juggernaut/schemata/unit.ex#L1)

One file's metamutant (design notes §10.3, §10.4): its live mutants, how each is
switched (`Juggernaut.Schemata.Site`), the lifted functions
(`Juggernaut.Schemata.Lift`), the mutants taken out (with the reason) and the rendered
source with its span map.

Each unit owns a fixed block of switches, `base..base + size - 1`, so taking mutants out
of one file renumbers only that file and the others' rendered text stays the same (and
Mix does not recompile them). Within the block, sites are numbered in source order and
the mutants of one site consecutively, as `Juggernaut.Peer.Switch.site/2` needs.

Inline sites whose ranges cross (rather than nest) cannot both be wrapped: the later
one is lifted instead.

# `entry`

```elixir
@type entry() :: %{
  mutant: Juggernaut.Mutant.t(),
  from: non_neg_integer(),
  to: non_neg_integer(),
  kind: :inline | {:lift, {module(), atom(), arity()}}
}
```

# `t`

```elixir
@type t() :: %Juggernaut.Schemata.Unit{
  base: pos_integer(),
  bisect: Juggernaut.Schemata.Bisect.state() | nil,
  bisected: non_neg_integer(),
  excluded: %{
    required(String.t()) =&gt; %{mutant: Juggernaut.Mutant.t(), reason: String.t()}
  },
  file: String.t(),
  functions: %{
    required({module(), atom(), arity()}) =&gt; [
      Juggernaut.Mutator.ModuleScan.clause()
    ]
  },
  lifts: %{
    required({module(), atom(), arity()}) =&gt; Juggernaut.Schemata.Lift.t()
  },
  live: [entry()],
  rendered: binary() | nil,
  rounds: non_neg_integer(),
  sites: %{required(pos_integer()) =&gt; [pos_integer()]},
  size: non_neg_integer(),
  spans: [Juggernaut.Schemata.Text.span()],
  switches: %{required(String.t()) =&gt; pos_integer()},
  text: Juggernaut.Schemata.Text.t(),
  verbatim?: boolean()
}
```

# `exclude`

```elixir
@spec exclude(t(), [String.t()], String.t()) :: t()
```

Takes the mutants with `keys` out of the unit, with `reason`.

# `keys`

```elixir
@spec keys(t(), [pos_integer()]) :: [String.t()]
```

The keys of the live mutants a list of switches names.

# `lift_or_exclude`

```elixir
@spec lift_or_exclude(t(), [String.t()], String.t()) :: t()
```

Poison isolation's step for the mutants with `keys`: an inline one is moved into a
lifted copy of its function (its site cannot take a `case`, as inside a macro's
argument, but the mutant alone may compile); a lifted one is taken out with `reason`.

# `metamutant?`

```elixir
@spec metamutant?(t()) :: boolean()
```

Whether the unit's rendered source differs from the file as written.

# `new`

```elixir
@spec new(String.t(), String.t(), [Juggernaut.Mutant.t()], pos_integer()) :: t()
```

The unit of `file` (its `source` and its mutants), with switches from `base`. Ignored
mutants are not compiled and are left out.

# `render`

```elixir
@spec render(t()) :: t()
```

Renders the unit: assigns switches and writes the metamutant source and its span map.
A lifted mutant whose copy cannot be written is taken out first.

# `switched`

```elixir
@spec switched(t()) :: [Juggernaut.Mutant.t()]
```

The live mutants with their switches (after `render/1`).

# `verbatim`

```elixir
@spec verbatim(t(), String.t()) :: t()
```

Takes every live mutant out with `reason`: the file is compiled as written.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
