Skip to content

Commit

Permalink
Support array tipes as viewmodels
Browse files Browse the repository at this point in the history
  • Loading branch information
Milan Mikuš committed Oct 12, 2023
1 parent a8aea52 commit d5bfe0c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ public BindingParserNode ReadPropertyDirectiveValue()
public BindingParserNode ReadDirectiveTypeName()
{
var startIndex = CurrentIndex;
var typeName = ReadNamespaceOrTypeName();

var typeName = TryReadTypeReference(out var resultType)
? resultType
: new ActualTypeReferenceBindingParserNode(new SimpleNameBindingParserNode(""));

if (PeekType() == BindingTokenType.Comma)
{
Read();
Expand Down
29 changes: 29 additions & 0 deletions src/Tests/Parser/Binding/BindingParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,35 @@ public void BindingParser_GenericExpression_MemberAccessInsteadOfType_Invalid()
.As<IdentifierNameBindingParserNode>().Name == "");
}

[TestMethod]
[DataRow("Domain.Company.Product.DotVVM.Feature.Type[], Domain.Company.Product")]
[DataRow("Domain.Company.Product.DotVVM.Feature.Type[], Product")]
[DataRow("Domain.Company.Product.DotVVM.Feature.Type<string>[], Domain.Company.Product")]
[DataRow("Domain.Company.Product.DotVVM.Feature.Type<string>[], Product")]
public void BindingParser_ArrayType_AssemblyQualifiedName_ValidAssemblyName(string binding)
{
var parser = bindingParserNodeFactory.SetupParser(binding);
var node = parser.ReadDirectiveTypeName() as AssemblyQualifiedNameBindingParserNode;
Assert.IsNotNull(node, "expected qualified name node.");

var array = node.TypeName as ArrayTypeReferenceBindingParserNode;

Assert.IsNotNull(array, "Expected array type reference");
Assert.IsFalse(node.AssemblyName.HasNodeErrors);
}

[TestMethod]
[DataRow("Domain.Company.Product.DotVVM.Feature.Type[]")]
[DataRow("Domain.Company.Product.DotVVM.Feature.Type<string>[]")]
public void BindingParser_ArrayType_ValidAssemblyName(string binding)
{
var parser = bindingParserNodeFactory.SetupParser(binding);
var array = parser.ReadDirectiveTypeName() as ArrayTypeReferenceBindingParserNode;

Assert.IsNotNull(array, "Expected array type reference");
Assert.IsFalse(array.HasNodeErrors);
}

[TestMethod]
[DataRow("Domain.Company.Product.DotVVM.Feature.Type, Domain.Company.Product")]
[DataRow("Domain.Company.Product.DotVVM.Feature.Type, Product")]
Expand Down

0 comments on commit d5bfe0c

Please sign in to comment.