Skip to content

Commit

Permalink
update interactive package
Browse files Browse the repository at this point in the history
  • Loading branch information
brettfo committed Jun 29, 2024
1 parent 9667ee5 commit e7909a5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 50 deletions.
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<ItemGroup>
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly" Version="7.0.3" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="7.0.3" />
<PackageVersion Include="Microsoft.DotNet.Interactive" Version="1.0.0-beta.23081.2" />
<PackageVersion Include="Microsoft.DotNet.Interactive" Version="1.0.0-beta.24229.4" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="1.1.1" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.1" />
Expand Down
72 changes: 24 additions & 48 deletions src/IxMilia.Lisp.Interactive.Test/InteractiveTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ public async Task GetCompletions()
GetCodeAndPosition(markedCode, out var code, out var position);
var kernel = new LispKernel();
var commandResult = await kernel.SendAsync(new RequestCompletions(code, GetLinePosition(position)), CancellationToken.None);
var events = GetEventList(commandResult.KernelEvents);
AssertNoErrors(events);
var completionsProduced = events.OfType<CompletionsProduced>().Single();
AssertNoErrors(commandResult.Events);
var completionsProduced = commandResult.Events.OfType<CompletionsProduced>().Single();
var _ = completionsProduced.Completions.Where(c => c.DisplayText == "KERNEL:+/2").Single();
}

Expand All @@ -33,9 +32,8 @@ public async Task GetHoverText()
GetCodeAndPosition(markedCode, out var code, out var position);
var kernel = new LispKernel();
var commandResult = await kernel.SendAsync(new RequestHoverText(code, GetLinePosition(position)), CancellationToken.None);
var events = GetEventList(commandResult.KernelEvents);
AssertNoErrors(events);
var hoverText = events.OfType<HoverTextProduced>().Single();
AssertNoErrors(commandResult.Events);
var hoverText = commandResult.Events.OfType<HoverTextProduced>().Single();
Assert.Equal("()", hoverText.Content.Single().Value);
}

Expand All @@ -44,9 +42,8 @@ public async Task RequestValueInfosInitiallyProducesEmptySet()
{
var kernel = new LispKernel();
var commandResult = await kernel.SendAsync(new RequestValueInfos(kernel.Name));
var events = GetEventList(commandResult.KernelEvents);
AssertNoErrors(events);
var valueInfosProduced = events.OfType<ValueInfosProduced>().Single();
AssertNoErrors(commandResult.Events);
var valueInfosProduced = commandResult.Events.OfType<ValueInfosProduced>().Single();
Assert.Empty(valueInfosProduced.ValueInfos);
}

Expand All @@ -55,13 +52,11 @@ public async Task RequestValueInfosReturnsOnlyWhatHasBeenSet()
{
var kernel = new LispKernel();
var commandResult = await kernel.SendAsync(new SubmitCode("(setf x 1)(setf y 2)"));
var events = GetEventList(commandResult.KernelEvents);
AssertNoErrors(events);
AssertNoErrors(commandResult.Events);

commandResult = await kernel.SendAsync(new RequestValueInfos(kernel.Name));
events = GetEventList(commandResult.KernelEvents);
AssertNoErrors(events);
var valueInfosProduced = events.OfType<ValueInfosProduced>().Single();
AssertNoErrors(commandResult.Events);
var valueInfosProduced = commandResult.Events.OfType<ValueInfosProduced>().Single();
var valueInfos = valueInfosProduced.ValueInfos.Select(v => v.Name).ToArray();
Assert.Equal("X,Y", string.Join(",", valueInfos));
}
Expand All @@ -71,13 +66,11 @@ public async Task RequestValueInfosDoesNotReportFunctionsOrMacros()
{
var kernel = new LispKernel();
var commandResult = await kernel.SendAsync(new SubmitCode("(setf x 1)(setf y 2)(defun some-function () ())(defmacro some-macro () ())"));
var events = GetEventList(commandResult.KernelEvents);
AssertNoErrors(events);
AssertNoErrors(commandResult.Events);

commandResult = await kernel.SendAsync(new RequestValueInfos(kernel.Name));
events = GetEventList(commandResult.KernelEvents);
AssertNoErrors(events);
var valueInfosProduced = events.OfType<ValueInfosProduced>().Single();
AssertNoErrors(commandResult.Events);
var valueInfosProduced = commandResult.Events.OfType<ValueInfosProduced>().Single();
var valueInfos = valueInfosProduced.ValueInfos.Select(v => v.Name).ToArray();
Assert.Equal("X,Y", string.Join(",", valueInfos));
}
Expand All @@ -91,13 +84,11 @@ public async Task RequestValueReturnsTheAppropriateValue(string mimeType, string
{
var kernel = new LispKernel();
var commandResult = await kernel.SendAsync(new SubmitCode("(setf x '(1 2 3))"));
var events = GetEventList(commandResult.KernelEvents);
AssertNoErrors(events);
AssertNoErrors(commandResult.Events);

commandResult = await kernel.SendAsync(new RequestValue(valueName, mimeType: mimeType));
events = GetEventList(commandResult.KernelEvents);
AssertNoErrors(events);
var valueProduced = events.OfType<ValueProduced>().Single();
AssertNoErrors(commandResult.Events);
var valueProduced = commandResult.Events.OfType<ValueProduced>().Single();
Assert.Equal(valueName, valueProduced.Name);
Assert.Equal(mimeType, valueProduced.FormattedValue.MimeType);
Assert.Equal(expectedResult, valueProduced.FormattedValue.Value);
Expand All @@ -109,9 +100,8 @@ public async Task SubmitCodeProducesAResult()
var code = "(+ 1 2)";
var kernel = new LispKernel();
var commandResult = await kernel.SendAsync(new SubmitCode(code));
var events = GetEventList(commandResult.KernelEvents);
AssertNoErrors(events);
var returnValue = events.OfType<ReturnValueProduced>().Single();
AssertNoErrors(commandResult.Events);
var returnValue = commandResult.Events.OfType<ReturnValueProduced>().Single();
Assert.Equal("3", returnValue.FormattedValues.Single(f => f.MimeType == "text/plain").Value);
}

Expand All @@ -121,9 +111,8 @@ public async Task SubmitCodeRedirectsStandardOut()
var code = "(format t \"stdout\")";
var kernel = new LispKernel();
var commandResult = await kernel.SendAsync(new SubmitCode(code));
var events = GetEventList(commandResult.KernelEvents);
AssertNoErrors(events);
var stdOut = events.OfType<StandardOutputValueProduced>().Single();
AssertNoErrors(commandResult.Events);
var stdOut = commandResult.Events.OfType<StandardOutputValueProduced>().Single();
Assert.Equal("stdout", stdOut.FormattedValues.Single().Value);
}

Expand All @@ -133,9 +122,8 @@ public async Task SubmitCodeDoesNotReturnAnythingForNil()
var code = "()";
var kernel = new LispKernel();
var commandResult = await kernel.SendAsync(new SubmitCode(code));
var events = GetEventList(commandResult.KernelEvents);
AssertNoErrors(events);
Assert.Empty(events.OfType<DisplayEvent>());
AssertNoErrors(commandResult.Events);
Assert.Empty(commandResult.Events.OfType<DisplayEvent>());
}

[Fact]
Expand All @@ -144,13 +132,11 @@ public async Task SendValueSetsValueInKernel()
var kernel = new LispKernel();
var command = new SendValue("x", null, new FormattedValue("application/json", "[1,2]"));
var commandResult = await kernel.SendAsync(command);
var events = GetEventList(commandResult.KernelEvents);
AssertNoErrors(events);
AssertNoErrors(commandResult.Events);

commandResult = await kernel.SendAsync(new RequestValueInfos());
events = GetEventList(commandResult.KernelEvents);
AssertNoErrors(events);
var valueInfos = events.OfType<ValueInfosProduced>().Single();
AssertNoErrors(commandResult.Events);
var valueInfos = commandResult.Events.OfType<ValueInfosProduced>().Single();
var valueInfo = valueInfos.ValueInfos.Single();
Assert.Equal("X", valueInfo.Name);
Assert.Equal("text/plain+summary", valueInfo.FormattedValue.MimeType);
Expand All @@ -172,15 +158,5 @@ private static LinePosition GetLinePosition(LispSourcePosition position)
{
return new LinePosition(position.Line - 1, position.Column - 1);
}

private static IList<KernelEvent> GetEventList(IObservable<KernelEvent> observable)
{
var result = new List<KernelEvent>();
observable.Subscribe(e =>
{
result.Add(e);
});
return result;
}
}
}
2 changes: 1 addition & 1 deletion src/IxMilia.Lisp.Interactive/LispKernel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public LispKernel()
_host = new Lazy<Task<LispHost>>(async () =>
{
var writer = new ListeningTextWriter(line => _stdoutSubject.OnNext(line));
var configuration = new LispHostConfiguration(output: writer);
var configuration = new LispHostConfiguration(output: writer, readerType: LispReaderType.NoReaderMacros);
var host = await LispHost.CreateAsync(configuration);
_suppressedValues = new HashSet<string>(host.RootFrame.GetValues().Select(v => v.Item1.Value));
return host;
Expand Down

0 comments on commit e7909a5

Please sign in to comment.