Metastatic.Test.FixtureHelper
(Metastatic v0.10.4)
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 a fixture directory structure for a language.
Get the full path to a fixture file.
Get the base fixtures directory path.
Get the fixtures directory for a specific language.
Load all fixtures across all languages.
Load a specific fixture.
Load all fixtures for a language.
Save a fixture file and optionally its expected AST.
Get statistics about available fixtures.
Validate that a fixture's expected AST matches actual parsing result.
Functions
@spec create_language_dir(atom()) :: :ok
Create a fixture directory structure for a language.
Examples
iex> FixtureHelper.create_language_dir(:python)
:ok
Get the full path to a fixture file.
Examples
iex> FixtureHelper.fixture_path(:python, "test.py")
"/path/to/test/fixtures/python/test.py"
@spec fixtures_dir() :: String.t()
Get the base fixtures directory path.
Get the fixtures directory for a specific language.
Examples
iex> FixtureHelper.language_dir(:python)
"/path/to/test/fixtures/python"
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 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 all fixtures for a language.
Returns a list of fixture maps.
Examples
iex> fixtures = FixtureHelper.load_language(:python)
iex> is_list(fixtures)
true
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
@spec stats() :: map()
Get statistics about available fixtures.
Examples
iex> stats = FixtureHelper.stats()
iex> stats.total_fixtures
42
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