-
Notifications
You must be signed in to change notification settings - Fork 328
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0c4a4f0
commit 74bb146
Showing
1 changed file
with
131 additions
and
130 deletions.
There are no files selected for viewing
261 changes: 131 additions & 130 deletions
261
.../Microsoft.PowerFx.Interpreter.Tests.Shared/LanguageServiceProtocol/PublicSurfaceTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,132 +1,133 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Text; | ||
using Microsoft.PowerFx.Syntax; | ||
using Xunit; | ||
|
||
namespace Microsoft.PowerFx.Tests.LanguageServiceProtocol | ||
{ | ||
public class PublicSurfaceTests | ||
{ | ||
[Fact] | ||
public void Test() | ||
{ | ||
var asm = typeof(EditorContextScope).Assembly; | ||
|
||
// The goal for public namespaces is to make the SDK easy for the consumer. | ||
// Namespace principles for public classes: | ||
// - prefer fewer namespaces. See C# for example: https://docs.microsoft.com/en-us/dotnet/api/microsoft.codeanalysis | ||
// - For easy discovery, but Engine in "Microsoft.PowerFx". | ||
// - For sub areas with many related classes, cluster into a single subnamespace. | ||
// - Avoid nesting more than 1 level deep | ||
|
||
var allowed = new HashSet<string>() | ||
{ | ||
// Public APIs | ||
"Microsoft.PowerFx.EditorEngineExtensions", | ||
"Microsoft.PowerFx.EditorContextScope", | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Text; | ||
using Microsoft.PowerFx.Syntax; | ||
using Xunit; | ||
|
||
namespace Microsoft.PowerFx.Tests.LanguageServiceProtocol | ||
{ | ||
public class PublicSurfaceTests | ||
{ | ||
[Fact] | ||
public void Test() | ||
{ | ||
var asm = typeof(EditorContextScope).Assembly; | ||
|
||
// The goal for public namespaces is to make the SDK easy for the consumer. | ||
// Namespace principles for public classes: | ||
// - prefer fewer namespaces. See C# for example: https://docs.microsoft.com/en-us/dotnet/api/microsoft.codeanalysis | ||
// - For easy discovery, but Engine in "Microsoft.PowerFx". | ||
// - For sub areas with many related classes, cluster into a single subnamespace. | ||
// - Avoid nesting more than 1 level deep | ||
|
||
var allowed = new HashSet<string>() | ||
{ | ||
// Public APIs | ||
"Microsoft.PowerFx.EditorEngineExtensions", | ||
"Microsoft.PowerFx.EditorContextScope", | ||
"Microsoft.PowerFx.Core.IPowerFxScopeFactory", | ||
"Microsoft.PowerFx.IExpressionRewriter", | ||
|
||
"Microsoft.PowerFx.LanguageServerProtocol.LanguageServer", | ||
|
||
// NL features. | ||
"Microsoft.PowerFx.LanguageServerProtocol.NLHandler", | ||
"Microsoft.PowerFx.LanguageServerProtocol.NL2FxParameters", | ||
"Microsoft.PowerFx.LanguageServerProtocol.INLHandlerFactory", | ||
"Microsoft.PowerFx.LanguageServerProtocol.IPowerFxScopeFx2NL", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Fx2NLParameters", | ||
"Microsoft.PowerFx.LanguageServerProtocol.UsageHints", | ||
"Microsoft.PowerFx.LanguageServerProtocol.LanguageServerInput", | ||
"Microsoft.PowerFx.LanguageServerProtocol.LanguageServerOutput", | ||
"Microsoft.PowerFx.LanguageServerProtocol.LanguageServerOutputBuilder", | ||
"Microsoft.PowerFx.LanguageServerProtocol.ILanguageServerLogger", | ||
"Microsoft.PowerFx.LanguageServerProtocol.IHostTaskExecutor", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Handlers.LanguageServerOperationContext", | ||
|
||
// Internal | ||
"Microsoft.PowerFx.LanguageServerProtocol.JsonRpcHelper", | ||
"Microsoft.PowerFx.LanguageServerProtocol.CodeActionKind", | ||
"Microsoft.PowerFx.LanguageServerProtocol.CommandName", | ||
|
||
// Protocol classes. | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.CodeAction", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.CodeActionCommand", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.CodeActionContext", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.CodeActionParams", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.CodeActionResult", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.CodeActionResultContext", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.CommandExecutedParams", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.CompletionContext", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.CompletionItem", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.CompletionItemKind", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.CompletionList", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.CompletionParams", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.CompletionTriggerKind", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.CustomProtocolNames", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.CustomGetCapabilitiesParams", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.CustomGetCapabilitiesResult", | ||
"Microsoft.PowerFx.IExpressionRewriter", | ||
|
||
"Microsoft.PowerFx.LanguageServerProtocol.LanguageServer", | ||
|
||
// NL features. | ||
"Microsoft.PowerFx.LanguageServerProtocol.NLHandler", | ||
"Microsoft.PowerFx.LanguageServerProtocol.NL2FxParameters", | ||
"Microsoft.PowerFx.LanguageServerProtocol.INLHandlerFactory", | ||
"Microsoft.PowerFx.LanguageServerProtocol.IPowerFxScopeFx2NL", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Fx2NLParameters", | ||
"Microsoft.PowerFx.LanguageServerProtocol.UsageHints", | ||
"Microsoft.PowerFx.LanguageServerProtocol.LanguageServerInput", | ||
"Microsoft.PowerFx.LanguageServerProtocol.LanguageServerOutput", | ||
"Microsoft.PowerFx.LanguageServerProtocol.LanguageServerOutputBuilder", | ||
"Microsoft.PowerFx.LanguageServerProtocol.ILanguageServerLogger", | ||
"Microsoft.PowerFx.LanguageServerProtocol.IHostTaskExecutor", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Handlers.LanguageServerOperationContext", | ||
|
||
// Internal | ||
"Microsoft.PowerFx.LanguageServerProtocol.JsonRpcHelper", | ||
"Microsoft.PowerFx.LanguageServerProtocol.CodeActionKind", | ||
"Microsoft.PowerFx.LanguageServerProtocol.CommandName", | ||
|
||
// Protocol classes. | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.CodeAction", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.CodeActionCommand", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.CodeActionContext", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.CodeActionParams", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.CodeActionResult", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.CodeActionResultContext", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.CommandExecutedParams", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.CompletionContext", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.CompletionItem", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.CompletionItemKind", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.CompletionList", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.CompletionParams", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.CompletionTriggerKind", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.CustomProtocolNames", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.CustomGetCapabilitiesParams", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.CustomGetCapabilitiesResult", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.BaseNLParams", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.BaseNLResult", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.CustomFx2NLParams", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.CustomFx2NLResult", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.CustomNL2FxParams", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.CustomNL2FxResult", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.CustomNL2FxResultItem", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.Diagnostic", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.DiagnosticSeverity", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.DidChangeTextDocumentParams", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.DidOpenTextDocumentParams", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.InitialFixupParams", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.LanguageServerRequestBaseParams", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.MarkupContent", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.ParameterInformation", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.Position", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.PublishDiagnosticsParams", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.PublishExpressionTypeParams", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.PublishTokensParams", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.Range", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.SignatureHelp", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.SignatureHelpContext", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.SignatureHelpParams", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.SignatureHelpTriggerKind", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.SignatureInformation", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.TextDocumentContentChangeEvent", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.TextDocumentIdentifier", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.TextDocumentItem", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.TextDocumentNames", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.TextDocumentPositionParams", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.TextEdit", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.VersionedTextDocumentIdentifier", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.WorkspaceEdit" | ||
}; | ||
|
||
var sb = new StringBuilder(); | ||
var count = 0; | ||
foreach (var type in asm.GetTypes().Where(t => t.IsPublic)) | ||
{ | ||
var name = type.FullName; | ||
if (!allowed.Contains(name)) | ||
{ | ||
sb.Append('"'); | ||
sb.Append(name); | ||
sb.Append("\","); | ||
sb.AppendLine(); | ||
count++; | ||
} | ||
|
||
allowed.Remove(name); | ||
} | ||
|
||
Assert.True(count == 0, $"Unexpected public types: {sb}"); | ||
|
||
// Types we expect to be in the assembly are all there. | ||
Assert.Empty(allowed); | ||
} | ||
} | ||
} | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.BaseNLResult", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.CustomFx2NLParams", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.CustomFx2NLResult", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.CustomNL2FxParams", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.CustomNL2FxResult", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.CustomNL2FxResultItem", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.Diagnostic", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.DiagnosticSeverity", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.DidChangeTextDocumentParams", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.DidOpenTextDocumentParams", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.InitialFixupParams", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.LanguageServerRequestBaseParams", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.MarkupContent", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.ParameterInformation", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.Position", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.PublishDiagnosticsParams", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.PublishExpressionTypeParams", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.PublishTokensParams", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.Range", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.ScalarRange", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.SignatureHelp", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.SignatureHelpContext", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.SignatureHelpParams", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.SignatureHelpTriggerKind", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.SignatureInformation", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.TextDocumentContentChangeEvent", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.TextDocumentIdentifier", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.TextDocumentItem", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.TextDocumentNames", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.TextDocumentPositionParams", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.TextEdit", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.VersionedTextDocumentIdentifier", | ||
"Microsoft.PowerFx.LanguageServerProtocol.Protocol.WorkspaceEdit" | ||
}; | ||
|
||
var sb = new StringBuilder(); | ||
var count = 0; | ||
foreach (var type in asm.GetTypes().Where(t => t.IsPublic)) | ||
{ | ||
var name = type.FullName; | ||
if (!allowed.Contains(name)) | ||
{ | ||
sb.Append('"'); | ||
sb.Append(name); | ||
sb.Append("\","); | ||
sb.AppendLine(); | ||
count++; | ||
} | ||
|
||
allowed.Remove(name); | ||
} | ||
|
||
Assert.True(count == 0, $"Unexpected public types: {sb}"); | ||
|
||
// Types we expect to be in the assembly are all there. | ||
Assert.Empty(allowed); | ||
} | ||
} | ||
} |