Search documentation of Metastatic

# Metastatic.Test.FixtureHelper (Metastatic v0.13.2)

View Source

Helper utilities for loading and managing test fixtures.

Provides structured access to test fixtures across different languages, with support for expected MetaAST outputs and validation.

## Directory Structure

    test/fixtures/
    ├── python/
    │   ├── simple_arithmetic.py
    │   ├── complex_function.py
    │   └── expected/
    │       ├── simple_arithmetic.exs
    │       └── complex_function.exs
    ├── javascript/
    │   └── ...
    └── elixir/
        └── ...

## Usage

    # Load all fixtures for a language
    fixtures = FixtureHelper.load_language(:python)

    # Load a specific fixture
    {:ok, fixture} = FixtureHelper.load_fixture(:python, "simple_arithmetic")

    # Get fixture path
    path = FixtureHelper.fixture_path(:python, "simple_arithmetic.py")

## Summary

### Functions

create_language_dir(language)

Create a fixture directory structure for a language.

fixture_path(language, filename)

Get the full path to a fixture file.

fixtures_dir()

Get the base fixtures directory path.

language_dir(language)

Get the fixtures directory for a specific language.

load_all()

Load all fixtures across all languages.

load_fixture(language, name)

Load a specific fixture.

load_language(language)

Load all fixtures for a language.

save_fixture(language, name, source, expected_ast \\ nil)

Save a fixture file and optionally its expected AST.

stats()

Get statistics about available fixtures.

validate_fixture(map, actual_ast)

Validate that a fixture's expected AST matches actual parsing result.

## Functions

# create_language_dir(language)

    @spec create_language_dir(atom()) :: :ok

Create a fixture directory structure for a language.

## Examples

    iex> FixtureHelper.create_language_dir(:python)
    :ok

# fixture_path(language, filename)

    @spec fixture_path(atom(), String.t()) :: String.t()

Get the full path to a fixture file.

## Examples

    iex> FixtureHelper.fixture_path(:python, "test.py")
    "/path/to/test/fixtures/python/test.py"

# fixtures_dir()

    @spec fixtures_dir() :: String.t()

Get the base fixtures directory path.

# language_dir(language)

    @spec language_dir(atom()) :: String.t()

Get the fixtures directory for a specific language.

## Examples

    iex> FixtureHelper.language_dir(:python)
    "/path/to/test/fixtures/python"

# load_all()

    @spec load_all() :: %{required(atom()) => [map()]}

Load all fixtures across all languages.

Returns a map of language => list of fixtures.

## Examples

    iex> all = FixtureHelper.load_all()
    iex> is_map(all)
    true

# load_fixture(language, name)

    @spec load_fixture(atom(), String.t()) ::
      {:ok, map()} | {:error, :not_found | :invalid_fixture}

Load a specific fixture.

Returns a map with:

- `:name` - Fixture name (without extension)
- `:source_file` - Full path to source file
- `:source` - Source code content
- `:expected_ast` - Expected MetaAST (if exists)
- `:language` - Language atom

## Examples

    iex> {:ok, fixture} = FixtureHelper.load_fixture(:python, "simple_arithmetic")
    iex> fixture.name
    "simple_arithmetic"
    iex> is_binary(fixture.source)
    true

# load_language(language)

    @spec load_language(atom()) :: [map()]

Load all fixtures for a language.

Returns a list of fixture maps.

## Examples

    iex> fixtures = FixtureHelper.load_language(:python)
    iex> is_list(fixtures)
    true

# save_fixture(language, name, source, expected_ast \\ nil)

    @spec save_fixture(atom(), String.t(), String.t(), term() | nil) :: :ok

Save a fixture file and optionally its expected AST.

## Examples

    iex> FixtureHelper.save_fixture(:python, "test", "x + 5")
    :ok

    iex> ast = {:binary_op, :arithmetic, :+, {:variable, "x"}, {:literal, :integer, 5}}
    iex> FixtureHelper.save_fixture(:python, "test", "x + 5", ast)
    :ok

# stats()

    @spec stats() :: map()

Get statistics about available fixtures.

## Examples

    iex> stats = FixtureHelper.stats()
    iex> stats.total_fixtures
    42

# validate_fixture(map, actual_ast)

    @spec validate_fixture(map(), term()) :: :ok | {:error, {:mismatch, term(), term()}}

Validate that a fixture's expected AST matches actual parsing result.

## Examples

    iex> {:ok, fixture} = FixtureHelper.load_fixture(:python, "test")
    iex> FixtureHelper.validate_fixture(fixture, actual_ast)
    :ok