private void AssertNodeEquals(SyntaxNode node, IEnumerable <SyntaxNode> ancestors, string expected, string actual)
        {
            if (string.Equals(expected, actual))
            {
                // YAY!!! everything is great.
                return;
            }

            if (expected == null)
            {
                var message = "The node is missing from baseline.";
                throw new SyntaxNodeBaselineException(node, Ancestors.ToArray(), expected, actual, message);
            }

            int charsVerified = 0;

            AssertNestingEqual(node, ancestors, expected, actual, ref charsVerified);
            AssertNameEqual(node, ancestors, expected, actual, ref charsVerified);
            AssertDelimiter(node, expected, actual, true, ref charsVerified);
            AssertLocationEqual(node, ancestors, expected, actual, ref charsVerified);
            AssertDelimiter(node, expected, actual, false, ref charsVerified);
            AssertContentEqual(node, ancestors, expected, actual, ref charsVerified);

            throw new InvalidOperationException("We can't figure out HOW these two things are different. This is a bug.");
        }
Exemple #2
0
        protected override void Visit(AphidExpression expression)
        {
            //if (_filename != null && expression.Filename == null)
            //{
            //    expression.Filename = _filename;
            //}

            if (expression.Index == -1 && Ancestors.Count > 1)
            {
                var a = Ancestors.ToArray()[1];

                if (a.Index == -1)
                {
                    return;
                }

                //var a = Ancestors.FirstOrDefault(x => x.Index != -1);

                if (a != null)
                {
                    expression.Index  = a.Index;
                    expression.Length = a.Length;
                }
                else if (expression is IParentNode parent)
                {
                    var children = parent.GetChildren();

                    if (children.Any())
                    {
                        expression.Index = children.First().Index;

                        expression.Length = children
                                            .Where(x => x != null)
                                            .GroupBy(x => x.Index)
                                            .Select(x => x.OrderByDescending(y => y.Length).First())
                                            .Sum(x => x.Length);
                    }
                }
            }

            //expression.Code = _code;
        }