|
1 | 1 | using System;
|
2 |
| -using System.Collections.Generic; |
3 |
| -using System.Linq; |
4 |
| -using System.Reflection; |
5 |
| -using FluentAssertions; |
6 | 2 | using Microsoft.Extensions.Logging;
|
7 |
| -using NSubstitute; |
8 |
| -using OmniSharp.Extensions.JsonRpc; |
9 |
| -using OmniSharp.Extensions.LanguageServer; |
10 | 3 | using OmniSharp.Extensions.LanguageServer.Abstractions;
|
11 |
| -using OmniSharp.Extensions.LanguageServer.Capabilities.Client; |
12 |
| -using OmniSharp.Extensions.LanguageServer.Models; |
13 | 4 | using Serilog;
|
14 | 5 | using Serilog.Extensions.Logging;
|
15 |
| -using Xunit; |
16 | 6 | using Xunit.Abstractions;
|
17 |
| -using HandlerCollection = OmniSharp.Extensions.LanguageServer.HandlerCollection; |
18 | 7 | using ILogger = Microsoft.Extensions.Logging.ILogger;
|
19 | 8 |
|
20 | 9 | namespace Lsp.Tests
|
@@ -42,118 +31,4 @@ void ILoggerFactory.AddProvider(ILoggerProvider provider) { }
|
42 | 31 |
|
43 | 32 | void IDisposable.Dispose() { }
|
44 | 33 | }
|
45 |
| - |
46 |
| - public class ClientCapabilityProviderTests |
47 |
| - { |
48 |
| - private static Type[] TextDocumentCapabilities = { |
49 |
| - typeof(CompletionCapability), |
50 |
| - typeof(HoverCapability), |
51 |
| - typeof(SignatureHelpCapability), |
52 |
| - typeof(ReferencesCapability), |
53 |
| - typeof(DocumentHighlightCapability), |
54 |
| - typeof(DocumentSymbolCapability), |
55 |
| - typeof(DocumentFormattingCapability), |
56 |
| - typeof(DocumentRangeFormattingCapability), |
57 |
| - typeof(DocumentOnTypeFormattingCapability), |
58 |
| - typeof(DefinitionCapability), |
59 |
| - typeof(CodeActionCapability), |
60 |
| - typeof(CodeLensCapability), |
61 |
| - typeof(DocumentLinkCapability), |
62 |
| - typeof(RenameCapability), |
63 |
| - typeof(WorkspaceSymbolCapability), |
64 |
| - typeof(ExecuteCommandCapability), |
65 |
| - }; |
66 |
| - |
67 |
| - [Theory, MemberData(nameof(AllowSupportedCapabilities))] |
68 |
| - public void Should_AllowSupportedCapabilities(IJsonRpcHandler handler, object instance) |
69 |
| - { |
70 |
| - var textDocumentSyncHandler = TextDocumentSyncHandlerExtensions.With(DocumentSelector.ForPattern("**/*.cs")); |
71 |
| - |
72 |
| - var collection = new HandlerCollection { textDocumentSyncHandler, handler }; |
73 |
| - var provider = new ClientCapabilityProvider(collection); |
74 |
| - |
75 |
| - HasHandler(provider, instance).Should().BeTrue(); |
76 |
| - } |
77 |
| - |
78 |
| - public static IEnumerable<object[]> AllowSupportedCapabilities() |
79 |
| - { |
80 |
| - return GetItems(TextDocumentCapabilities, type => { |
81 |
| - var handlerType = GetHandlerType(type); |
82 |
| - var handler = Substitute.For(new Type[] { handlerType }, new object[0]); |
83 |
| - return new[] { handler, Activator.CreateInstance(typeof(Supports<>).MakeGenericType(type), true, Activator.CreateInstance(type)) }; |
84 |
| - }); |
85 |
| - } |
86 |
| - |
87 |
| - [Theory, MemberData(nameof(DisallowUnsupportedCapabilities))] |
88 |
| - public void Should_DisallowUnsupportedCapabilities(IJsonRpcHandler handler, object instance) |
89 |
| - { |
90 |
| - var textDocumentSyncHandler = TextDocumentSyncHandlerExtensions.With(DocumentSelector.ForPattern("**/*.cs")); |
91 |
| - |
92 |
| - var collection = new HandlerCollection { textDocumentSyncHandler, handler }; |
93 |
| - var provider = new ClientCapabilityProvider(collection); |
94 |
| - |
95 |
| - HasHandler(provider, instance).Should().BeFalse(); |
96 |
| - } |
97 |
| - |
98 |
| - public static IEnumerable<object[]> DisallowUnsupportedCapabilities() |
99 |
| - { |
100 |
| - return GetItems(TextDocumentCapabilities, type => { |
101 |
| - var handlerType = GetHandlerType(type); |
102 |
| - var handler = Substitute.For(new Type[] { handlerType }, new object[0]); |
103 |
| - return new[] { handler, Activator.CreateInstance(typeof(Supports<>).MakeGenericType(type), false) }; |
104 |
| - }); |
105 |
| - } |
106 |
| - |
107 |
| - [Theory, MemberData(nameof(DisallowNullSupportsCapabilities))] |
108 |
| - public void Should_DisallowNullSupportedCapabilities(IJsonRpcHandler handler, object instance) |
109 |
| - { |
110 |
| - var textDocumentSyncHandler = TextDocumentSyncHandlerExtensions.With(DocumentSelector.ForPattern("**/*.cs")); |
111 |
| - |
112 |
| - var collection = new HandlerCollection { textDocumentSyncHandler, handler }; |
113 |
| - var provider = new ClientCapabilityProvider(collection); |
114 |
| - |
115 |
| - HasHandler(provider, instance).Should().BeFalse(); |
116 |
| - } |
117 |
| - |
118 |
| - public static IEnumerable<object[]> DisallowNullSupportsCapabilities() |
119 |
| - { |
120 |
| - return GetItems(TextDocumentCapabilities, type => { |
121 |
| - var handlerType = GetHandlerType(type); |
122 |
| - var handler = Substitute.For(new Type[] { handlerType }, new object[0]); |
123 |
| - return new[] { handler, Activator.CreateInstance(typeof(Supports<>).MakeGenericType(type), true) }; |
124 |
| - }); |
125 |
| - } |
126 |
| - |
127 |
| - private static bool HasHandler(ClientCapabilityProvider provider, object instance) |
128 |
| - { |
129 |
| - return (bool)typeof(ClientCapabilityProviderTests).GetTypeInfo() |
130 |
| - .GetMethod(nameof(GenericHasHandler), BindingFlags.Static | BindingFlags.NonPublic) |
131 |
| - .MakeGenericMethod(instance.GetType().GetTypeInfo().GetGenericArguments()[0]).Invoke(null, new[] { provider, instance }); |
132 |
| - } |
133 |
| - |
134 |
| - private static bool HasHandler(ClientCapabilityProvider provider, Type type) |
135 |
| - { |
136 |
| - return (bool)typeof(ClientCapabilityProviderTests).GetTypeInfo() |
137 |
| - .GetMethod(nameof(GenericHasHandler), BindingFlags.Static | BindingFlags.NonPublic) |
138 |
| - .MakeGenericMethod(type).Invoke(null, new object[] { provider, null }); |
139 |
| - } |
140 |
| - |
141 |
| - private static bool GenericHasHandler<T>(ClientCapabilityProvider provider, Supports<T> supports) |
142 |
| - where T : DynamicCapability, ConnectedCapability<IJsonRpcHandler> |
143 |
| - { |
144 |
| - return provider.HasHandler(supports); |
145 |
| - } |
146 |
| - |
147 |
| - private static IEnumerable<object[]> GetItems<T>(IEnumerable<T> types, Func<T, IEnumerable<object>> func) |
148 |
| - { |
149 |
| - return types.Select(x => func(x).ToArray()); |
150 |
| - } |
151 |
| - |
152 |
| - private static Type GetHandlerType(Type type) |
153 |
| - { |
154 |
| - return type.GetTypeInfo().ImplementedInterfaces |
155 |
| - .Single(x => x.GetTypeInfo().IsGenericType && x.GetTypeInfo().GetGenericTypeDefinition() == typeof(ConnectedCapability<>)) |
156 |
| - .GetTypeInfo().GetGenericArguments()[0]; |
157 |
| - } |
158 |
| - } |
159 | 34 | }
|
0 commit comments