Skip to content

Commit

Permalink
added tests for Server Options
Browse files Browse the repository at this point in the history
  • Loading branch information
divmeh-aws committed Jan 15, 2025
1 parent 46609fa commit 1da2128
Showing 1 changed file with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
import software.amazon.smithy.model.shapes.Shape;
import software.amazon.smithy.model.shapes.ShapeId;
import software.amazon.smithy.model.traits.LengthTrait;
import software.amazon.smithy.model.validation.Severity;

public class SmithyLanguageServerTest {
@Test
Expand Down Expand Up @@ -2561,6 +2562,43 @@ public void reloadsProjectOnBuildFileSave() {
Map.of()));
}

@Test
public void testCustomServerOptions() {
ServerOptions options = ServerOptions.builder()
.setMinimumSeverity(Severity.NOTE)
.setOnlyReloadOnSave(true)
.build();

assertThat(options.getMinimumSeverity(), equalTo(Severity.NOTE));
assertThat(options.getOnlyReloadOnSave(), equalTo(true));
}

@Test
public void testFromInitializeParamsWithValidOptions() {
StubClient client = new StubClient();
JsonObject opts = new JsonObject();
opts.add("diagnostics.minimumSeverity", new JsonPrimitive("ERROR"));
opts.add("onlyReloadOnSave", new JsonPrimitive(true));

ServerOptions options = ServerOptions.fromInitializeParams(opts, new SmithyLanguageClient(client));

assertThat(options.getMinimumSeverity(), equalTo(Severity.ERROR));
assertThat(options.getOnlyReloadOnSave(), equalTo(true));
}

@Test
public void testFromInitializeParamsWithPartialOptions() {
StubClient client = new StubClient();
JsonObject opts = new JsonObject();
opts.add("onlyReloadOnSave", new JsonPrimitive(true));
// Not setting minimumSeverity

ServerOptions options = ServerOptions.fromInitializeParams(opts, new SmithyLanguageClient(client));

assertThat(options.getMinimumSeverity(), equalTo(Severity.WARNING)); // Default value
assertThat(options.getOnlyReloadOnSave(), equalTo(true)); // Explicitly set value
}

private void assertServerState(SmithyLanguageServer server, ServerState expected) {
ServerState actual = ServerState.from(server);
assertThat(actual, equalTo(expected));
Expand Down

0 comments on commit 1da2128

Please sign in to comment.