Esempio n. 1
0
        private string?TryGetSourceLinkUrl(DocumentHandle handle)
        {
            var document = _pdbReader.GetDocument(handle);

            if (document.Name.IsNil)
            {
                return(null);
            }

            var documentName = _pdbReader.GetString(document.Name);

            if (documentName is null)
            {
                return(null);
            }

            foreach (var cdiHandle in _pdbReader.GetCustomDebugInformation(EntityHandle.ModuleDefinition))
            {
                var cdi = _pdbReader.GetCustomDebugInformation(cdiHandle);
                if (_pdbReader.GetGuid(cdi.Kind) == PortableCustomDebugInfoKinds.SourceLink && !cdi.Value.IsNil)
                {
                    var blobReader     = _pdbReader.GetBlobReader(cdi.Value);
                    var sourceLinkJson = blobReader.ReadUTF8(blobReader.Length);

                    var map = SourceLinkMap.Parse(sourceLinkJson);

                    if (map.TryGetUri(documentName, out var uri))
                    {
                        return(uri);
                    }
                }
            }

            return(null);
        }
Esempio n. 2
0
        public void Entries()
        {
            var map = SourceLinkMap.Parse(@"
{
   ""documents"" : 
   {
      ""C:\\a*"": ""http://server/[*]"",
      ""C:\\a*"": ""http://a/"",
      ""C:\\a"": ""http://a/"",
      ""C:\\a*"": ""http://*a"",
      ""C:\\b"": ""http://b"",
   }
}");

            AssertEx.Equal(new[]
            {
                @"('C:\a', *) -> ('http://server/[', ']')",
                @"('C:\a', *) -> ('http://a/', '')",
                @"('C:\a', ) -> ('http://a/', '')",
                @"('C:\a', *) -> ('http://', 'a')",
                @"('C:\b', ) -> ('http://b', '')"
            }, Inspect(map));

            Assert.True(map.TryGetUri(@"C:\a", out var url));
            Assert.Equal("http://server/[]", url);

            Assert.True(map.TryGetUri(@"C:\a\b\c\d\e", out url));
            Assert.Equal("http://server/[/b/c/d/e]", url);

            Assert.True(map.TryGetUri(@"C:\b", out url));
            Assert.Equal("http://b", url);

            Assert.False(map.TryGetUri(@"C:\b\c", out _));
        }
Esempio n. 3
0
        public void Order1()
        {
            var map = SourceLinkMap.Parse(@"
{
   ""documents"" : 
   {
      ""C:\\a\\b*"": ""2:*"",
      ""C:\\a\\b\\c*"": ""1:*"",
      ""C:\\a*"": ""3:*"",
   }
}");

            AssertEx.Equal(new[]
            {
                @"('C:\a\b\c', *) -> ('1:', '')",
                @"('C:\a\b', *) -> ('2:', '')",
                @"('C:\a', *) -> ('3:', '')"
            }, Inspect(map));

            string?url;

            Assert.True(map.TryGetUri(@"C:\a\b\c\d\e", out url));
            Assert.Equal("1:/d/e", url);

            Assert.True(map.TryGetUri(@"C:\a\b\", out url));
            Assert.Equal("2:/", url);

            Assert.True(map.TryGetUri(@"C:\a\x", out url));
            Assert.Equal("3:/x", url);

            Assert.False(map.TryGetUri(@"D:\x", out _));
        }
Esempio n. 4
0
        public void Order2()
        {
            var map = SourceLinkMap.Parse(@"
{
   ""documents"" : 
   {
      ""C:\\aaa\\bbb*"": ""1:*"",
      ""C:\\aaa\\bb*"": ""2:*"",
   }
}");

            AssertEx.Equal(new[]
            {
                @"('C:\aaa\bbb', *) -> ('1:', '')",
                @"('C:\aaa\bb', *) -> ('2:', '')",
            }, Inspect(map));

            string?url;

            Assert.True(map.TryGetUri(@"C:\aaa\bbbb", out url));
            Assert.Equal("1:b", url);

            Assert.True(map.TryGetUri(@"C:\aaa\bbb", out url));
            Assert.Equal("1:", url);

            Assert.True(map.TryGetUri(@"C:\aaa\bb", out url));
            Assert.Equal("2:", url);

            Assert.False(map.TryGetUri(@"C:\aaa\b", out _));
        }
Esempio n. 5
0
        public void Extra()
        {
            var map = SourceLinkMap.Parse(@"
{
   ""documents"" : 
   {
      ""C:\\a*"": ""http://server/1/a*"",
   },
   ""extra"": {}
}");

            AssertEx.Equal(new[] { "('C:\\a', *) -> ('http://server/1/a', '')" }, Inspect(map));
        }
Esempio n. 6
0
        public void Empty(string json)
        {
            var map = SourceLinkMap.Parse(json);

            Assert.Empty(map.Entries);
        }
Esempio n. 7
0
 public void InvalidWildcards(string json)
 {
     Assert.Throws <InvalidDataException>(() => SourceLinkMap.Parse(json));
 }
Esempio n. 8
0
 public void BadJson_Key(string json)
 {
     Assert.ThrowsAny <JsonException>(() => SourceLinkMap.Parse(json));
 }
Esempio n. 9
0
        public void TryGetUrl_InvalidArgument()
        {
            var map = SourceLinkMap.Parse(@"{""documents"":{}}");

            Assert.Throws <ArgumentNullException>(() => map.TryGetUri(null !, out _));
        }
Esempio n. 10
0
        public void TryGetUrl_Star()
        {
            var map = SourceLinkMap.Parse(@"{""documents"":{}}");

            Assert.False(map.TryGetUri("path*", out _));
        }