示例#1
0
 internal static Func <SyntaxNode, SyntaxNode> GetSyntaxMapFromMarkers(
     SourceWithMarkedNodes source0,
     SourceWithMarkedNodes source1
     )
 {
     return(SourceWithMarkedNodes.GetSyntaxMap(source0, source1));
 }
示例#2
0
        internal static void VerifyPdbLambdasAndClosures(
            this Compilation compilation,
            SourceWithMarkedNodes source
            )
        {
            var pdb    = GetPdbXml(compilation);
            var pdbXml = XElement.Parse(pdb);

            // We need to get the method start index from the input source, as its not in the PDB
            var methodStartTags = source.MarkedSpans.WhereAsArray(s => s.TagName == "M");

            Assert.True(
                methodStartTags.Length == 1,
                "There must be one and only one method start tag per test input."
                );
            var methodStart = methodStartTags[0].MatchedSpan.Start;

            // Calculate the expected tags for closures
            var expectedTags = pdbXml
                               .DescendantsAndSelf("closure")
                               .Select(
                (c, i) =>
                new
            {
                Tag        = $"<C:{i}>",
                StartIndex = methodStart + int.Parse(c.Attribute("offset").Value)
            }
                )
                               .ToList();

            // Add the expected tags for lambdas
            expectedTags.AddRange(
                pdbXml
                .DescendantsAndSelf("lambda")
                .Select(
                    (c, i) =>
                    new
            {
                Tag        = $"<L:{i}.{int.Parse(c.Attribute("closure").Value)}>",
                StartIndex = methodStart + int.Parse(c.Attribute("offset").Value)
            }
                    )
                );

            // Order by start index so they line up nicely
            expectedTags.Sort((x, y) => x.StartIndex.CompareTo(y.StartIndex));

            // Ensure the tag for the method start is the first element
            expectedTags.Insert(0, new { Tag = "<M>", StartIndex = methodStart });

            // Now reverse the list so we can insert without worrying about offsets
            expectedTags.Reverse();

            var expected = source.Source;

            foreach (var tag in expectedTags)
            {
                expected = expected.Insert(tag.StartIndex, tag.Tag);
            }

            AssertEx.EqualOrDiff(expected, source.Input);
        }