Skip to content

v1.8.0 - Full Go Generics Support

Choose a tag to compare

@cweill cweill released this 21 Oct 04:49
· 14 commits to develop since this release

πŸŽ‰ Full Go Generics Support

This release adds complete support for Go generics (type parameters), enabling gotests to generate tests for generic functions and methods on generic types.

✨ Key Features

  • πŸ”§ Generic Functions: Generate tests for functions with type parameters

    func FindFirst[T comparable](slice []T, target T) (int, error)
  • πŸ—οΈ Generic Types: Support for methods on generic types

    type Set[T comparable] struct { ... }
    func (s *Set[T]) Add(v T)
  • 🎯 All Constraint Types: any, comparable, union types (int64 | float64), approximation (~int)

  • 🧠 Smart Type Mapping: Intelligent defaults for type instantiation

    • any β†’ int
    • comparable β†’ string
    • Union types β†’ first option
    • Approximation β†’ underlying type
  • πŸ”„ Multiple Type Parameters: Handles functions like Pair[T, U any]

πŸ“Š Test Coverage

  • βœ… 97.5% main package coverage
  • βœ… 83.5% overall project coverage
  • βœ… 100% coverage on all new parser functions
  • βœ… 8 comprehensive generic test patterns

πŸ”§ Technical Improvements

Parser Enhancements:

  • New parseTypeDecls() extracts type parameters from type declarations
  • New parseTypeParams() parses AST field lists
  • New extractBaseTypeName() handles receiver types

Template Functions:

  • TypeArgs - generates concrete type arguments for calls
  • FieldType - substitutes type parameters in field declarations
  • ReceiverType - substitutes type parameters in receiver instantiations

Model Updates:

  • New TypeParam struct
  • Added TypeParams field to Function
  • Helper methods: IsGeneric(), HasGenericReceiver()

πŸ“š Documentation

Added comprehensive "Go Generics Support" section to README with:

  • Example: Generic function test generation
  • Example: Methods on generic types
  • Type constraint mapping reference

πŸ› Fixes

Closes #165

πŸ“¦ Installation

go install github.com/cweill/gotests/gotests@v1.8.0

πŸ™ Credits

πŸ€– Developed with assistance from Claude Code


Full Changelog: v1.7.0...v1.8.0