diff --git a/src/Framework/Framework/Compilation/Parser/Binding/Parser/BindingParser.cs b/src/Framework/Framework/Compilation/Parser/Binding/Parser/BindingParser.cs index 14b9c58423..c9347fcbb5 100644 --- a/src/Framework/Framework/Compilation/Parser/Binding/Parser/BindingParser.cs +++ b/src/Framework/Framework/Compilation/Parser/Binding/Parser/BindingParser.cs @@ -144,13 +144,16 @@ public AssemblyNameBindingParserNode ReadAssemblyName() { // almost anything can be an assembly name, so we just read everything until the end SkipWhiteSpace(); - var tokens = this.Tokens.Skip(CurrentIndex).ToList(); + + 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 = new AssemblyNameBindingParserNode(tokens); + var node = CreateNode(new AssemblyNameBindingParserNode(tokens), startIndex); if (node.Name.Length == 0) { node.NodeErrors.Add("Assembly name cannot be empty."); diff --git a/src/Tests/Parser/Binding/BindingParserTests.cs b/src/Tests/Parser/Binding/BindingParserTests.cs index 33a5bbff5f..6d96e5ff00 100644 --- a/src/Tests/Parser/Binding/BindingParserTests.cs +++ b/src/Tests/Parser/Binding/BindingParserTests.cs @@ -1,16 +1,8 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; +using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Threading.Tasks; -using DotVVM.Framework.Compilation.Parser; using DotVVM.Framework.Compilation.Parser.Binding.Parser; using DotVVM.Framework.Compilation.Parser.Binding.Tokenizer; -using DotVVM.Framework.Controls; using Microsoft.VisualStudio.TestTools.UnitTesting; -using BindingParser = DotVVM.Framework.Compilation.Parser.Binding.Parser.BindingParser; -using a = System.Collections.Generic.Dictionary.ValueCollection; using DotVVM.Framework.Utils; namespace DotVVM.Framework.Tests.Parser.Binding @@ -830,23 +822,26 @@ public void BindingParser_GenericExpression_MemberAccessInsteadOfType_Invalid() } [TestMethod] - [DataRow("Domain.Company.Product.DotVVM.Feature.Type[], Domain.Company.Product", "Domain.Company.Product.DotVVM.Feature.Type[]")] - [DataRow("Domain.Company.Product.DotVVM.Feature.Type[], Product", "Domain.Company.Product.DotVVM.Feature.Type[]")] - [DataRow("Domain.Company.Product.DotVVM.Feature.Type[], Domain.Company.Product", "Domain.Company.Product.DotVVM.Feature.Type[]")] - [DataRow("Domain.Company.Product.DotVVM.Feature.Type[], Product", "Domain.Company.Product.DotVVM.Feature.Type[]")] - public void BindingParser_ArrayType_AssemblyQualifiedName_ValidAssemblyName(string binding, string type) + [DataRow("Domain.Company.Product.DotVVM.Feature.Type[], Domain.Company.Product", "Domain.Company.Product.DotVVM.Feature.Type[]", "Domain.Company.Product")] + [DataRow("Domain.Company.Product.DotVVM.Feature.Type[], Product", "Domain.Company.Product.DotVVM.Feature.Type[]", "Product")] + [DataRow("Domain.Company.Product.DotVVM.Feature.Type[], Domain.Company.Product", "Domain.Company.Product.DotVVM.Feature.Type[]", "Domain.Company.Product")] + [DataRow("Domain.Company.Product.DotVVM.Feature.Type[], Product", "Domain.Company.Product.DotVVM.Feature.Type[]", "Product")] + public void BindingParser_ArrayType_AssemblyQualifiedName_ValidAssemblyName(string binding, string type, string assembly) { var parser = bindingParserNodeFactory.SetupParser(binding); var node = parser.ReadDirectiveTypeName() as AssemblyQualifiedNameBindingParserNode; + Assert.IsNotNull(node, "expected qualified name node."); AssertNode(node, binding, 0, binding.Length); - var array = node.TypeName as ArrayTypeReferenceBindingParserNode; + var arrayNode = node.TypeName as ArrayTypeReferenceBindingParserNode; + var assemblyNode = node.AssemblyName; - Assert.IsNotNull(array, "Expected array type reference"); - Assert.IsFalse(node.AssemblyName.HasNodeErrors); + Assert.IsNotNull(assemblyNode, "expected assembly name node."); + AssertNode(assemblyNode, assembly, type.Length + 2, assembly.Length); - AssertNode(array, type, 0, type.Length); + Assert.IsNotNull(arrayNode, "Expected array type reference"); + AssertNode(arrayNode, type, 0, type.Length); } [TestMethod] @@ -1222,7 +1217,7 @@ public void BindingParser_PropertyHalfWrittenAttributes() Assert.AreEqual(4, root.Attributes.Count); var emptyAttribute = root.Attributes[0].CastTo(); - AssertNode(emptyAttribute, "", 19, 0); + AssertNode(emptyAttribute, "", 19, 0, hasErrors:true); var dotvvmNode = root.Attributes[1].CastTo(); AssertNode(dotvvmNode, "DotVVM.", 21, 7); @@ -1248,7 +1243,7 @@ public void BindingParser_PropertyTypeHalfWritten() AssertNode(type, "System.", 0, 7); AssertNode(target, "System", 0, 6); - AssertNode(name, "", 7, 0); + AssertNode(name, "", 7, 0, hasErrors: true); } [TestMethod] @@ -1488,11 +1483,20 @@ public void BindingParser_GenericMethodCall_MultipleGenericArguments() AssertNode(typeArgument2, "System.String", 29, 13); } - private static void AssertNode(BindingParserNode elementType, string expectedDisplayString, int start, int length) + private static void AssertNode(BindingParserNode node, string expectedDisplayString, int start, int length, bool hasErrors = false) { - Assert.AreEqual(expectedDisplayString, elementType.ToDisplayString(), $"Node {elementType.GetType().Name}: display string incorrect."); - Assert.AreEqual(start, elementType.StartPosition, $"Node {elementType.GetType().Name}: Start position incorrect."); - Assert.AreEqual(length, elementType.Length, $"Node {elementType.GetType().Name}: Length incorrect."); + Assert.AreEqual(expectedDisplayString, node.ToDisplayString(), $"Node {node.GetType().Name}: display string incorrect."); + Assert.AreEqual(start, node.StartPosition, $"Node {node.GetType().Name}: Start position incorrect."); + Assert.AreEqual(length, node.Length, $"Node {node.GetType().Name}: Length incorrect."); + + if (hasErrors) + { + Assert.IsTrue(node.HasNodeErrors); + } + else + { + Assert.IsFalse (node.HasNodeErrors); + } } private static string SkipWhitespaces(string str) => string.Join("", str.Where(c => !char.IsWhiteSpace(c)));