ValueSemanticsSpec

abstract class ValueSemanticsSpec

The guard of the hand-written equals of a module's classes: a class that is not a data class and overrides equals lists the fields it compares by hand (valueFields(), or comparisons of its own), and a field added later and left out is not caught by the compiler. This spec builds an instance of each such class with every field set (bypassing its constructor), checks that an instance with the same fields is equal to it and has its hash code, and that changing any one field makes it unequal: a field equals does not compare fails the class, unless it is excluded with its reason.

A module's test extends it and names the packages it checks; the classes are those compiled in the module itself (its build/classes), so each module checks its own. Fields of the type kotlin.Lazy (a by lazy cache), static, synthetic and transient fields are not values and are left out.

Constructors

Link copied to clipboard
constructor()

Functions

Link copied to clipboard
@TestFactory
fun every copyWith keeps every field(): List<DynamicTest>

A class without a copy (its fields may grow) is copied through a copyWith whose parameters default to the receiver's fields: one that misses a field rebuilds the class with that field's default instead, and a copy with every default must equal the original.