using GFramework.Godot.SourceGenerators.Registration; using GFramework.Godot.SourceGenerators.Tests.Core; namespace GFramework.Godot.SourceGenerators.Tests.Registration; [TestFixture] public class AutoRegisterExportedCollectionsGeneratorTests { [Test] public async Task Generates_Batch_Registration_Method_For_Annotated_Collections() { const string source = """ using System; using System.Collections.Generic; using GFramework.Godot.SourceGenerators.Abstractions; namespace GFramework.Godot.SourceGenerators.Abstractions { [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)] public sealed class AutoRegisterExportedCollectionsAttribute : Attribute { } [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, Inherited = false, AllowMultiple = false)] public sealed class RegisterExportedCollectionAttribute : Attribute { public RegisterExportedCollectionAttribute(string registryMemberName, string registerMethodName) { } } } namespace TestApp { public sealed class IntRegistry { public void Register(int value) { } } [AutoRegisterExportedCollections] public partial class Bootstrapper { private readonly IntRegistry _registry = new(); [RegisterExportedCollection(nameof(_registry), nameof(IntRegistry.Register))] public List Values { get; } = new(); } } """; const string expected = """ // #nullable enable namespace TestApp; partial class Bootstrapper { private void __RegisterExportedCollections_Generated() { foreach (var item in Values) { _registry.Register(item); } } } """; await GeneratorTest.RunAsync( source, ("TestApp_Bootstrapper.AutoRegisterExportedCollections.g.cs", expected)); } }