$ show kishikawakatsumi/swift-power-assert
swift-power-assert is a Swift library that provides a `#assert` macro, delivering detailed diagnostic diagrams for assertion failures. The macro, built on SwiftSyntax, rewrites expressions to capture intermediate values and renders a tree of sub-expression results on failure, including word/line diffs for string comparisons. It supports sync and async evaluation, short-circuiting, and custom operators, aiming to replace multiple assertion APIs (XCTest, Nimble, etc.) with a single, universal assert. The package also includes a `StringWidth` module for accurate Unicode width calculations and a comprehensive test suite (2300+ lines) covering diverse expression types. Additionally, the repository contains an interactive web playground with a Deno backend and Monaco editor, allowing users to test the macro in a browser. The codebase is well-structured, with clean abstractions in the runtime library and plugin, though the macro rewriter is tightly coupled to the capture pattern and the generated Unicode width table is large.
The LLM identified 4 files worth highlighting for reuse:
A standalone class for console text styling with ANSI escape codes. Supports bold, italic, underline, foreground/background colors, and respects `NO_COLOR` and `TERM` environment variables. The implementation is clean, isolated (no internal imports), and could be extracted for any Swift CLI tool requiring cross-platform terminal styling.
Provides custom word-level and line-level diff algorithms for rendering differences in assertion failures. The implementation uses a longest common subsequence (LCS) approach with careful handling of line breaks and word boundaries. It is self-contained and reusable for any Swift application needing human-readable diff output.
A SwiftSyntax `SyntaxRewriter` that collapses trivia (comments, whitespace) into a single space, producing a compact single-line representation of a Swift expression. This is a general-purpose utility for formatting syntax trees and can be reused in other SwiftSyntax-based tools, such as code formatters or diagnostics.
A public API for calculating the display width of Unicode strings, considering East Asian Width, combining characters, and emoji sequences. It wraps the generated `CodePointWidth` table and provides a simple `width(of:)` method. This module is self-contained and could be extracted for any Swift project needing accurate terminal column alignment.