Skip to content

Commit

Permalink
refactor tc_as_a_exe test
Browse files Browse the repository at this point in the history
  • Loading branch information
WebFreak001 committed May 31, 2024
1 parent 35c9edc commit 9e9d761
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 28 deletions.
34 changes: 6 additions & 28 deletions test/tc_as_a_exe/source/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,17 @@ import core.thread;
import core.thread.fiber;

import served.lsp.filereader;
import served.lsp.jsonops;
import served.lsp.jsonrpc;
import served.lsp.protocol;
import served.lsp.uri;
import served.lsp.jsonops;

version (assert)
{
}
else
static assert(false, "Compile with asserts.");

__gshared RPCProcessor rpc;
__gshared string cwd;

// https://forum.dlang.org/post/[email protected]
void copyDir(string inDir, string outDir)
{
Expand Down Expand Up @@ -91,25 +88,6 @@ void main()
return;
}

void delegate(RequestMessageRaw msg) gotRequest;
void delegate(RequestMessageRaw msg) gotNotify;

shared static this()
{
gotRequest = toDelegate(&defaultRequestHandler);
gotNotify = toDelegate(&defaultNotifyHandler);
}

void defaultRequestHandler(RequestMessageRaw msg)
{
assert(false, "Unexpected request " ~ msg.toString);
}

void defaultNotifyHandler(RequestMessageRaw msg)
{
info("Ignoring notification " ~ msg.toString);
}

void pumpEvents()
{
while (rpc.hasData)
Expand All @@ -127,13 +105,13 @@ void doTests()
WorkspaceClientCapabilities workspace = {
configuration: opt(true)
};
InitializeParams init = {
processId: thisProcessID,
InitializeParams init = InitializeParams(
processId: typeof(InitializeParams.processId)(thisProcessID),
rootUri: uriFromFile(cwd),
capabilities: {
capabilities: ClientCapabilities(
workspace: opt(workspace)
}
};
)
);
auto msg = rpc.sendRequest("initialize", init, 10.seconds);
info("Response: ", msg.resultJson);

Expand Down
46 changes: 46 additions & 0 deletions test/tc_as_a_exe/source/tests/package.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
module tests;

abstract class ServedTest
{
abstract void run();

void tick()
{
pumpEvents();
Fiber.yield();
}

void processResponse(void delegate(RequestMessageRaw msg) cb)
{
bool called;
gotRequest = (msg) {
called = true;
cb(msg);
};
tick();
assert(called, "no response received!");
gotRequest = null;
}
}

__gshared RPCProcessor rpc;
__gshared string cwd;

__gshared void delegate(RequestMessageRaw msg) gotRequest;
__gshared void delegate(RequestMessageRaw msg) gotNotify;

shared static this()
{
gotRequest = toDelegate(&defaultRequestHandler);
gotNotify = toDelegate(&defaultNotifyHandler);
}

void defaultRequestHandler(RequestMessageRaw msg)
{
assert(false, "Unexpected request " ~ msg.toString);
}

void defaultNotifyHandler(RequestMessageRaw msg)
{
info("Ignoring notification " ~ msg.toString);
}

0 comments on commit 9e9d761

Please sign in to comment.