Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using TUnit.Assertions.SourceGenerator.Generators;

namespace TUnit.Assertions.SourceGenerator.Tests;

internal class CollectionShapeAssertionGeneratorTests : TestsBase<CollectionShapeAssertionGenerator>
{
[Test]
public Task Emits_Full_Per_Shape_Assertion_Surface() => RunTest(
Path.Combine(Sourcy.Git.RootDirectory.FullName,
"TUnit.Assertions.SourceGenerator.Tests",
"TestData",
"CollectionShapeAssertionSource.cs"),
async generatedFiles =>
{
// Only Emitter A fires (no Satisfies / CountSpecialised triggers in the input).
await Assert.That(generatedFiles).Count().IsEqualTo(1);

var file = generatedFiles[0];

// Per-shape signature fidelity reflected from the real symbols: ReadOnlyList.HasItemAt
// carries an IEqualityComparer the IList overload does not.
await Assert.That(file).Contains(
"ReadOnlyListAssertion<TItem>(source.Context).HasItemAt(index, expected, comparer, indexExpression, expectedExpression)");
await Assert.That(file).Contains(
"ListAssertion<TItem>(source.Context).HasItemAt(index, expected, indexExpression, expectedExpression)");

// Set shapes seed via the internal FromContext factory.
await Assert.That(file).Contains("SetAssertion<TItem>.FromContext(source.Context)");

// Concrete shapes upcast their context (List<T> -> IList<T>) via the shared pre-work-preserving
// helper on AssertionContext, so the wrapper's pre-work survives without emitting a helper per file.
await Assert.That(file).Contains(
"source.Context.MapPreservingPreWork<global::System.Collections.Generic.IList<TItem>>(x => x)");

// Dictionary value shapes preserve dictionary-specific methods and the notnull key constraint.
await Assert.That(file).Contains("DictionaryAssertion<TKey, TValue>(source.Context).ContainsKey");
await Assert.That(file).Contains("where TKey : notnull");
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using TUnit.Assertions.Core;

// Local stand-in for the (internal) TUnit.Assertions.Attributes.GenerateCollectionShapeAssertionsAttribute.
// The generator matches the trigger by metadata name, so a same-named source declaration drives it without
// needing friend access to the real internal attribute (which strong-naming would otherwise require). The
// real attribute is invisible here (internal, no InternalsVisibleTo), so there is no accessible conflict.
namespace TUnit.Assertions.Attributes
{
[System.AttributeUsage(System.AttributeTargets.Class)]
internal sealed class GenerateCollectionShapeAssertionsAttribute : System.Attribute;
}

namespace TUnit.Assertions.SourceGenerator.Tests.TestData
{
// Minimal arity-1 wrapper source used to exercise CollectionShapeAssertionGenerator (Emitter A).
// The generator reflects the real shape-assertion-source method surface from the referenced
// TUnit.Assertions assembly, so per-shape signature fidelity (e.g. the ReadOnlyList HasItemAt
// comparer parameter that IList lacks) is asserted against the actual symbols. Only the single
// type parameter and the public Context property are required by the generator.
[TUnit.Assertions.Attributes.GenerateCollectionShapeAssertions]
public sealed class CollectionShapeAssertionSource<T>
{
public AssertionContext<T> Context { get; } = null!;
}
}
Loading
Loading