Skip to content

Commit

Permalink
handle PR responses.
Browse files Browse the repository at this point in the history
  • Loading branch information
Régis Fricker committed Aug 19, 2019
1 parent 3df2f4c commit e291995
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -453,30 +453,25 @@ public void should_leave_supplied_protomap()
}

[Test]
public void should_generate_two_class()
public void should_generate_two_classes_with_same_name_and_different_arity()
{
// Arrange
var msg1 = new MessageDefinition();
msg1.Name = "GenericCommand";
var msg2 = new MessageDefinition();
msg2.Name = msg1.Name;
msg2.GenericParameters.Add("IEnumerable");
msg2.GenericParameters.Add("T");
var contracts = new ParsedContracts();
contracts.Messages.Add(msg1);
contracts.Messages.Add(msg2);
contracts.ImportedNamespaces.Add("System.Collections");

// Act
var result = GenerateRaw(contracts);

// Assert
Console.WriteLine("----- START -----");
Console.WriteLine(result);
Console.WriteLine("----- END -----");

contracts.Errors.ShouldBeEmpty();
result.ShouldContain("public sealed partial class GenericCommand");
result.ShouldContain("public sealed partial class GenericCommand<IEnumerable>");
result.ShouldContain("public sealed partial class GenericCommand<T>");
}

protected override string GenerateRaw(ParsedContracts contracts) => CSharpGenerator.Generate(contracts);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,13 +499,12 @@ public void should_return_source_text()
}

[Test]
public void should_return_two_messages()
public void should_return_two_messages_with_same_name_but_different_arity()
{
// Arrange
var name = "Command";
var genericParam = "IEnumerable";
var definitionText = "using System.Collections;" + Environment.NewLine +
$"{name}()" + Environment.NewLine +
var name = "Foo";
var genericParam = "T";
var definitionText = $"{name}()" + Environment.NewLine +
$"{name}<{genericParam}>()";

// Act
Expand Down
26 changes: 13 additions & 13 deletions src/Abc.Zebus.MessageDsl/Analysis/AstValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,29 +99,29 @@ private void DetectDuplicateTypes()

foreach (var typeNode in types)
{
var id = Id(typeNode);
var nameWithGenericArity = GetNameWithGenericArity(typeNode);

if (!seenTypes.Add(id))
duplicates.Add(id);
if (!seenTypes.Add(nameWithGenericArity))
duplicates.Add(nameWithGenericArity);
}

foreach (var typeNode in types)
{
var id = Id(typeNode);
var nameWithGenericArity = GetNameWithGenericArity(typeNode);

if (duplicates.Contains(id))
_contracts.AddError(typeNode.ParseContext, "Duplicate type id: {0}", id);
if (duplicates.Contains(nameWithGenericArity))
_contracts.AddError(typeNode.ParseContext, "Duplicate type name: {0}", nameWithGenericArity);
}
}

private string Id(AstNode node)
{
var name = ((INamedNode)node).Name;
if (node is MessageDefinition messageDef && messageDef.GenericParameters.Count > 0)
string GetNameWithGenericArity(AstNode node)
{
name = $"{name}-{messageDef.GenericParameters.Count}";
var name = ((INamedNode)node).Name;
if (node is MessageDefinition messageDef && messageDef.GenericParameters.Count > 0)
{
name = $"{name}`{messageDef.GenericParameters.Count}";
}
return name;
}
return name;
}

public static bool IsValidTag(int tag)
Expand Down

0 comments on commit e291995

Please sign in to comment.