Skip to content

Add unit tests for VirtualBinderFields + BinderFieldsBody #14

@VPDPersonal

Description

@VPDPersonal

The Aspid.MVVM.Generators.Tests/ project is currently empty (no .cs files since the Global rename commit). The new auto-binder-fields pipeline introduced in PR #13 (VirtualBinderFields collector + BinderFieldsBody emitter) ships without regression coverage. This issue tracks adding it.

Required test cases

  • AutoBinderFields default-on: [View] over a MonoBehaviour partial that implements IView<TVm> where TVm has at least one [Bind] member not already declared on the View — generated <View>.BinderFields.g.cs contains a _<name>: MonoBinder[] field decorated with [RequireBinder(typeof(<expected>))] and [SerializeField].
  • AutoBinderFields = false: same input, [View(AutoBinderFields = false)] — no BinderFields.g.cs partial emitted.
  • ScriptableObject base: View deriving from UnityEngine.ScriptableObject — no BinderFields.g.cs partial regardless of AutoBinderFields value.
  • Skip already-declared: if the View already declares private MonoBinder[] _foo; for Foo (or inherits a binder field for it from a base [View]), it is not duplicated as a virtual field.
  • [Header] propagation: VM member tagged [UnityEngine.Header("X")] → generated field decorated with [Header("X")].
  • HeaderGroup propagation (single): VM member tagged [Aspid.MVVM.HeaderGroup("G")] → generated field decorated with [Aspid.MVVM.HeaderGroup("G")].
  • HeaderGroupStart / HeaderGroupEnd range: VM members between [HeaderGroupStart("G")] and [HeaderGroupEnd] → all generated fields in that range carry [HeaderGroup("G")]; the field right after HeaderGroupEnd does not.
  • RequireBinder types: when a VM member has multiple bindable shapes (e.g. IBindableMember<int> + IBindableMember<int?>), the generated [RequireBinder] lists each required type once, nullable suffix stripped.

Infrastructure prerequisites

The test project is xUnit + Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing.XUnit but has no source files. Setting up tests requires:

  • A helper that builds a CSharpCompilation referencing Aspid.MVVM + UnityEngine stub types (ViewAttribute with AutoBinderFields property, IView<T>, IBindableMember<T>, BindAttribute, MonoBinder, IBinder, HeaderGroupAttribute / HeaderGroupStartAttribute / HeaderGroupEndAttribute, RequireBinderAttribute, UnityEngine.MonoBehaviour, SerializeField, Header, ScriptableObject).
  • A CSharpGeneratorDriver wrapper that runs ViewGenerator on a given source string and exposes runResult.Results[0].GeneratedSources for assertions.

Out of scope here

  • Initialization-pipeline / InitializeBody regression — covered separately if needed.
  • Full BindableMembersFactory coverage — only the subset reachable via VirtualBinderFields.Collect matters for this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    Status
    Backlog

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions