Skip to content

Commit

Permalink
Simplify tag generation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubfijalkowski committed Aug 11, 2023
1 parent 0951368 commit c073c90
Showing 1 changed file with 19 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Xunit;
using static LeanCode.ContractsGenerator.Tests.TypeRefExtensions;
using CompilationTagGenerator = LeanCode.ContractsGenerator.Generation.NotificationTagGenerator;
using ContractsTagGenerator = LeanCode.Contracts.NotificationTagGenerator;
using OtherNamespaceDTO1 = Notifications.Internal.DTO1;
Expand All @@ -16,7 +17,7 @@ public class NotificationTagGenerators
private readonly string otherNamespaceDto1Name = $"{typeof(OtherNamespaceDTO1).FullName}";

[Fact]
public void Simple_class()
public void Simple_class_tag_is_generated_correctly()
{
var type = typeof(Class1);
var typeRef = TypeRefExtensions.Internal(class1Name);
Expand All @@ -26,62 +27,49 @@ public void Simple_class()
}

[Fact]
public void Single_generic_argument()
public void Generic_arguments_are_described_correctly()
{
var type = typeof(Class2<int>);
var typeRef = TypeRefExtensions
.Internal(class2Name)
.WithArguments(TypeRefExtensions.Known(KnownType.Int32));
var typeRef = TypeRefExtensions.Internal(class2Name).WithArguments(Known(KnownType.Int32));
var expectedTag = $"{class2Name}[!Int32]";

CheckGeneratedTags(type, typeRef, expectedTag);
}

[Fact]
public void Multiple_generic_arguments()
public void Multiple_generic_arguments_are_described_correctly()
{
var type = typeof(Class3<int, DateTimeOffset>);
var typeRef = TypeRefExtensions
.Internal(class3Name)
.WithArguments(
TypeRefExtensions.Known(KnownType.Int32),
TypeRefExtensions.Known(KnownType.DateTimeOffset)
);
.WithArguments(Known(KnownType.Int32), Known(KnownType.DateTimeOffset));
var expectedTag = $"{class3Name}[!Int32,!DateTimeOffset]";

CheckGeneratedTags(type, typeRef, expectedTag);
}

[Fact]
public void Nested_generic_arguments()
public void Nested_generic_arguments_are_described_correctly()
{
var type = typeof(Class3<Class2<object>, Class2<int[]>>);
var typeRef = TypeRefExtensions
.Internal(class3Name)
.WithArguments(
TypeRefExtensions
.Internal(class2Name)
.WithArguments(TypeRefExtensions.Known(KnownType.Object)),
TypeRefExtensions
.Internal(class2Name)
.WithArguments(
TypeRefExtensions.Array(TypeRefExtensions.Known(KnownType.Int32))
)
TypeRefExtensions.Internal(class2Name).WithArguments(Known(KnownType.Object)),
TypeRefExtensions.Internal(class2Name).WithArguments(Array(Known(KnownType.Int32)))
);
var expectedTag = $"{class3Name}[{class2Name}[!Object],{class2Name}[!Array[!Int32]]]";

CheckGeneratedTags(type, typeRef, expectedTag);
}

[Fact]
public void Map()
public void Maps_are_described_correctly()
{
var type = typeof(Dictionary<Guid[], Class2<TimeSpan>>);
var typeRef = TypeRefExtensions.Map(
TypeRefExtensions.Array(TypeRefExtensions.Known(KnownType.Guid)),
TypeRefExtensions
.Internal(class2Name)
.WithArguments(TypeRefExtensions.Known(KnownType.TimeSpan))
var typeRef = Map(
Array(Known(KnownType.Guid)),
TypeRefExtensions.Internal(class2Name).WithArguments(Known(KnownType.TimeSpan))
);
var expectedTag = $"!Map[!Array[!Guid],{class2Name}[!TimeSpan]]";

Expand All @@ -95,17 +83,10 @@ public void Map()
}

[Fact]
public void Array()
public void Arrays_are_described_correctly()
{
var type = typeof(Dictionary<int, string>[][]);
var typeRef = TypeRefExtensions.Array(
TypeRefExtensions.Array(
TypeRefExtensions.Map(
TypeRefExtensions.Known(KnownType.Int32),
TypeRefExtensions.Known(KnownType.String)
)
)
);
var typeRef = Array(Array(Map(Known(KnownType.Int32), Known(KnownType.String))));
var expectedTag = "!Array[!Array[!Map[!Int32,!String]]]";

CheckGeneratedTags(type, typeRef, expectedTag);
Expand All @@ -120,17 +101,15 @@ public void Array()
}

[Fact]
public void Known_type_name_clashes()
public void If_a_known_type_clashes_name_with_internal_type_The_clash_is_resolved_correctly()
{
var type1 = typeof(List<int>);
var type2 = typeof(System.Collections.Generic.List<int>);

CheckIfTagsAreDifferent(type1, type2);

var typeRef1 = TypeRefExtensions
.Internal(listName)
.WithArguments(TypeRefExtensions.Known(KnownType.Int32));
var typeRef2 = TypeRefExtensions.Array(TypeRefExtensions.Known(KnownType.Int32));
var typeRef1 = TypeRefExtensions.Internal(listName).WithArguments(Known(KnownType.Int32));
var typeRef2 = Array(Known(KnownType.Int32));

CheckIfTagsAreDifferent(typeRef1, typeRef2);

Expand All @@ -139,7 +118,7 @@ public void Known_type_name_clashes()
}

[Fact]
public void Class_name_clashes()
public void Namespaces_are_preserved_and_contribute_to_the_tag()
{
var type1 = typeof(DTO1);
var type2 = typeof(OtherNamespaceDTO1);
Expand Down

0 comments on commit c073c90

Please sign in to comment.