TermUI.Test.Assertions (TermUI v0.2.0)

View Source

TUI-specific assertion helpers for testing.

Provides assertions for checking rendered content, styles, component state, and focus. Assertions produce clear failure messages showing expected vs actual.

Usage

use TermUI.Test.Assertions

# Content assertions
assert_text(renderer, 1, 1, "Hello")
assert_text_contains(renderer, 1, 1, 80, "Error")
refute_text(renderer, 1, 1, "Goodbye")

# Style assertions
assert_style(renderer, 1, 1, fg: :red)
assert_attr(renderer, 1, 1, :bold)

# State assertions
assert_state(state, [:counter, :value], 42)

Summary

Functions

Imports all assertion macros.

Asserts that a cell has a specific attribute.

Asserts that buffer is empty (all spaces with default style).

Asserts row matches expected text (trimming trailing spaces).

Asserts that a snapshot matches the current buffer.

Asserts state at a path matches expected value.

Asserts state at a path exists (is not nil).

Asserts that a cell has the expected style.

Asserts that text appears at the given position.

Asserts that a region contains the expected text.

Asserts that text exists somewhere in the buffer.

Asserts that a cell does not have a specific attribute.

Asserts state at a path does not match value.

Asserts that text does not appear at the given position.

Asserts that a region does not contain the text.

Asserts that text does not exist anywhere in the buffer.

Functions

__using__(opts)

(macro)

Imports all assertion macros.

Example

defmodule MyTest do
  use ExUnit.Case
  use TermUI.Test.Assertions

  test "renders correctly" do
    {:ok, renderer} = TestRenderer.new(24, 80)
    assert_text(renderer, 1, 1, "Hello")
  end
end

assert_attr(renderer, row, col, attr)

(macro)

Asserts that a cell has a specific attribute.

Examples

assert_attr(renderer, 1, 1, :bold)

assert_empty(renderer)

(macro)

Asserts that buffer is empty (all spaces with default style).

assert_row(renderer, row, expected)

(macro)

Asserts row matches expected text (trimming trailing spaces).

assert_snapshot(renderer, snapshot)

(macro)

Asserts that a snapshot matches the current buffer.

Examples

snapshot = TestRenderer.snapshot(renderer)
# ... operations ...
assert_snapshot(renderer, snapshot)

assert_state(state, path, expected)

(macro)

Asserts state at a path matches expected value.

Examples

assert_state(%{counter: %{value: 42}}, [:counter, :value], 42)
assert_state(state, [:items], [1, 2, 3])

assert_state_exists(state, path)

(macro)

Asserts state at a path exists (is not nil).

assert_style(renderer, row, col, expected)

(macro)

Asserts that a cell has the expected style.

Options

  • :fg - Expected foreground color
  • :bg - Expected background color
  • :attrs - Expected attributes (list or MapSet)

Examples

assert_style(renderer, 1, 1, fg: :red)
assert_style(renderer, 1, 1, fg: :red, bg: :white)
assert_style(renderer, 1, 1, attrs: [:bold, :underline])

assert_text(renderer, row, col, expected)

(macro)

Asserts that text appears at the given position.

Examples

assert_text(renderer, 1, 1, "Hello")

assert_text_contains(renderer, row, col, width, expected)

(macro)

Asserts that a region contains the expected text.

Examples

assert_text_contains(renderer, 1, 1, 80, "Error")

assert_text_exists(renderer, text)

(macro)

Asserts that text exists somewhere in the buffer.

Examples

assert_text_exists(renderer, "Error")

refute_attr(renderer, row, col, attr)

(macro)

Asserts that a cell does not have a specific attribute.

refute_state(state, path, value)

(macro)

Asserts state at a path does not match value.

refute_text(renderer, row, col, text)

(macro)

Asserts that text does not appear at the given position.

refute_text_contains(renderer, row, col, width, text)

(macro)

Asserts that a region does not contain the text.

refute_text_exists(renderer, text)

(macro)

Asserts that text does not exist anywhere in the buffer.