Skip to content

Commit

Permalink
Trailing whitespaces discarded from assembly name.
Browse files Browse the repository at this point in the history
Improved AssemblyQualifiedName tests to test ranges.
  • Loading branch information
Milan Mikuš committed Dec 7, 2023
1 parent e2f2f67 commit 85d2ff4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,11 @@ namespace DotVVM.Framework.Compilation.Parser.Binding.Parser
public class AssemblyNameBindingParserNode : BindingParserNode
{
public string Name { get; }
public AssemblyNameBindingParserNode(List<BindingToken> tokens)
{
Tokens = tokens;
Name = string.Concat(tokens.Select(t => t.Text));
}

public AssemblyNameBindingParserNode(string name)
: this(new List<BindingToken>() { new BindingToken(name, BindingTokenType.Identifier, 0, 0, 0, 0)})
{ }
{
Name = name;
}

public override IEnumerable<BindingParserNode> EnumerateChildNodes()
=> Enumerable.Empty<BindingParserNode>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,16 @@ public AssemblyNameBindingParserNode ReadAssemblyName()
var startIndex = CurrentIndex;

var tokens = Tokens.Skip(CurrentIndex).ToList();
CurrentIndex = Tokens.Count;

while (tokens.Count > 0 && tokens[tokens.Count - 1].Type == BindingTokenType.WhiteSpace)
tokens.RemoveAt(tokens.Count - 1);

var node = CreateNode(new AssemblyNameBindingParserNode(tokens), startIndex);
CurrentIndex += tokens.Count;
var name = string.Concat(tokens.Select(t => t.Text));

var node = CreateNode(new AssemblyNameBindingParserNode(name), startIndex);
CurrentIndex = Tokens.Count;

if (node.Name.Length == 0)
{
node.NodeErrors.Add("Assembly name cannot be empty.");
Expand Down
12 changes: 9 additions & 3 deletions src/Tests/Parser/Binding/BindingParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -864,13 +864,19 @@ public void BindingParser_ArrayType_ValidAssemblyName(string binding)
[DataRow("Domain.Company.Product.DotVVM.Feature.Type, Domain.Company<int>.Product", "Domain.Company<int>.Product")]
[DataRow("Domain.Company.Product.DotVVM.Feature.Type, Domain<int>.Company.Product", "Domain<int>.Company.Product")]
[DataRow("Domain.Company.Product.DotVVM.Feature.Type, Product<int>", "Product<int>")]
[DataRow("Domain.Company.Product.DotVVM.Feature.Type, Product<int> ", "Product<int>")]
[DataRow("Domain.Company.Product.DotVVM.Feature.Type, my assembly name ", "my assembly name")]

public void BindingParser_AssemblyQualifiedName_ValidAssemblyName(string binding, string assemblyName)
{
var parser = bindingParserNodeFactory.SetupParser(binding);
var node = parser.ReadDirectiveTypeName() as AssemblyQualifiedNameBindingParserNode;

var controlSting = binding.TrimEnd();

Assert.IsFalse(node.AssemblyName.HasNodeErrors);
Assert.AreEqual(assemblyName, node.AssemblyName.ToDisplayString());
AssertNode(node, controlSting, 0, binding.Length);
AssertNode(node.AssemblyName, assemblyName, 44, assemblyName.Length);
}

[TestMethod]
Expand Down Expand Up @@ -1217,7 +1223,7 @@ public void BindingParser_PropertyHalfWrittenAttributes()
Assert.AreEqual(4, root.Attributes.Count);

var emptyAttribute = root.Attributes[0].CastTo<SimpleNameBindingParserNode>();
AssertNode(emptyAttribute, "", 19, 0, hasErrors:true);
AssertNode(emptyAttribute, "", 19, 0, hasErrors: true);

var dotvvmNode = root.Attributes[1].CastTo<MemberAccessBindingParserNode>();
AssertNode(dotvvmNode, "DotVVM.", 21, 7);
Expand Down Expand Up @@ -1495,7 +1501,7 @@ private static void AssertNode(BindingParserNode node, string expectedDisplayStr
}
else
{
Assert.IsFalse (node.HasNodeErrors);
Assert.IsFalse(node.HasNodeErrors);
}
}

Expand Down

0 comments on commit 85d2ff4

Please sign in to comment.