github cweill/gotests v1.8.0
v1.8.0 - Full Go Generics Support

one day ago

🎉 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

    • anyint
    • comparablestring
    • 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

Don't miss a new gotests release

NewReleases is sending notifications on new releases.